diff mbox

[FFmpeg-devel,4/4] h264_metadata: Don't use inferred value of buffering frames

Message ID 20181112141815.4472-5-andreas.rheinhardt@googlemail.com
State Accepted
Headers show

Commit Message

Andreas Rheinhardt Nov. 12, 2018, 2:18 p.m. UTC
Using the value of buffering frames inferred from the old level is
not a sensible approach when one wants to guess the level.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
---
 libavcodec/h264_metadata_bsf.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Mark Thompson Nov. 13, 2018, 9:24 p.m. UTC | #1
On 12/11/18 14:18, Andreas Rheinhardt wrote:
> Using the value of buffering frames inferred from the old level is
> not a sensible approach when one wants to guess the level.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
> ---
>  libavcodec/h264_metadata_bsf.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
> index 7fe213e8cd..cb3e45e8b3 100644
> --- a/libavcodec/h264_metadata_bsf.c
> +++ b/libavcodec/h264_metadata_bsf.c
> @@ -222,7 +222,7 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
>          if (ctx->level == LEVEL_AUTO) {
>              const H264LevelDescriptor *desc;
>              int64_t bit_rate;
> -            int width, height;
> +            int width, height, frames;
>  
>              if (sps->vui.nal_hrd_parameters_present_flag) {
>                  bit_rate = (sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
> @@ -236,13 +236,16 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
>                  bit_rate = 0;
>              }
>  
> +            // Don't use max_dec_frame_buffering if it is only inferred.
> +            frames = sps->vui.bitstream_restriction_flag
> +                   ? sps->vui.max_dec_frame_buffering : H264_MAX_DPB_FRAMES;
> +
>              width  = 16 * (sps->pic_width_in_mbs_minus1 + 1);
>              height = 16 * (sps->pic_height_in_map_units_minus1 + 1) *
>                  (2 - sps->frame_mbs_only_flag);
>  
>              desc = ff_h264_guess_level(sps->profile_idc, bit_rate,
> -                                       width, height,
> -                                       sps->vui.max_dec_frame_buffering);
> +                                       width, height, frames);
>              if (desc) {
>                  if ((desc->level_idc == 11) && desc->constraint_set3_flag)
>                      // This ensures that for level 1b the correct level
> 

LGTM, applied.

Thanks,

- Mark
diff mbox

Patch

diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 7fe213e8cd..cb3e45e8b3 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -222,7 +222,7 @@  static int h264_metadata_update_sps(AVBSFContext *bsf,
         if (ctx->level == LEVEL_AUTO) {
             const H264LevelDescriptor *desc;
             int64_t bit_rate;
-            int width, height;
+            int width, height, frames;
 
             if (sps->vui.nal_hrd_parameters_present_flag) {
                 bit_rate = (sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
@@ -236,13 +236,16 @@  static int h264_metadata_update_sps(AVBSFContext *bsf,
                 bit_rate = 0;
             }
 
+            // Don't use max_dec_frame_buffering if it is only inferred.
+            frames = sps->vui.bitstream_restriction_flag
+                   ? sps->vui.max_dec_frame_buffering : H264_MAX_DPB_FRAMES;
+
             width  = 16 * (sps->pic_width_in_mbs_minus1 + 1);
             height = 16 * (sps->pic_height_in_map_units_minus1 + 1) *
                 (2 - sps->frame_mbs_only_flag);
 
             desc = ff_h264_guess_level(sps->profile_idc, bit_rate,
-                                       width, height,
-                                       sps->vui.max_dec_frame_buffering);
+                                       width, height, frames);
             if (desc) {
                 if ((desc->level_idc == 11) && desc->constraint_set3_flag)
                     // This ensures that for level 1b the correct level