[FFmpeg-devel,29/31] vp9_metadata: Update AVCodecParameters during init

Submitted by Andreas Rheinhardt on July 9, 2019, 1:10 a.m.

Details

Message ID 20190709011048.29601-4-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt July 9, 2019, 1:10 a.m.
This commit changes vp9_metadata to update the AVCodecParameters to
reflect the output bitstream. This brings vp9_metadata in line with what
is expected of a bitstream filter.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/vp9_metadata_bsf.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/vp9_metadata_bsf.c b/libavcodec/vp9_metadata_bsf.c
index 52e962b1c0..0ce017ffea 100644
--- a/libavcodec/vp9_metadata_bsf.c
+++ b/libavcodec/vp9_metadata_bsf.c
@@ -107,7 +107,23 @@  fail:
 
 static int vp9_metadata_init(AVBSFContext *bsf)
 {
+    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
+    };
     VP9MetadataContext *ctx = bsf->priv_data;
+    AVCodecParameters  *par = bsf->par_out;
+
+    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);
 }