[FFmpeg-cvslog] libx264: only use ABR mode when the user explicitly set bitrate.

Anton Khirnov git at videolan.org
Mon Aug 22 15:32:48 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Aug 20 16:59:47 2011 +0200| [ae60927aefe7a9debc285451b2badf1b8eb5ab22] | committer: Anton Khirnov

libx264: only use ABR mode when the user explicitly set bitrate.

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

 libavcodec/libx264.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 50688fd..44c85fd 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/opt.h"
 #include "avcodec.h"
+#include "internal.h"
 #include <x264.h>
 #include <math.h>
 #include <stdio.h>
@@ -263,7 +264,10 @@ static av_cold int X264_init(AVCodecContext *avctx)
     x4->params.i_log_level          = X264_LOG_DEBUG;
 
     x4->params.b_intra_refresh      = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH;
-    x4->params.rc.i_bitrate         = avctx->bit_rate       / 1000;
+    if (avctx->bit_rate) {
+        x4->params.rc.i_bitrate   = avctx->bit_rate / 1000;
+        x4->params.rc.i_rc_method = X264_RC_ABR;
+    }
     x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
     x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate    / 1000;
     x4->params.rc.b_stat_write      = avctx->flags & CODEC_FLAG_PASS1;
@@ -280,11 +284,6 @@ static av_cold int X264_init(AVCodecContext *avctx)
         }
     }
 
-    // if neither crf nor cqp modes are selected we have to enable the RC
-    // we do it this way because we cannot check if the bitrate has been set
-    if (!(avctx->crf || (avctx->cqp > -1)))
-        x4->params.rc.i_rc_method = X264_RC_ABR;
-
     if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
         (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
         x4->params.rc.f_vbv_buffer_init =
@@ -376,6 +375,11 @@ static const AVClass class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
+static const AVCodecDefault x264_defaults[] = {
+    { "b",                "0" },
+    { NULL },
+};
+
 AVCodec ff_libx264_encoder = {
     .name           = "libx264",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -388,4 +392,5 @@ AVCodec ff_libx264_encoder = {
     .pix_fmts       = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_NONE },
     .long_name      = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
     .priv_class     = &class,
+    .defaults       = x264_defaults,
 };



More information about the ffmpeg-cvslog mailing list