Bump required x264 version, because X264_WEIGHTP_BLIND was renamed to
X264_WEIGHTP_SIMPLE in version 110.
---
 libavcodec/libx264.c |   69 ++++++++++++++++++++++++++++++++++++++++++++-----
 libavcodec/options.c |   20 +++++++++-----
 libavcodec/version.h |    3 ++
 3 files changed, 78 insertions(+), 14 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 5825945..30c1974 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -20,13 +20,16 @@
  */
 
 #include "avcodec.h"
+#include "libavutil/opt.h"
 #include <x264.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <float.h>
 
 typedef struct X264Context {
+    AVClass        *class;
     x264_param_t    params;
     x264_t         *enc;
     x264_picture_t  pic;
@@ -178,7 +181,10 @@ static av_cold int X264_init(AVCodecContext *avctx)
         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;
+#if FF_API_X264_GLOBAL_OPTS
+            if (avctx->crf_max >= 0)
+                x4->params.rc.f_rf_constant_max = avctx->crf_max;
+#endif
         } else if (avctx->cqp > -1) {
             x4->params.rc.i_rc_method   = X264_RC_CQP;
             x4->params.rc.i_qp_constant = avctx->cqp;
@@ -241,7 +247,10 @@ static av_cold int X264_init(AVCodecContext *avctx)
     x4->params.analyse.i_direct_mv_pred  = avctx->directpred;
 
     x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
-    x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred;
+#if FF_API_X264_GLOBAL_OPTS
+    if (avctx->weighted_p_pred)
+        x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred;
+#endif
 
     if (avctx->me_method == ME_EPZS)
         x4->params.analyse.i_me_method = X264_ME_DIA;
@@ -255,13 +264,22 @@ static av_cold int X264_init(AVCodecContext *avctx)
         x4->params.analyse.i_me_method = X264_ME_TESA;
     else x4->params.analyse.i_me_method = X264_ME_HEX;
 
-    x4->params.rc.i_aq_mode               = avctx->aq_mode;
-    x4->params.rc.f_aq_strength           = avctx->aq_strength;
-    x4->params.rc.i_lookahead             = avctx->rc_lookahead;
+#if FF_API_X264_GLOBAL_OPTS
+    if (avctx->aq_mode != 1)
+        x4->params.rc.i_aq_mode               = avctx->aq_mode;
+    if (avctx->aq_strength >= 0)
+        x4->params.rc.f_aq_strength           = avctx->aq_strength;
+    if (avctx->rc_lookahead != 40)
+        x4->params.rc.i_lookahead             = avctx->rc_lookahead;
+#endif
 
     x4->params.analyse.b_psy              = avctx->flags2 & CODEC_FLAG2_PSY;
-    x4->params.analyse.f_psy_rd           = avctx->psy_rd;
-    x4->params.analyse.f_psy_trellis      = avctx->psy_trellis;
+#if FF_API_X264_GLOBAL_OPTS
+    if (avctx->psy_rd >= 0)
+        x4->params.analyse.f_psy_rd           = avctx->psy_rd;
+    if (avctx->psy_trellis >= 0)
+        x4->params.analyse.f_psy_trellis      = avctx->psy_trellis;
+#endif
 
     x4->params.analyse.i_me_range         = avctx->me_range;
     x4->params.analyse.i_subpel_refine    = avctx->me_subpel_quality;
@@ -328,6 +346,42 @@ static av_cold int X264_init(AVCodecContext *avctx)
     return 0;
 }
 
