-
Notifications
You must be signed in to change notification settings - Fork 0
All FFmpeg changes #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: jpadia/tags/n5.1.3
Are you sure you want to change the base?
All FFmpeg changes #1
Conversation
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 @@ | |||
| /*! | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There compression types are described here: https://developer.apple.com/library/archive/technotes/tn2162/_index.html#//apple_ref/doc/uid/DTS40013070-CH1-TNTAG8
| kPRHalfSize = kPRDownscale_1x2, | ||
| kPRQuarterSize = kPRDownscale_2x2 | ||
|
|
||
| } PRDownscaleMode; |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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)()); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; | ||
|
|
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 | ||
|
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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