Skip to content

Commit

Permalink
lavc: Deprecate avctx.me_method
Browse files Browse the repository at this point in the history
This option is extremely codec specific and only a few codecs employ it.
Move it to codec private options instead: mpegenc family supports only 3
values, xavs and x264 use 5, and xvid has a different metric entirely.

Signed-off-by: Vittorio Giovara <[email protected]>
  • Loading branch information
kodawah committed Jul 27, 2015
1 parent 03eb557 commit 4b6b108
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 111 deletions.
2 changes: 0 additions & 2 deletions doc/encoders.texi
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,6 @@ options follow the Libav ones.
@tab Noise reduction.
@item me_range @tab merange
@tab Maximum range of the motion search in pixels.
@item me_method @tab me
@tab Full-pixel motion estimation method.
@item subq @tab subme
@tab Sub-pixel motion estimation method.
@item b_strategy @tab b-adapt
Expand Down
14 changes: 8 additions & 6 deletions libavcodec/avcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,9 @@ typedef struct AVCodecDescriptor {
/**
* @ingroup lavc_encoding
* motion estimation type.
* @deprecated use codec private option instead
*/
#if FF_API_MOTION_EST
enum Motion_Est_ID {
ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed
ME_FULL,
Expand All @@ -560,6 +562,7 @@ enum Motion_Est_ID {
ME_UMH, ///< uneven multi-hexagon search
ME_TESA, ///< transformed exhaustive search algorithm
};
#endif

/**
* @ingroup lavc_decoding
Expand Down Expand Up @@ -1281,14 +1284,13 @@ typedef struct AVCodecContext {
*/
enum AVPixelFormat pix_fmt;

#if FF_API_MOTION_EST
/**
* Motion estimation algorithm used for video coding.
* 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
* 8 (umh), 10 (tesa) [7, 8, 10 are x264 specific]
* - encoding: MUST be set by user.
* - decoding: unused
* This option does nothing
* @deprecated use codec private options instead
*/
int me_method;
attribute_deprecated int me_method;
#endif

/**
* If non NULL, 'draw_horiz_band' is called by the libavcodec
Expand Down
39 changes: 28 additions & 11 deletions libavcodec/libx264.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef struct X264Context {
int slice_max_size;
char *stats;
int nal_hrd;
int motion_est;
char *x264_params;
} X264Context;

Expand Down Expand Up @@ -394,17 +395,6 @@ static av_cold int X264_init(AVCodecContext *avctx)
x4->params.rc.f_pb_factor = avctx->b_quant_factor;
x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;

if (avctx->me_method == ME_EPZS)
x4->params.analyse.i_me_method = X264_ME_DIA;
else if (avctx->me_method == ME_HEX)
x4->params.analyse.i_me_method = X264_ME_HEX;
else if (avctx->me_method == ME_UMH)
x4->params.analyse.i_me_method = X264_ME_UMH;
else if (avctx->me_method == ME_FULL)
x4->params.analyse.i_me_method = X264_ME_ESA;
else if (avctx->me_method == ME_TESA)
x4->params.analyse.i_me_method = X264_ME_TESA;

if (avctx->gop_size >= 0)
x4->params.i_keyint_max = avctx->gop_size;
if (avctx->max_b_frames >= 0)
Expand Down Expand Up @@ -493,6 +483,25 @@ static av_cold int X264_init(AVCodecContext *avctx)
if (x4->nal_hrd >= 0)
x4->params.i_nal_hrd = x4->nal_hrd;

if (x4->motion_est >= 0) {
x4->params.analyse.i_me_method = x4->motion_est;
#if FF_API_MOTION_EST
FF_DISABLE_DEPRECATION_WARNINGS
} else {
if (avctx->me_method == ME_EPZS)
x4->params.analyse.i_me_method = X264_ME_DIA;
else if (avctx->me_method == ME_HEX)
x4->params.analyse.i_me_method = X264_ME_HEX;
else if (avctx->me_method == ME_UMH)
x4->params.analyse.i_me_method = X264_ME_UMH;
else if (avctx->me_method == ME_FULL)
x4->params.analyse.i_me_method = X264_ME_ESA;
else if (avctx->me_method == ME_TESA)
x4->params.analyse.i_me_method = X264_ME_TESA;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
}

if (x4->profile)
if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
Expand Down Expand Up @@ -675,6 +684,12 @@ static const AVOption options[] = {
{ "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX, VE, "nal-hrd" },
{ "vbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR}, INT_MIN, INT_MAX, VE, "nal-hrd" },
{ "cbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR}, INT_MIN, INT_MAX, VE, "nal-hrd" },
{ "motion-est", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA, VE, "motion-est"},
{ "dia", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_DIA }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "hex", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_HEX }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "umh", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_UMH }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "esa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_ESA }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "tesa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_TESA }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "x264-params", "Override the x264 configuration using a :-separated list of key=value parameters", OFFSET(x264_params), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
{ NULL },
};
Expand All @@ -694,7 +709,9 @@ static const AVCodecDefault x264_defaults[] = {
{ "trellis", "-1" },
{ "nr", "-1" },
{ "me_range", "-1" },
#if FF_API_MOTION_EST
{ "me_method", "-1" },
#endif
{ "subq", "-1" },
{ "b_strategy", "-1" },
{ "keyint_min", "-1" },
Expand Down
56 changes: 36 additions & 20 deletions libavcodec/libxavs.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct XavsContext {
int direct_pred;
int aud;
int fast_pskip;
int motion_est;
int mbtree;
int mixed_refs;

Expand Down Expand Up @@ -271,13 +272,41 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
if (x4->fast_pskip >= 0)
x4->params.analyse.b_fast_pskip = x4->fast_pskip;
if (x4->motion_est >= 0)
x4->params.analyse.i_me_method = x4->motion_est;
if (x4->mixed_refs >= 0)
x4->params.analyse.b_mixed_references = x4->mixed_refs;
if (x4->b_bias != INT_MIN)
x4->params.i_bframe_bias = x4->b_bias;
if (x4->cplxblur >= 0)
x4->params.rc.f_complexity_blur = x4->cplxblur;

#if FF_API_MOTION_EST
FF_DISABLE_DEPRECATION_WARNINGS
if (x4->motion_est < 0) {
switch (avctx->me_method) {
case ME_EPZS:
x4->params.analyse.i_me_method = XAVS_ME_DIA;
break;
case ME_HEX:
x4->params.analyse.i_me_method = XAVS_ME_HEX;
break;
case ME_UMH:
x4->params.analyse.i_me_method = XAVS_ME_UMH;
break;
case ME_FULL:
x4->params.analyse.i_me_method = XAVS_ME_ESA;
break;
case ME_TESA:
x4->params.analyse.i_me_method = XAVS_ME_TESA;
break;
default:
x4->params.analyse.i_me_method = XAVS_ME_HEX;
}
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif

x4->params.i_bframe = avctx->max_b_frames;
/* cabac is not included in AVS JiZhun Profile */
x4->params.b_cabac = 0;
Expand Down Expand Up @@ -314,26 +343,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
x4->params.i_fps_den = avctx->time_base.num;
x4->params.analyse.inter = XAVS_ANALYSE_I8x8 |XAVS_ANALYSE_PSUB16x16| XAVS_ANALYSE_BSUB16x16;

switch (avctx->me_method) {
case ME_EPZS:
x4->params.analyse.i_me_method = XAVS_ME_DIA;
break;
case ME_HEX:
x4->params.analyse.i_me_method = XAVS_ME_HEX;
break;
case ME_UMH:
x4->params.analyse.i_me_method = XAVS_ME_UMH;
break;
case ME_FULL:
x4->params.analyse.i_me_method = XAVS_ME_ESA;
break;
case ME_TESA:
x4->params.analyse.i_me_method = XAVS_ME_TESA;
break;
default:
x4->params.analyse.i_me_method = XAVS_ME_HEX;
}

x4->params.analyse.i_me_range = avctx->me_range;
x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;

Expand Down Expand Up @@ -423,6 +432,13 @@ static const AVOption options[] = {
{ "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 1, VE},
{ "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE },
{ "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 1, VE},
{ "motion-est", "Set motion estimation method", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, XAVS_ME_TESA, VE, "motion-est"},
{ "dia", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_ME_DIA }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "hex", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_ME_HEX }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "umh", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_ME_UMH }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "esa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_ME_ESA }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "tesa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_ME_TESA }, INT_MIN, INT_MAX, VE, "motion-est" },

{ NULL },
};

Expand Down
43 changes: 32 additions & 11 deletions libavcodec/libxvid.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct xvid_context {
int ssim; /**< SSIM information display mode */
int ssim_acc; /**< SSIM accuracy. 0: accurate. 4: fast. */
int gmc;
int me_quality; /**< Motion estimation quality. 0: fast 6: best. */
};

/**
Expand Down Expand Up @@ -379,26 +380,45 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx)

/* Decide which ME quality setting to use */
x->me_flags = 0;
switch (avctx->me_method) {
case ME_FULL: /* Quality 6 */
switch (x->me_quality) {
case 6:
case 5:
x->me_flags |= XVID_ME_EXTSEARCH16 |
XVID_ME_EXTSEARCH8;

case ME_EPZS: /* Quality 4 */
case 4:
case 3:
x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 |
XVID_ME_HALFPELREFINE8 |
XVID_ME_CHROMA_PVOP |
XVID_ME_CHROMA_BVOP;

case ME_LOG: /* Quality 2 */
case ME_PHODS:
case ME_X1:
case 2:
case 1:
x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 |
XVID_ME_HALFPELREFINE16;

case ME_ZERO: /* Quality 0 */
default:
#if FF_API_MOTION_EST
FF_DISABLE_DEPRECATION_WARNINGS
break;
default:
switch (avctx->me_method) {
case ME_FULL: /* Quality 6 */
x->me_flags |= XVID_ME_EXTSEARCH16 |
XVID_ME_EXTSEARCH8;
case ME_EPZS: /* Quality 4 */
x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 |
XVID_ME_HALFPELREFINE8 |
XVID_ME_CHROMA_PVOP |
XVID_ME_CHROMA_BVOP;
case ME_LOG: /* Quality 2 */
case ME_PHODS:
case ME_X1:
x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 |
XVID_ME_HALFPELREFINE16;
case ME_ZERO: /* Quality 0 */
default:
break;
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif
}

/* Decide how we should decide blocks */
Expand Down Expand Up @@ -828,6 +848,7 @@ static const AVOption options[] = {
{ "frame", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "ssim" },
{ "ssim_acc", "SSIM accuracy", OFFSET(ssim_acc), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, 4, VE },
{ "gmc", "use GMC", OFFSET(gmc), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "me_quality", "Motion estimation quality", OFFSET(me_quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 6, VE },
{ NULL },
};

Expand Down
Loading

0 comments on commit 4b6b108

Please sign in to comment.