diff mbox

[FFmpeg-devel,6/8] vp9_metadata: Update AVCodecParameters

Message ID 20181201192810.852-7-andreas.rheinhardt@googlemail.com
State Superseded
Headers show

Commit Message

Andreas Rheinhardt Dec. 1, 2018, 7:28 p.m. UTC
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@googlemail.com>
---
 doc/bitstream_filters.texi    | 15 ++++++++++-----
 libavcodec/vp9_metadata_bsf.c | 21 +++++++++++++++++++++
 2 files changed, 31 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 7ab535b58c..f5bf4aa93e 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -656,9 +656,7 @@  Modify metadata embedded in a VP9 stream.
 
 @table @option
 @item color_space
-Set the color space value in the frame header. Note that any frame
-set to RGB will be implicitly set to PC range and that RGB is
-incompatible with profiles 0 and 2.
+Set the color space value in the frame header.
 @table @samp
 @item unknown
 @item bt601
@@ -670,12 +668,19 @@  incompatible with profiles 0 and 2.
 @end table
 
 @item color_range
-Set the color range value in the frame header. Note that any value
-imposed by the color space will take precedence over this value.
+Set the color range value in the frame header.  Note that this cannot
+be set in RGB streams.
 @table @samp
 @item tv
 @item pc
 @end table
+
+@item full_update
+If this is set, the AVCodecParameters are updated 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 9170083c06..1b03a4dea4 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;
 
 
@@ -115,6 +117,22 @@  static int vp9_metadata_init(AVBSFContext *bsf)
 {
     VP9MetadataContext *ctx = bsf->priv_data;
 
+    if (ctx->full_update) {
+        AVCodecParameters *par = bsf->par_out;
+        static const enum AVColorSpace colorspaces[] = {
+            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 && (ctx->color_space != VP9_CS_RGB || par->profile & 1))
+            par->color_space = colorspaces[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);
 }
 
@@ -153,6 +171,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 }
 };