summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libavcodec/avcodec.h5
-rw-r--r--libavcodec/libx264.c13
-rw-r--r--libavcodec/options.c2
-rw-r--r--libavcodec/version.h3
4 files changed, 21 insertions, 2 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 5698f512a5..350708da08 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 44c85fdef6..bd7955a2a3 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 47886e8444..3cef24c3d2 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 43efcafc5b..889e945082 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 */