[FFmpeg-devel,4/8] mpeg2_metadata: Additionally update AVCodecParameters

Submitted by Andreas Rheinhardt on Dec. 1, 2018, 7:28 p.m.

Details

Message ID 20181201192810.852-5-andreas.rheinhardt@googlemail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Dec. 1, 2018, 7:28 p.m.
Otherwise the muxer could add header data that is based on the old
AVCodecParameters that contradicts and nullifies the modifications
made to the bitstream.
An option to revert to the old behaviour is included.

The documentation has been updated to reflect the change.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
---
 doc/bitstream_filters.texi      |  6 ++++++
 libavcodec/mpeg2_metadata_bsf.c | 11 +++++++++++
 2 files changed, 17 insertions(+)

Patch hide | download patch | download mbox

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 80df345f26..a1558c5d69 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -487,6 +487,12 @@  table 6-6).
 Set the colour description in the stream (see H.262 section 6.3.6
 and tables 6-7, 6-8 and 6-9).
 
+@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 mpeg4_unpack_bframes
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
index e787cb3782..e874f2fbb7 100644
--- a/libavcodec/mpeg2_metadata_bsf.c
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -43,6 +43,8 @@  typedef struct MPEG2MetadataContext {
     int matrix_coefficients;
 
     int mpeg1_warned;
+
+    int full_update;
 } MPEG2MetadataContext;
 
 
@@ -253,6 +255,12 @@  static int mpeg2_metadata_init(AVBSFContext *bsf)
         }
     }
 
+    if (ctx->full_update)
+        ff_cbs_update_video_parameters(ctx->cbc, bsf->par_out, -1, -1, -1,
+                                       -1, -1, -1, ctx->colour_primaries,
+                                       ctx->transfer_characteristics,
+                                       ctx->matrix_coefficients, -1, -1);
+
     err = 0;
 fail:
     ff_cbs_fragment_uninit(ctx->cbc, frag);
@@ -289,6 +297,9 @@  static const AVOption mpeg2_metadata_options[] = {
         OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
         { .i64 = -1 }, -1, 255, FLAGS },
 
+    { "full_update", "Update not only bitstream, but also AVCodecParameters",
+        OFFSET(full_update), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS},
+
     { NULL }
 };