The *_metadata-bitstream filter (I only mean the ones based upon cbs: prores_metadata is not included.) currently only update the bitstream and not the AVCodecParameters. As a consequence, if one changes a bitstream parameter, it might very well happen that ffmpeg adds information at the container level contradicting and preceding (hence nullifying) the new bitstream value even if the new container value was not already present in the source container, but is only read from the original bitstream.
The situation is even worse for h264_metadata and hevc_metadata: If one uses the crop parameters, the dimensions of the bitstream change, but the AVCodecParamters don't. This means that muxer write wrong dimension values which means that some files violate the specifications. I have therefore implemented updating the output AVCodecParameters for the five *_metadata filters. Some things can only be reliably updated when there is extradata available (e.g. the aforementioned crop values in h264_metadata and hevc_metadata don't denote additional cropping; rather these values are used to replace the existing cropping values which means that one can't know by how much the dimensions change). I noticed something odd about the aspect ratio: If one updates this part of the AVCodecParameters, one runs into trouble in init_muxer in libavformat/mux.c because of an aspect ratio mismatch between muxer and encoder layer (the muxer information comes from the sample_aspect_ratio member of AVStream, the encoder information is the aspect ratio information from the AVCodecParameters embedded in AVStream). Is there a way to successfully update the sample_aspect_ratio from a bitstream filter? I would very much appreciate that. My first version that did update the aspect ratio par_out value can be found on github: https://github.com/mkver/FFmpeg/commits/par_out (The reason for the improved check for invalid values in cbs_mpeg2 was that this enabled me to rely on the dimensions being strictly positive in the next patch; in the new version, this part of the code has been removed.) A last note: The hevc_metadata filter now updates the height to the frame height (after all, the width and height refer to video frames); this deviates from current behaviour for field-based HEVC (FFmpeg always reports the picture dimensions for HEVC, even when said pictures only contain fields). But if I am not mistaken (I only have a draft of the third edition of ISO/IEC 14496-15) then muxers (at least mp4 and Matroska) want the frame dimensions, too, so this seemed to be the right thing to do. Andreas Rheinhardt (8): cbs: Add function to update video codec parameters av1_metadata: Add option to update video parameters cbs_mpeg2: Improve checks for invalid values mpeg2_metadata: Additionally update AVCodecParameters vp9_metadata: Improve spec-compliance and warnings vp9_metadata: Update AVCodecParameters h264_metadata: Update AVCodecParameters hevc_metadata: Update AVCodecParameters doc/bitstream_filters.texi | 35 +++++++++++++++ libavcodec/av1_metadata_bsf.c | 43 ++++++++++++++++-- libavcodec/cbs.c | 35 +++++++++++++++ libavcodec/cbs.h | 15 +++++++ libavcodec/cbs_mpeg2.c | 17 ++++--- libavcodec/cbs_mpeg2_syntax_template.c | 4 +- libavcodec/h264_metadata_bsf.c | 48 +++++++++++++++++--- libavcodec/h265_metadata_bsf.c | 44 ++++++++++++++++--- libavcodec/mpeg2_metadata_bsf.c | 11 +++++ libavcodec/vp9_metadata_bsf.c | 61 +++++++++++++++++++++----- 10 files changed, 278 insertions(+), 35 deletions(-) -- 2.19.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel