If any of the *_metadata filter based upon cbs currently updates a video codec parameter like color information, the AVCodecParameters are not updated accordingly, so that e.g. muxers write header values based upon outdated information that may precede and thereby nullify the new values on the bitstream level. This commit adds a function to also update the video codec parameters so that the above situation can be fixed in a unified manner.
Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@gmail.com> --- libavcodec/cbs.c | 35 +++++++++++++++++++++++++++++++++++ libavcodec/cbs.h | 15 +++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 47679eca1b..37b080b5ba 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -342,6 +342,41 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, return 0; } +void ff_cbs_update_video_parameters(CodedBitstreamContext *ctx, + AVCodecParameters *par, int profile, + int level, int width, int height, + int field_order, int color_range, + int color_primaries, int color_trc, + int color_space, int chroma_location, + int video_delay) +{ +#define SET_IF_NONNEGATIVE(elem) \ + if (elem >= 0) \ + par->elem = elem; + SET_IF_NONNEGATIVE(profile) + SET_IF_NONNEGATIVE(level) + SET_IF_NONNEGATIVE(width) + SET_IF_NONNEGATIVE(height) + SET_IF_NONNEGATIVE(field_order) + SET_IF_NONNEGATIVE(video_delay) +#undef SET_IF_NONNEGATIVE + +#define SET_IF_VALID(elem, upper_bound) \ + if (0 <= elem && elem < upper_bound) \ + par->elem = elem; + SET_IF_VALID(color_range, AVCOL_RANGE_NB) + SET_IF_VALID(color_trc, AVCOL_TRC_NB) + SET_IF_VALID(color_space, AVCOL_SPC_NB) + SET_IF_VALID(chroma_location, AVCHROMA_LOC_NB) +#undef SET_IF_VALID + + if (0 <= color_primaries && color_primaries <= AVCOL_PRI_SMPTE432 + || color_primaries == AVCOL_PRI_JEDEC_P22) + par->color_primaries = color_primaries; + + return; +} + int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag) diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index e1e6055ceb..1655f790cd 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -304,6 +304,21 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag); +/** + * Update the parameters of an AVCodecParameters structure + * + * If a parameter is negative, the corresponding member is not + * modified. For the color/chroma parameters, only values that + * are part of the relevant enumeration are written. + */ +void ff_cbs_update_video_parameters(CodedBitstreamContext *ctx, + AVCodecParameters *par, int profile, + int level, int width, int height, + int field_order, int color_range, + int color_primaries, int color_trc, + int color_space, int chroma_location, + int video_delay); + /** * Write the bitstream of a fragment to a packet. * -- 2.21.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".