[PATCH] avcodec/libx264: Implement reference frame count limiting based on level
This makes libavcodec/libx264.c behave more similar to the x264 command line util Fixes Ticket3307 Implementation based on x264 Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/libx264.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index d9130b2..474c247 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/eval.h" #include "libavutil/internal.h" #include "libavutil/opt.h" #include "libavutil/mem.h" @@ -426,6 +427,28 @@ static av_cold int X264_init(AVCodecContext *avctx) 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) { + int i; + int mbn = FF_CEIL_RSHIFT(avctx->width, 4) * FF_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) + x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / mbn / scale, 1, x4->params.i_frame_reference); + } + if (avctx->trellis >= 0) x4->params.analyse.i_trellis = avctx->trellis; if (avctx->me_range >= 0) -- 1.7.9.5
On Sat, 12 Apr 2014 16:50:05 +0200, Michael Niedermayer wrote:
This makes libavcodec/libx264.c behave more similar to the x264 command line util
Fixes Ticket3307
Implementation based on x264
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/libx264.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
This seems to work for me based on some limited testing. I'm not qualified to review the path, however.
On 4/12/2014 3:50 PM, Michael Niedermayer wrote:
This makes libavcodec/libx264.c behave more similar to the x264 command line util
Fixes Ticket3307
Implementation based on x264
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/libx264.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
The idea seems solid, but maybe we could add a message? The silent functionality might catch people off guard. - Derek
On 22/04/14 4:18 PM, Derek Buitenhuis wrote:
On 4/12/2014 3:50 PM, Michael Niedermayer wrote:
This makes libavcodec/libx264.c behave more similar to the x264 command line util
Fixes Ticket3307
Implementation based on x264
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/libx264.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
The idea seems solid, but maybe we could add a message?
The silent functionality might catch people off guard.
- Derek
Maybe a changelog entry? That file is kinda being underused after all. The average user doesn't check commit messages, or the git repo for that matter. Also maybe a micro version bump since the effect of the "level" option is changing.
On 4/22/2014 9:26 PM, James Almer wrote:
Maybe a changelog entry? That file is kinda being underused after all. The average user doesn't check commit messages, or the git repo for that matter.
Also maybe a micro version bump since the effect of the "level" option is changing.
As long as its noted somehow. - Derek
On Tue, Apr 22, 2014 at 09:30:58PM +0100, Derek Buitenhuis wrote:
On 4/22/2014 9:26 PM, James Almer wrote:
Maybe a changelog entry? That file is kinda being underused after all. The average user doesn't check commit messages, or the git repo for that matter.
Also maybe a micro version bump since the effect of the "level" option is changing.
As long as its noted somehow.
ok, applied thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have never wished to cater to the crowd; for what I know they do not approve, and what they approve I do not know. -- Epicurus
participants (4)
-
Derek Buitenhuis -
James Almer -
Lou Logan -
Michael Niedermayer