[FFmpeg-devel,27/31] mpeg2_metadata: Additionally update AVCodecParameters

Submitted by Andreas Rheinhardt on June 19, 2019, 11:45 p.m.

Details

Message ID 20190619234521.15619-19-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt June 19, 2019, 11:45 p.m.
Otherwise the muxer could add header data that is based on the old
AVCodecParameters that contradicts and potentially 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@gmail.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 f625c8f768..e5ce7bc0a3 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -490,6 +490,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 3f371a028d..8396922979 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;
 
 
@@ -249,6 +251,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_reset(ctx->cbc, frag);
@@ -287,6 +295,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 }
 };