[FFmpeg-devel] [PATCH] Correctly set low_delay_hrd_flag when rewriting fixed_frame_rate_flag in h264_metadata bitstream filter

Keshav Varma keshavdv at gmail.com
Sat Feb 5 01:00:55 EET 2022


After changes like ef13faf, the h264_metadata bitstream filter stopped
working when using the fixed_frame_rate_flag option on an input stream
that doesn't contain VUI because the default inferred value of
low_hrd_delay_flag seems to be 1. ffmpeg used to raise a warning, but
proceeded anyway but now aborts after the other fixes since the output
is rightfully invalid.

I believe this change makes the bitstream filter conform to page 403
of the ITU spec: "When fixed_frame_rate_flag is equal to 1,
low_delay_hrd_flag shall be equal to 0. When low_delay_hrd_flag is not
present, its value shall be inferred to be equal to 1 −
fixed_frame_rate_flag."

Signed-off-by: Keshav Varma <keshavdv at gmail.com>
---
 libavcodec/h264_metadata_bsf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 9df99cbae3..59a7eba546 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -228,7 +228,13 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
         sps->vui.timing_info_present_flag = 1;
         need_vui = 1;
     }
-    SET_VUI_FIELD(fixed_frame_rate_flag);
+
+    // Set fixed frame rate flag and update low_delay_hrd_flag to match
+    if (ctx->fixed_frame_rate_flag >= 0) {
+        sps->vui.fixed_frame_rate_flag = ctx->fixed_frame_rate_flag;
+        sps->vui.low_delay_hrd_flag = 1 - sps->vui.fixed_frame_rate_flag;
+    }
+
     if (ctx->zero_new_constraint_set_flags) {
         sps->constraint_set4_flag = 0;
         sps->constraint_set5_flag = 0;
--
2.31.1


More information about the ffmpeg-devel mailing list