Opened 2 years ago
#18233 new bug
ffmpeg media add-on is not fully initializing encoder parameters
Reported by: | pulkomandy | Owned by: | pulkomandy |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | Audio & Video/Codecs | Version: | R1/beta4 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
See for example https://stackoverflow.com/questions/60278773/invalid-data-when-creating-mkv-container-with-h264-stream-because-extradata-is-n
In AVFormatWriter, we hit a similar situation for example for MKV (which used to work with older ffmpeg versions...) because we call avformat_write_header with a completely manually set up AVStream. However, ffmpeg is not designed to work this way, and needs the stream to relay infos from the AVCodecContext, using the function avcodec_parameters_from_context.
In the current add-on design, the AVFormatWriter class does not have access to the codec which is in AVCodecEncoder. Things are done this way because in theory, it may be possible to use a writer or an encoder from another media plug-in. However, this is only an "in theory" thing and the user facing media kit API does not really need that (especially as we use very few other plugins anyway, everything goes through ffmpeg).
When doing things this way, the encoder can transfer as much data as it needs to the writer, which can then store this data in the file header. In the current code this is simply not possible, and this causes several of the encoding formats to not work.