From 4b6b1082a73907c7c3de2646c6398bc61320f2c6 Mon Sep 17 00:00:00 2001 From: Vittorio Giovara Date: Tue, 7 Jul 2015 01:20:43 +0100 Subject: [PATCH] lavc: Deprecate avctx.me_method 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 --- doc/encoders.texi | 2 - libavcodec/avcodec.h | 14 ++--- libavcodec/libx264.c | 39 ++++++++++---- libavcodec/libxavs.c | 56 ++++++++++++------- libavcodec/libxvid.c | 43 +++++++++++---- libavcodec/motion_est.c | 108 ++++++++++++++++++------------------- libavcodec/motion_est.h | 4 ++ libavcodec/mpegvideo.h | 7 +++ libavcodec/mpegvideo_enc.c | 4 ++ libavcodec/options_table.h | 2 + libavcodec/svq1enc.c | 32 +++++++++++ libavcodec/svq1enc.h | 2 + libavcodec/version.h | 5 +- libavcodec/wmv2enc.c | 8 +++ 14 files changed, 218 insertions(+), 108 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 94d834077a..779a469214 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -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 diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 290de70f9c..6fb3c0fc35 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -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, @@ -560,6 +562,7 @@ enum Motion_Est_ID { ME_UMH, ///< uneven multi-hexagon search ME_TESA, ///< transformed exhaustive search algorithm }; +#endif /** * @ingroup lavc_decoding @@ -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 diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 7d719d4e3a..531d8970d7 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -76,6 +76,7 @@ typedef struct X264Context { int slice_max_size; char *stats; int nal_hrd; + int motion_est; char *x264_params; } X264Context; @@ -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) @@ -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); @@ -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 }, }; @@ -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" }, diff --git a/libavcodec/libxavs.c b/libavcodec/libxavs.c index 446e2336eb..f62c65b75a 100644 --- a/libavcodec/libxavs.c +++ b/libavcodec/libxavs.c @@ -53,6 +53,7 @@ typedef struct XavsContext { int direct_pred; int aud; int fast_pskip; + int motion_est; int mbtree; int mixed_refs; @@ -271,6 +272,8 @@ 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) @@ -278,6 +281,32 @@ static av_cold int XAVS_init(AVCodecContext *avctx) 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; @@ -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; @@ -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 }, }; diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c index 7b25c628b2..243caaa94b 100644 --- a/libavcodec/libxvid.c +++ b/libavcodec/libxvid.c @@ -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. */ }; /** @@ -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 */ @@ -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 }, }; diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index d0c0439319..83d7b39e91 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -309,12 +309,25 @@ int ff_init_me(MpegEncContext *s){ av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n"); return -1; } - if (s->me_method != ME_ZERO && - s->me_method != ME_EPZS && - s->me_method != ME_X1) { - av_log(s->avctx, AV_LOG_ERROR, "me_method is only allowed to be set to zero and epzs; for hex,umh,full and others see dia_size\n"); - return -1; + +#if FF_API_MOTION_EST +FF_DISABLE_DEPRECATION_WARNINGS + if (s->motion_est == FF_ME_EPZS) { + if (s->me_method == ME_ZERO) + s->motion_est = FF_ME_ZERO; + else if (s->me_method == ME_EPZS) + s->motion_est = FF_ME_EPZS; + else if (s->me_method == ME_X1) + s->motion_est = FF_ME_XONE; + else { + av_log(s->avctx, AV_LOG_ERROR, + "me_method is only allowed to be set to zero and epzs; " + "for hex,umh,full and others see dia_size\n"); + return -1; + } } +FF_ENABLE_DEPRECATION_WARNINGS +#endif c->avctx= s->avctx; @@ -863,7 +876,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, { MotionEstContext * const c= &s->me; uint8_t *pix, *ppix; - int sum, mx, my, dmin; + int sum, mx = 0, my = 0, dmin = 0; int varc; ///< the variance of the block (sum of squared (p[y][x]-average)) int vard; ///< sum of squared differences with the estimated motion vector int P[10][2]; @@ -895,52 +908,43 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8; c->mb_var_sum_temp += (varc+128)>>8; - switch(s->me_method) { - case ME_ZERO: - default: - mx = 0; - my = 0; - dmin = 0; - break; - case ME_X1: - case ME_EPZS: - { - const int mot_stride = s->b8_stride; - const int mot_xy = s->block_index[0]; + if (s->motion_est != FF_ME_ZERO) { + const int mot_stride = s->b8_stride; + const int mot_xy = s->block_index[0]; - P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0]; - P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1]; + P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0]; + P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1]; - if(P_LEFT[0] > (c->xmax<xmax< (c->xmax << shift)) + P_LEFT[0] = c->xmax << shift; - if(!s->first_slice_line) { - P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0]; - P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1]; - P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0]; - P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1]; - if(P_TOP[1] > (c->ymax<ymax<xmin<xmin< (c->ymax<ymax<first_slice_line) { + P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0]; + P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1]; + P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0]; + P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1]; + if (P_TOP[1] > (c->ymax << shift)) + P_TOP[1] = c->ymax << shift; + if (P_TOPRIGHT[0] < (c->xmin << shift)) + P_TOPRIGHT[0] = c->xmin << shift; + if (P_TOPRIGHT[1] > (c->ymax << shift)) + P_TOPRIGHT[1] = c->ymax << shift; - P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); - P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); + P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); + P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); - if(s->out_format == FMT_H263){ - c->pred_x = P_MEDIAN[0]; - c->pred_y = P_MEDIAN[1]; - }else { /* mpeg1 at least */ - c->pred_x= P_LEFT[0]; - c->pred_y= P_LEFT[1]; - } - }else{ - c->pred_x= P_LEFT[0]; - c->pred_y= P_LEFT[1]; + if (s->out_format == FMT_H263) { + c->pred_x = P_MEDIAN[0]; + c->pred_y = P_MEDIAN[1]; + } else { /* mpeg1 at least */ + c->pred_x = P_LEFT[0]; + c->pred_y = P_LEFT[1]; } - + } else { + c->pred_x = P_LEFT[0]; + c->pred_y = P_LEFT[1]; } dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16); - - break; } /* At this point (mx,my) are full-pell and the relative displacement */ @@ -1100,7 +1104,7 @@ static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y, int16_t (*mv_table)[2], int ref_index, int f_code) { MotionEstContext * const c= &s->me; - int mx, my, dmin; + int mx = 0, my = 0, dmin = 0; int P[10][2]; const int shift= 1+s->quarter_sample; const int mot_stride = s->mb_stride; @@ -1115,15 +1119,7 @@ static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y, get_limits(s, 16*mb_x, 16*mb_y); - switch(s->me_method) { - case ME_ZERO: - default: - mx = 0; - my = 0; - dmin = 0; - break; - case ME_X1: - case ME_EPZS: + if (s->motion_est != FF_ME_ZERO) { P_LEFT[0] = mv_table[mot_xy - 1][0]; P_LEFT[1] = mv_table[mot_xy - 1][1]; @@ -1152,8 +1148,6 @@ static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y, } dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16); - - break; } dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16); @@ -1592,7 +1586,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s, /* find best f_code for ME which do unlimited searches */ int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type) { - if(s->me_method>=ME_EPZS){ + if (s->motion_est != FF_ME_ZERO) { int score[8]; int i, y, range= s->avctx->me_range ? s->avctx->me_range : (INT_MAX/2); uint8_t * fcode_tab= s->fcode_tab; diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h index 4ffe70ed30..a5c662f8c5 100644 --- a/libavcodec/motion_est.h +++ b/libavcodec/motion_est.h @@ -31,6 +31,10 @@ struct MpegEncContext; #define MAX_MV 2048 +#define FF_ME_ZERO 0 +#define FF_ME_EPZS 1 +#define FF_ME_XONE 2 + /** * Motion estimation context. */ diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index cba9836d12..cb449faef2 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -256,7 +256,10 @@ typedef struct MpegEncContext { int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced b-frame encoding uint8_t (*p_field_select_table[2]); uint8_t (*b_field_select_table[2][2]); +#if FF_API_MOTION_EST int me_method; ///< ME algorithm +#endif + int motion_est; ///< ME algorithm int mv_dir; #define MV_DIR_FORWARD 1 #define MV_DIR_BACKWARD 2 @@ -576,6 +579,10 @@ typedef struct MpegEncContext { {"ibias", "intra quant bias", FF_MPV_OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.i64 = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"pbias", "inter quant bias", FF_MPV_OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.i64 = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"rc_strategy", "ratecontrol method", FF_MPV_OFFSET(rc_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS }, \ +{"motion_est", "motion estimation algorithm", FF_MPV_OFFSET(motion_est), AV_OPT_TYPE_INT, {.i64 = FF_ME_EPZS }, FF_ME_ZERO, FF_ME_XONE, FF_MPV_OPT_FLAGS, "motion_est" }, \ +{ "zero", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_ZERO }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \ +{ "epzs", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_EPZS }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \ +{ "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \ extern const AVOption ff_mpv_generic_options[]; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 770f66c9e5..b348e984a1 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -324,7 +324,11 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->intra_only = 0; } +#if FF_API_MOTION_EST +FF_DISABLE_DEPRECATION_WARNINGS s->me_method = avctx->me_method; +FF_ENABLE_DEPRECATION_WARNINGS +#endif /* Fixed QSCALE */ s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index 4fc59ffa8a..c5b2f76659 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -84,6 +84,7 @@ static const AVOption avcodec_options[] = { {"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"}, {"ignorecrop", "ignore cropping information from sps", 1, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_IGNORE_CROP }, INT_MIN, INT_MAX, V|D, "flags2"}, {"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.i64 = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"}, +#if FF_API_MOTION_EST {"me_method", "set motion estimation method", OFFSET(me_method), AV_OPT_TYPE_INT, {.i64 = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method"}, {"zero", "zero motion estimation (fastest)", 0, AV_OPT_TYPE_CONST, {.i64 = ME_ZERO }, INT_MIN, INT_MAX, V|E, "me_method" }, {"full", "full motion estimation (slowest)", 0, AV_OPT_TYPE_CONST, {.i64 = ME_FULL }, INT_MIN, INT_MAX, V|E, "me_method" }, @@ -96,6 +97,7 @@ static const AVOption avcodec_options[] = { {"x1", "X1 motion estimation", 0, AV_OPT_TYPE_CONST, {.i64 = ME_X1 }, INT_MIN, INT_MAX, V|E, "me_method" }, {"hex", "hex motion estimation", 0, AV_OPT_TYPE_CONST, {.i64 = ME_HEX }, INT_MIN, INT_MAX, V|E, "me_method" }, {"umh", "umh motion estimation", 0, AV_OPT_TYPE_CONST, {.i64 = ME_UMH }, INT_MIN, INT_MAX, V|E, "me_method" }, +#endif {"extradata_size", NULL, OFFSET(extradata_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, {"time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, INT_MIN, INT_MAX}, {"g", "set the group of picture (GOP) size", OFFSET(gop_size), AV_OPT_TYPE_INT, {.i64 = 12 }, INT_MIN, INT_MAX, V|E}, diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c index 24251ff02c..338b2afc7f 100644 --- a/libavcodec/svq1enc.c +++ b/libavcodec/svq1enc.c @@ -272,7 +272,20 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane, s->m.b8_stride = 2 * s->m.mb_width + 1; s->m.f_code = 1; s->m.pict_type = s->pict_type; +#if FF_API_MOTION_EST +FF_DISABLE_DEPRECATION_WARNINGS s->m.me_method = s->avctx->me_method; + if (s->motion_est == FF_ME_EPZS) { + if (s->avctx->me_method == ME_ZERO) + s->motion_est = FF_ME_ZERO; + else if (s->avctx->me_method == ME_EPZS) + s->motion_est = FF_ME_EPZS; + else if (s->avctx->me_method == ME_X1) + s->motion_est = FF_ME_XONE; + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + s->m.motion_est = s->motion_est; s->m.me.scene_change_score = 0; // s->m.out_format = FMT_H263; // s->m.unrestricted_mv = 1; @@ -654,12 +667,31 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; } +#define OFFSET(x) offsetof(struct SVQ1EncContext, x) +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM +static const AVOption options[] = { + { "motion-est", "Motion estimation algorithm", OFFSET(motion_est), AV_OPT_TYPE_INT, { .i64 = FF_ME_EPZS }, FF_ME_ZERO, FF_ME_XONE, VE, "motion-est"}, + { "zero", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_ZERO }, 0, 0, FF_MPV_OPT_FLAGS, "motion-est" }, + { "epzs", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_EPZS }, 0, 0, FF_MPV_OPT_FLAGS, "motion-est" }, + { "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, FF_MPV_OPT_FLAGS, "motion-est" }, + + { NULL }, +}; + +static const AVClass svq1enc_class = { + .class_name = "svq1enc", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVCodec ff_svq1_encoder = { .name = "svq1", .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_SVQ1, .priv_data_size = sizeof(SVQ1EncContext), + .priv_class = &svq1enc_class, .init = svq1_encode_init, .encode2 = svq1_encode_frame, .close = svq1_encode_end, diff --git a/libavcodec/svq1enc.h b/libavcodec/svq1enc.h index 5ecb2a5639..62e8bb2699 100644 --- a/libavcodec/svq1enc.h +++ b/libavcodec/svq1enc.h @@ -72,6 +72,8 @@ typedef struct SVQ1EncContext { uint8_t *scratchbuf; + int motion_est; + int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2, int size); } SVQ1EncContext; diff --git a/libavcodec/version.h b/libavcodec/version.h index eaa108436a..28a28097fc 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #define LIBAVCODEC_VERSION_MAJOR 56 #define LIBAVCODEC_VERSION_MINOR 34 -#define LIBAVCODEC_VERSION_MICRO 0 +#define LIBAVCODEC_VERSION_MICRO 1 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ @@ -174,5 +174,8 @@ #ifndef FF_API_CODED_FRAME #define FF_API_CODED_FRAME (LIBAVCODEC_VERSION_MAJOR < 59) #endif +#ifndef FF_API_MOTION_EST +#define FF_API_MOTION_EST (LIBAVCODEC_VERSION_MAJOR < 59) +#endif #endif /* AVCODEC_VERSION_H */ diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c index e4d4159e37..06ad2b65cf 100644 --- a/libavcodec/wmv2enc.c +++ b/libavcodec/wmv2enc.c @@ -216,12 +216,20 @@ void ff_wmv2_encode_mb(MpegEncContext *s, int16_t block[6][64], ff_msmpeg4_encode_block(s, block[i], i); } +static const AVClass wmv2_class = { + .class_name = "wmv2 encoder", + .item_name = av_default_item_name, + .option = ff_mpv_generic_options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVCodec ff_wmv2_encoder = { .name = "wmv2", .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 8"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_WMV2, .priv_data_size = sizeof(Wmv2Context), + .priv_class = &wmv2_class, .init = wmv2_encode_init, .encode2 = ff_mpv_encode_picture, .close = ff_mpv_encode_end,