[FFmpeg-cvslog] libx264: add 'crf' private option.

Anton Khirnov git at videolan.org
Wed Aug 24 20:34:16 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Aug 22 07:55:34 2011 +0200| [d5dc8cc2974c816ba964692b75c9f17f40830414] | committer: Anton Khirnov

libx264: add 'crf' private option.

Deprecate corresponding global option.

Ideally all x264 private options should be generated automatically, but
x264 doesn't provide the API for this yet.

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

 libavcodec/avcodec.h |    5 ++++-
 libavcodec/libx264.c |   13 ++++++++++++-
 libavcodec/options.c |    2 ++
 libavcodec/version.h |    3 +++
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 5698f51..350708d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2377,12 +2377,15 @@ typedef struct AVCodecContext {
      */
     int brd_scale;
 
+#if FF_API_X264_GLOBAL_OPTS
     /**
      * constant rate factor - quality-based VBR - values ~correspond to qps
      * - encoding: Set by user.
      * - decoding: unused
+     *   @deprecated use 'crf' libx264 private option
      */
-    float crf;
+    attribute_deprecated float crf;
+#endif
 
     /**
      * constant quantization parameter rate control method
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 44c85fd..bd7955a 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -23,6 +23,7 @@
 #include "avcodec.h"
 #include "internal.h"
 #include <x264.h>
+#include <float.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -40,6 +41,7 @@ typedef struct X264Context {
     char *tune;
     char *profile;
     int fastfirstpass;
+    float crf;
 } X264Context;
 
 static void X264_log(void *p, int level, const char *fmt, va_list args)
@@ -274,14 +276,22 @@ static av_cold int X264_init(AVCodecContext *avctx)
     if (avctx->flags & CODEC_FLAG_PASS2) {
         x4->params.rc.b_stat_read = 1;
     } else {
+#if FF_API_X264_GLOBAL_OPTS
         if (avctx->crf) {
             x4->params.rc.i_rc_method   = X264_RC_CRF;
             x4->params.rc.f_rf_constant = avctx->crf;
             x4->params.rc.f_rf_constant_max = avctx->crf_max;
-        } else if (avctx->cqp > -1) {
+        } else
+#endif
+               if (avctx->cqp > -1) {
             x4->params.rc.i_rc_method   = X264_RC_CQP;
             x4->params.rc.i_qp_constant = avctx->cqp;
         }
+
+        if (x4->crf >= 0) {
+            x4->params.rc.i_rc_method   = X264_RC_CRF;
+            x4->params.rc.f_rf_constant = x4->crf;
+        }
     }
 
     if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
@@ -365,6 +375,7 @@ static const AVOption options[] = {
     { "tune",          "Tune the encoding params (cf. x264 --fullhelp)",  OFFSET(tune),          FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
     { "profile",       "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile),       FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
     { "fastfirstpass", "Use fast settings when encoding first pass",      OFFSET(fastfirstpass), FF_OPT_TYPE_INT,    { 1 }, 0, 1, VE},
+    { "crf",           "Select the quality for constant quality mode",    OFFSET(crf),           FF_OPT_TYPE_FLOAT,  {-1 }, -1, FLT_MAX, VE },
     { NULL },
 };
 
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 47886e8..3cef24c 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -375,7 +375,9 @@ static const AVOption options[]={
 {"all"             , NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AVDISCARD_ALL     }, INT_MIN, INT_MAX, V|D, "avdiscard"},
 {"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 4, V|E},
 {"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 10, V|E},
+#if FF_API_X264_GLOBAL_OPTS
 {"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E},
+#endif
 {"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E},
 {"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, {.dbl = 25 }, INT_MIN, INT_MAX, V|E},
 {"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 43efcaf..889e945 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -83,5 +83,8 @@
 #ifndef FF_API_AVCODEC_INIT
 #define FF_API_AVCODEC_INIT     (LIBAVCODEC_VERSION_MAJOR < 54)
 #endif
+#ifndef FF_API_X264_GLOBAL_OPTS
+#define FF_API_X264_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
 
 #endif /* AVCODEC_VERSION_H */



More information about the ffmpeg-cvslog mailing list