+#define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption options[] = {
+    { "aq_mode", "AQ method", offsetof(X264Context, params.rc.i_aq_mode),
+      FF_OPT_TYPE_INT, X264_AQ_VARIANCE, 0, INT_MAX , FLAGS, "aq_mode"},
+    { "none", NULL, 0, FF_OPT_TYPE_CONST, X264_AQ_NONE, INT_MIN, INT_MAX, 
FLAGS, "aq_mode" },
+    { "variance", "Variance AQ (complexity mask)", 0, FF_OPT_TYPE_CONST,
+      X264_AQ_VARIANCE, INT_MIN, INT_MAX, FLAGS, "aq_mode" },
+    { "autovariance", "Auto-variance AQ (experimental)", 0, FF_OPT_TYPE_CONST,
+      X264_AQ_AUTOVARIANCE, INT_MIN, INT_MAX, FLAGS, "aq_mode" },
+    { "aq_strength", "AQ strength. Reduces blocking and blurring in flat and 
textured areas.",
+      offsetof(X264Context, params.rc.f_aq_strength), FF_OPT_TYPE_FLOAT, 1.0, 
0, FLT_MAX, FLAGS },
+    { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this 
point.",
+       offsetof(X264Context, params.rc.f_rf_constant_max),
+       FF_OPT_TYPE_FLOAT, 0, 0, 51, FLAGS },
+    { "psy_rd", "Psy RD strength", offsetof(X264Context, params.analyse.b_psy),
+      FF_OPT_TYPE_FLOAT, 1.0, 0, FLT_MAX, FLAGS },
+    { "psy_trellis", "Psy trellis strength", offsetof(X264Context, 
params.analyse.f_psy_trellis),
+      FF_OPT_TYPE_FLOAT, 0, 0, FLT_MAX, FLAGS },
+    { "rc_lookahead", "Number of frames to look ahead for frametype and 
ratecontrol",
+      offsetof(X264Context, params.rc.i_lookahead), FF_OPT_TYPE_INT, 40, 0, 
INT_MAX, FLAGS },
+    { "wpredp", "Weighted prediction analysis method",
+      offsetof(X264Context, params.analyse.i_weighted_pred),
+      FF_OPT_TYPE_INT, 0, 0, INT_MAX, FLAGS, "wpredp" },
+    { "none",   NULL, 0, FF_OPT_TYPE_CONST, X264_WEIGHTP_NONE,   INT_MIN, 
INT_MAX, FLAGS, "wpredp" },
+    { "simple", NULL, 0, FF_OPT_TYPE_CONST, X264_WEIGHTP_SIMPLE, INT_MIN, 
INT_MAX, FLAGS, "wpredp" },
+    { "smart",  NULL, 0, FF_OPT_TYPE_CONST, X264_WEIGHTP_SMART,  INT_MIN, 
INT_MAX, FLAGS, "wpredp" },
+    { NULL },
+};
+
+static const AVClass libx264_class = {
+    "libx264",
+    av_default_item_name,
+    options,
+    LIBAVUTIL_VERSION_INT,
+};
+
 AVCodec ff_libx264_encoder = {
     .name           = "libx264",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -339,4 +393,5 @@ AVCodec ff_libx264_encoder = {
     .capabilities   = CODEC_CAP_DELAY,
     .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     = &libx264_class,
 };
diff --git a/libavcodec/options.c b/libavcodec/options.c
index ae8abb2..dc6c032 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -126,7 +126,9 @@ static const AVOption options[]={
 {"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), 
FF_OPT_TYPE_FLOAT, 1.25, -FLT_MAX, FLT_MAX, V|E},
 {"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, 
DEFAULT, INT_MIN, INT_MAX, V|E},
 {"b_strategy", "strategy to choose between I/P/B-frames", 
OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
-{"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), 
FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
+#if FF_API_X264_GLOBAL_OPTS
+{"wpredp", "deprecated, use x264-specific options", OFFSET(weighted_p_pred), 
FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
+#endif
 #if FF_API_HURRY_UP
 {"hurry_up", "deprecated, use skip_idct/skip_frame instead", OFFSET(hurry_up), 
FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
 #endif
@@ -424,14 +426,18 @@ static const AVOption options[]={
 {"color_range", NULL, OFFSET(color_range), FF_OPT_TYPE_INT, 
AVCOL_RANGE_UNSPECIFIED, 0, AVCOL_RANGE_NB-1, V|E|D},
 {"chroma_sample_location", NULL, OFFSET(chroma_sample_location), 
FF_OPT_TYPE_INT, AVCHROMA_LOC_UNSPECIFIED, 0, AVCHROMA_LOC_NB-1, V|E|D},
 {"psy", "use psycho visual optimization", 0, FF_OPT_TYPE_CONST, 
CODEC_FLAG2_PSY, INT_MIN, INT_MAX, V|E, "flags2"},
-{"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), 
FF_OPT_TYPE_FLOAT, 1.0, 0, FLT_MAX, V|E},
-{"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), 
FF_OPT_TYPE_FLOAT, 0, 0, FLT_MAX, V|E},
-{"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, 1, 0, 
INT_MAX, V|E},
-{"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, 
1.0, 0, FLT_MAX, V|E},
-{"rc_lookahead", "specify number of frames to look ahead for frametype", 
OFFSET(rc_lookahead), FF_OPT_TYPE_INT, 40, 0, INT_MAX, V|E},
+#if FF_API_X264_GLOBAL_OPTS
+{"psy_rd", "deprecated, use x264-specific options", OFFSET(psy_rd), 
FF_OPT_TYPE_FLOAT, -1.0, -1.0, FLT_MAX, V|E},
+{"psy_trellis", "deprecated, use x264-specific options", OFFSET(psy_trellis), 
FF_OPT_TYPE_FLOAT, -1.0, -1.0, FLT_MAX, V|E},
+{"aq_mode", "deprecated, use x264-specific options", OFFSET(aq_mode), 
FF_OPT_TYPE_INT, 1, 0, INT_MAX, V|E},
+{"aq_strength", "deprecated, use x264-specific options", OFFSET(aq_strength), 
FF_OPT_TYPE_FLOAT, -1.0, -1.0, FLT_MAX, V|E},
+{"rc_lookahead", "deprecated, use x264-specific options", 
OFFSET(rc_lookahead), FF_OPT_TYPE_INT, 40, 0, INT_MAX, V|E},
+#endif
 {"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, 
CODEC_FLAG2_SSIM, INT_MIN, INT_MAX, V|E, "flags2"},
 {"intra_refresh", "use periodic insertion of intra blocks instead of 
keyframes", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_REFRESH, INT_MIN, INT_MAX, 
V|E, "flags2"},
-{"crf_max", "in crf mode, prevents vbv from lowering quality beyond this 
point", OFFSET(crf_max), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E},
+#if FF_API_X264_GLOBAL_OPTS
+{"crf_max", "deprecated, use x264-specific options", OFFSET(crf_max), 
FF_OPT_TYPE_FLOAT, -1.0, -1.0, 51, V|E},
+#endif
 {"log_level_offset", "set the log level offset", OFFSET(log_level_offset), 
FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX },
 {"lpc_type", "specify LPC algorithm", OFFSET(lpc_type), FF_OPT_TYPE_INT, 
AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, A|E},
 {"none",     NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_NONE,     INT_MIN, 
INT_MAX, A|E, "lpc_type"},
diff --git a/libavcodec/version.h b/libavcodec/version.h
index ec3045f..6f61fa5 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -86,5 +86,8 @@
 #ifndef FF_API_ANTIALIAS_ALGO
 #define FF_API_ANTIALIAS_ALGO   (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 */
-- 
1.7.4.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to