[FFmpeg-cvslog] libavcodec/libx264: fix reference frame computation based on level

Josh Brewster git at videolan.org
Wed Apr 29 14:13:06 EEST 2020


ffmpeg | branch: master | Josh Brewster <josh.brewster at protonmail.com> | Thu Apr 16 22:50:29 2020 +0200| [79f001675a2bae16e243f30a3e7de9da6aeb3c2d] | committer: Josh de Kock

libavcodec/libx264: fix reference frame computation based on level

The current implementation allows passing levels to libavcodec as
integers (such as "31" instead of "3.1").

However, in this case, the maximum reference frame value per level was
ignored because libavcodec converted the string to 310 instead of 31.

Since libx264 has correctly parsed the level to int
(x4->params.i_level_idc), we should rely on this value instead of
attempting to parse the level string on our own.

Signed-off-by: Josh Brewster <josh.brewster at protonmail.com>
Signed-off-by: Josh de Kock <josh at itanimul.li>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=79f001675a2bae16e243f30a3e7de9da6aeb3c2d
---

 libavcodec/libx264.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index a08fe0ce76..c6cce9ff80 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -692,25 +692,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
         x4->params.rc.f_qcompress       = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
     if (avctx->refs >= 0)
         x4->params.i_frame_reference    = avctx->refs;
-    else if (x4->level) {
+    else if (x4->params.i_level_idc > 0) {
         int i;
         int mbn = AV_CEIL_RSHIFT(avctx->width, 4) * AV_CEIL_RSHIFT(avctx->height, 4);
-        int level_id = -1;
-        char *tail;
         int scale = X264_BUILD < 129 ? 384 : 1;
 
-        if (!strcmp(x4->level, "1b")) {
-            level_id = 9;
-        } else if (strlen(x4->level) <= 3){
-            level_id = av_strtod(x4->level, &tail) * 10 + 0.5;
-            if (*tail)
-                level_id = -1;
-        }
-        if (level_id <= 0)
-            av_log(avctx, AV_LOG_WARNING, "Failed to parse level\n");
-
         for (i = 0; i<x264_levels[i].level_idc; i++)
-            if (x264_levels[i].level_idc == level_id)
+            if (x264_levels[i].level_idc == x4->params.i_level_idc)
                 x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / mbn / scale, 1, x4->params.i_frame_reference);
     }
 



More information about the ffmpeg-cvslog mailing list