ffmpeg | branch: master | Clément Bœsch <[email protected]> | Wed Feb 1 14:21:36 2017 +0100| [566bfd59c963938e183d523be9216b3f95ad8a09] | committer: Clément Bœsch
Merge commit 'd639dcdae022130078c9c84b7b691c5e9694786c' * commit 'd639dcdae022130078c9c84b7b691c5e9694786c': ratecontrol: Move Xvid-related functions to the place they are actually used Merged-by: Clément Bœsch <[email protected]> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=566bfd59c963938e183d523be9216b3f95ad8a09 --- libavcodec/libxvid.h | 7 +++++++ libavcodec/mpegvideo_enc.c | 37 ++++++++++++++++++++++++++++++++++++- libavcodec/ratecontrol.c | 32 -------------------------------- libavcodec/ratecontrol.h | 4 ---- 4 files changed, 43 insertions(+), 37 deletions(-) diff --git a/libavcodec/libxvid.h b/libavcodec/libxvid.h index ef9a5a9..58bef61 100644 --- a/libavcodec/libxvid.h +++ b/libavcodec/libxvid.h @@ -26,4 +26,11 @@ * common functions for use with the Xvid wrappers */ +struct MpegEncContext; + +/* rate control */ +int ff_xvid_rate_control_init(struct MpegEncContext *s); +void ff_xvid_rate_control_uninit(struct MpegEncContext *s); +float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run); + #endif /* AVCODEC_LIBXVID_H */ diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 10b4c5b..cdda73b 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -64,6 +64,7 @@ #include "bytestream.h" #include "wmv2.h" #include "rv10.h" +#include "libxvid.h" #include <limits.h> #include "sp5x.h" @@ -1027,9 +1028,32 @@ FF_ENABLE_DEPRECATION_WARNINGS 31, 0); } +#if FF_API_RC_STRATEGY +FF_DISABLE_DEPRECATION_WARNINGS + if (!s->rc_strategy) + s->rc_strategy = s->avctx->rc_strategy; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (ff_rate_control_init(s) < 0) return -1; +#if FF_API_RC_STRATEGY + av_assert0(MPV_RC_STRATEGY_XVID == FF_RC_STRATEGY_XVID); +#endif + + if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) { +#if CONFIG_LIBXVID + ret = ff_xvid_rate_control_init(s); +#else + ret = AVERROR(ENOSYS); + av_log(s->avctx, AV_LOG_ERROR, + "Xvid ratecontrol requires libavcodec compiled with Xvid support.\n"); +#endif + if (ret < 0) + return ret; + } + #if FF_API_ERROR_RATE FF_DISABLE_DEPRECATION_WARNINGS if (avctx->error_rate) @@ -1123,6 +1147,10 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) int i; ff_rate_control_uninit(s); +#if CONFIG_LIBXVID + if ((avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) + ff_xvid_rate_control_uninit(s); +#endif ff_mpv_common_end(s); if (CONFIG_MJPEG_ENCODER && @@ -3629,8 +3657,15 @@ static int estimate_qp(MpegEncContext *s, int dry_run){ s->current_picture.f->quality = s->next_lambda; if(!dry_run) s->next_lambda= 0; } else if (!s->fixed_qscale) { + int quality; +#if CONFIG_LIBXVID + if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) + quality = ff_xvid_rate_estimate_qscale(s, dry_run); + else +#endif + quality = ff_rate_estimate_qscale(s, dry_run); s->current_picture_ptr->f->quality = - s->current_picture.f->quality = ff_rate_estimate_qscale(s, dry_run); + s->current_picture.f->quality = quality; if (s->current_picture.f->quality < 0) return -1; } diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 507dcbb..b731f72 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -136,13 +136,6 @@ av_cold int ff_rate_control_init(MpegEncContext *s) return res; } -#if FF_API_RC_STRATEGY -FF_DISABLE_DEPRECATION_WARNINGS - if (!s->rc_strategy) - s->rc_strategy = s->avctx->rc_strategy; -FF_ENABLE_DEPRECATION_WARNINGS -#endif - for (i = 0; i < 5; i++) { rcc->pred[i].coeff = FF_QP2LAMBDA * 7.0; rcc->pred[i].count = 1.0; @@ -226,21 +219,6 @@ FF_ENABLE_DEPRECATION_WARNINGS ff_rate_control_uninit(s); return -1; } - -#if FF_API_RC_STRATEGY - av_assert0(MPV_RC_STRATEGY_XVID == FF_RC_STRATEGY_XVID); -#endif - - // FIXME maybe move to end - if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) { -#if CONFIG_LIBXVID - return ff_xvid_rate_control_init(s); -#else - av_log(s->avctx, AV_LOG_ERROR, - "Xvid ratecontrol requires libavcodec compiled with Xvid support.\n"); - return -1; -#endif - } } if (!(s->avctx->flags & AV_CODEC_FLAG_PASS2)) { @@ -310,11 +288,6 @@ av_cold void ff_rate_control_uninit(MpegEncContext *s) av_expr_free(rcc->rc_eq_eval); av_freep(&rcc->entry); - -#if CONFIG_LIBXVID - if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) - ff_xvid_rate_control_uninit(s); -#endif } int ff_vbv_update(MpegEncContext *s, int frame_size) @@ -758,11 +731,6 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) Picture * const pic = &s->current_picture; emms_c(); -#if CONFIG_LIBXVID - if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) - return ff_xvid_rate_estimate_qscale(s, dry_run); -#endif - get_qminmax(&qmin, &qmax, s, pict_type); fps = get_fps(s->avctx); diff --git a/libavcodec/ratecontrol.h b/libavcodec/ratecontrol.h index c15f9e2..2a7aaec 100644 --- a/libavcodec/ratecontrol.h +++ b/libavcodec/ratecontrol.h @@ -96,8 +96,4 @@ void ff_rate_control_uninit(struct MpegEncContext *s); int ff_vbv_update(struct MpegEncContext *s, int frame_size); void ff_get_2pass_fcode(struct MpegEncContext *s); -int ff_xvid_rate_control_init(struct MpegEncContext *s); -void ff_xvid_rate_control_uninit(struct MpegEncContext *s); -float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run); - #endif /* AVCODEC_RATECONTROL_H */ ====================================================================== diff --cc libavcodec/libxvid.h index ef9a5a9,4535898..58bef61 --- a/libavcodec/libxvid.h +++ b/libavcodec/libxvid.h @@@ -26,4 -26,13 +26,11 @@@ * common functions for use with the Xvid wrappers */ -int ff_tempfile(const char *prefix, char **filename); - + struct MpegEncContext; + + /* rate control */ + int ff_xvid_rate_control_init(struct MpegEncContext *s); + void ff_xvid_rate_control_uninit(struct MpegEncContext *s); + float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run); + #endif /* AVCODEC_LIBXVID_H */ diff --cc libavcodec/mpegvideo_enc.c index 10b4c5b,d738d06..cdda73b --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@@ -64,8 -60,8 +64,9 @@@ #include "bytestream.h" #include "wmv2.h" #include "rv10.h" + #include "libxvid.h" #include <limits.h> +#include "sp5x.h" #define QUANT_BIAS_SHIFT 8 @@@ -1030,6 -882,18 +1038,22 @@@ FF_ENABLE_DEPRECATION_WARNING if (ff_rate_control_init(s) < 0) return -1; - if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == 1) { ++#if FF_API_RC_STRATEGY ++ av_assert0(MPV_RC_STRATEGY_XVID == FF_RC_STRATEGY_XVID); ++#endif ++ ++ if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) { + #if CONFIG_LIBXVID + ret = ff_xvid_rate_control_init(s); + #else + ret = AVERROR(ENOSYS); + av_log(s->avctx, AV_LOG_ERROR, + "Xvid ratecontrol requires libavcodec compiled with Xvid support.\n"); + #endif + if (ret < 0) + return ret; + } + #if FF_API_ERROR_RATE FF_DISABLE_DEPRECATION_WARNINGS if (avctx->error_rate) @@@ -1123,6 -987,10 +1147,10 @@@ av_cold int ff_mpv_encode_end(AVCodecCo int i; ff_rate_control_uninit(s); + #if CONFIG_LIBXVID - if ((avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == 1) ++ if ((avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) + ff_xvid_rate_control_uninit(s); + #endif ff_mpv_common_end(s); if (CONFIG_MJPEG_ENCODER && @@@ -3629,8 -3409,15 +3657,15 @@@ static int estimate_qp(MpegEncContext * s->current_picture.f->quality = s->next_lambda; if(!dry_run) s->next_lambda= 0; } else if (!s->fixed_qscale) { + int quality; + #if CONFIG_LIBXVID - if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == 1) ++ if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) + quality = ff_xvid_rate_estimate_qscale(s, dry_run); + else + #endif + quality = ff_rate_estimate_qscale(s, dry_run); s->current_picture_ptr->f->quality = - s->current_picture.f->quality = ff_rate_estimate_qscale(s, dry_run); + s->current_picture.f->quality = quality; if (s->current_picture.f->quality < 0) return -1; } diff --cc libavcodec/ratecontrol.c index 507dcbb,7e604b1..b731f72 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@@ -758,24 -700,16 +731,19 @@@ float ff_rate_estimate_qscale(MpegEncCo Picture * const pic = &s->current_picture; emms_c(); - #if CONFIG_LIBXVID - if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == MPV_RC_STRATEGY_XVID) - return ff_xvid_rate_estimate_qscale(s, dry_run); - #endif - get_qminmax(&qmin, &qmax, s, pict_type); - fps = 1 / av_q2d(s->avctx->time_base); + fps = get_fps(s->avctx); /* update predictors */ if (picture_number > 2 && !dry_run) { - const int last_var = s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum - : rcc->last_mc_mb_var_sum; + const int64_t last_var = + s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum + : rcc->last_mc_mb_var_sum; + av_assert1(s->frame_bits >= s->stuffing_bits); update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, - sqrt(last_var), s->frame_bits); + sqrt(last_var), + s->frame_bits - s->stuffing_bits); } if (s->avctx->flags & AV_CODEC_FLAG_PASS2) { _______________________________________________ ffmpeg-cvslog mailing list [email protected] http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
