[FFmpeg-devel] [PATCH 29/31] vp9_metadata: Update AVCodecParameters

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Thu Jun 20 02:45:19 EEST 2019


This commit adds an option to not only update the bitstream parameters
when using the vp9_metadata bitstream filter, but also the relevant
AVCodecParameters. The new option is on by default.

This commit also adds documentation for this value.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 doc/bitstream_filters.texi    |  7 +++++++
 libavcodec/vp9_metadata_bsf.c | 24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index c9dff7ae03..80be525e0f 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -680,6 +680,13 @@ imposed by the color space will take precedence over this value.
 @item tv
 @item pc
 @end table
+
+ at item full_update
+If this is set, an effort is made to update the AVCodecParameters in addition
+to the bitstream. If unset, muxers might add header information based upon
+the old AVCodecParameters that contradicts and potentially precedes
+the changes made at the bitstream level. On by default.
+
 @end table
 
 @section vp9_superframe
diff --git a/libavcodec/vp9_metadata_bsf.c b/libavcodec/vp9_metadata_bsf.c
index 52e962b1c0..338d6d2af3 100644
--- a/libavcodec/vp9_metadata_bsf.c
+++ b/libavcodec/vp9_metadata_bsf.c
@@ -34,6 +34,8 @@ typedef struct VP9MetadataContext {
     int color_range;
 
     int color_warnings;
+
+    int full_update;
 } VP9MetadataContext;
 
 
@@ -109,6 +111,25 @@ static int vp9_metadata_init(AVBSFContext *bsf)
 {
     VP9MetadataContext *ctx = bsf->priv_data;
 
+    if (ctx->full_update) {
+        AVCodecParameters *par = bsf->par_out;
+        static const uint8_t conversion_table[8] = {
+            AVCOL_SPC_UNSPECIFIED, AVCOL_SPC_BT470BG,
+            AVCOL_SPC_BT709,       AVCOL_SPC_SMPTE170M,
+            AVCOL_SPC_SMPTE240M,   AVCOL_SPC_BT2020_NCL,
+            AVCOL_SPC_RESERVED,    AVCOL_SPC_RGB
+        };
+
+        if (ctx->color_space >= 0 && (par->profile & 1 ||
+                                      ctx->color_space != VP9_CS_RGB))
+            par->color_space = conversion_table[ctx->color_space];
+
+        if (par->color_space == AVCOL_SPC_RGB)
+            par->color_range = AVCOL_RANGE_JPEG;
+        else if (ctx->color_range >= 0)
+            par->color_range = ctx->color_range + 1;
+    }
+
     return ff_cbs_init(&ctx->cbc, AV_CODEC_ID_VP9, bsf);
 }
 
@@ -149,6 +170,9 @@ static const AVOption vp9_metadata_options[] = {
     { "pc", "PC (full) range",    0, AV_OPT_TYPE_CONST,
         { .i64 = 1 }, .flags = FLAGS, .unit = "cr" },
 
+    { "full_update", "Update not only bitstream, but also AVCodecParameters",
+        OFFSET(full_update), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS},
+
     { NULL }
 };
 
-- 
2.21.0



More information about the ffmpeg-devel mailing list