Skip to content

Conversation

@jaypadia-frame
Copy link
Owner

New branch with all the FFmpeg changes for the libproresdecoder.a integration.

The files in the auxiliary folder are the ones that don't go into the repo, but are needed for compilation. They are

  • libproresdecoder.a (the .a library from apple, which we don't have here)
  • proresdecoder.h (include header from apple)
  • proresdecoder.pc (package config)

New branch with all the FFmpeg changes for the libproresdecoder.a integration.

The files in the auxiliary folder are the ones that don't go into the repo, but are needed for compilation. They are
- libproresdecoder.a (the .a library from apple, which we don't have here)
- proresdecoder.h (include header from apple)
- proresdecoder.pc (package config)
@@ -0,0 +1,148 @@
/*!
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the include header we received along with the .a library.

kPRFormat_b64a = 'b64a' //!< 4:4:4:4 Full-range (0-65535) ARGB 16-bit big endian per component
} PRPixelFormat;
#define PR_PIXEL_FORMAT_DEFINED
#endif
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kPRHalfSize = kPRDownscale_1x2,
kPRQuarterSize = kPRDownscale_2x2

} PRDownscaleMode;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shall always assume kPRDownscale_1x1 as the others may not apply

for DNN based filters like dnn_processing [no]
--enable-libopus enable Opus de/encoding via libopus [no]
--enable-libplacebo enable libplacebo library [no]
--enable-libproresdecoder enable Apple ProRes decoder library [no]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the enable / disable option for FFmpeg compliation. We haven't set it for a default enable

}
}
enabled libplacebo && require_pkg_config libplacebo "libplacebo >= 4.192.0" libplacebo/vulkan.h pl_vulkan_create
enabled libproresdecoder && require_pkg_config libproresdecoder proresdecoder proresdecoder.h PROpenDecoder
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require_pkg_config: package config is present
libproresdecoder: library file name
proresdecoder proresdecoder.h: include header to look for
PROpenDecoder: actual frame decode function name

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the template for other / existing codecs.
I had digged into the configure functions that access these params (or rather where these params are passed into & processed by; don't remember the full details about the impact and use of each of these).

extern const FFCodec ff_ppm_encoder;
extern const FFCodec ff_ppm_decoder;
extern const FFCodec ff_prores_encoder;
extern const FFCodec ff_prores_decoder;
Copy link
Owner Author

@jaypadia-frame jaypadia-frame Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prores decoder was moved to the end in order to deprioritize this decoder.

extern const FFCodec ff_libopenjpeg_decoder;
extern const FFCodec ff_libopus_encoder;
extern const FFCodec ff_libopus_decoder;
extern const FFCodec ff_libproresdecoder_decoder;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New decoder - libproresdecoder

{
return 0;
}
#endif
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines 45 - 51 should be deleted.

.priv_data_size = sizeof(ProResDecodeCodec),
.init = initAppleProResDecoder,
.close = closeAppleProResDecoder,
FF_CODEC_DECODE_CB(decodeAppleProResFrame),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 3 main functions to this interface are the ones that init, close, decode

};

const FFCodec ff_libproresdecoder_decoder = {
.p.name = "libproresdecoder",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the name of the decoder in the command line.

* @return A reference to the instantiated decoder, or NULL on failure.
*/
PRDecoderRef
PROpenDecoder(int numThreads, void (*threadStartupCallback)());
Copy link
Owner Author

@jaypadia-frame jaypadia-frame Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==
Important NOTE
We haven't yet explored the numThreads opportunity provided by the decoder itself.
We are only use the FFmpeg threading per frame feature.

int compressedFrameSize,
PRPixelBuffer* destinationBuffer,
PRDownscaleMode downscaleMode,
bool ignoreAlpha);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs the decoder reference, pointer to and the size of the compressed video frame, output buffer, downscale mode (always set to 1x1) and whether to consider the alpha (we always look for it) - that helps us define the context in our local header - libavcodec/libproresdecoder.h::ProResDecodeCodec


dstdecodectx->m_width = srcdecodectx->m_width;
dstdecodectx->m_height = srcdecodectx->m_height;
dstdecodectx->pix_fmt = srcdecodectx->pix_fmt;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just copying over everything that I could I think of that would need to be replicated.

proresdecodecctx->m_height = avctx->height;
// For now the downscale mode is universally 1x1
proresdecodecctx->downscale_mode = kPRDownscale_1x1;

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the reading of the tags and setting up accordingly, we follow the same approach as the FFmpeg prores decoder does: https://github.com/jaypadia-frame/FFmpeg/blob/master/libavcodec/proresdec2.c#L134

return 0;
};

int decodeAppleProResFrame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface here is the same as other decoders' decode frame function.


int decodePacket(ProResDecodeCodec* decoderctx, AVPacket* pkt, AVFrame* framePtr, bool drain) {
if (drain) {
// return AVError_create(AVErrorCode_kErrorEOF);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These return AVError_create(AVErrorCode_kErrorEOF); were referenced from Harry's team's changes. They should be cleaned up, I guess. We should have readable return strings that enumerate these return value.
TODO for Jay.

memset(framePtr->data[0], 0, framePtr->linesize[0] * decoderctx->m_height); // Y
memset(framePtr->data[1], 0, framePtr->linesize[1] * decoderctx->m_height); // U
memset(framePtr->data[2], 0, framePtr->linesize[2] * decoderctx->m_height); // V

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code from here on below converts the packed YUV outputs in Apple's formats (the ones listed in that include header) to more generic (or rather standardized(?)) FFmpeg supported YUV formats.
Ques: Should. this code be another function?

}
}
}
free(dataPtr);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I had forgotten this earlier which caused the memory leak. 🤦 🤦 🤦

return -2; // error code to be updated
}

int rowBytes = PRBytesPerRowNeededInPixelBuffer(decoderctx->m_width, decoderctx->pix_fmt, decoderctx->downscale_mode);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to have this as we don't have to do this Maths. Although, with the formats explained by Apple in the link above, we could have done that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants