]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit 'd639dcdae022130078c9c84b7b691c5e9694786c'
authorClément Bœsch <u@pkh.me>
Wed, 1 Feb 2017 13:21:36 +0000 (14:21 +0100)
committerClément Bœsch <u@pkh.me>
Wed, 1 Feb 2017 13:21:36 +0000 (14:21 +0100)
* commit 'd639dcdae022130078c9c84b7b691c5e9694786c':
  ratecontrol: Move Xvid-related functions to the place they are actually used

Merged-by: Clément Bœsch <u@pkh.me>
1  2 
libavcodec/libxvid.h
libavcodec/mpegvideo_enc.c
libavcodec/ratecontrol.c
libavcodec/ratecontrol.h

index ef9a5a9c59cfc95e97cb23c58c91352b224d2068,4535898530ecb9a836cfa0f38a5b6af3afc1f9e2..58bef616608cc33eed1e821add5d8569044c09d2
   * 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 */
index 10b4c5b8c486dea0114f441fcc7d5d67bb0f79fb,d738d06ee63cdf7e93f48907871c5f4ab4fac227..cdda73b65412e226a60acb3689c9af30bc25d4af
@@@ -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 ((avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == 1)
+ #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 -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) {
 -        if ((s->avctx->flags & AV_CODEC_FLAG_PASS2) && s->rc_strategy == 1)
+         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;
      }
index 507dcbb33a6de7c72455a7a04dcfa5e3294dc4d9,7e604b1efbebd6deeea32f11f672eeb153b42f4e..b731f72a14ba1a403ea17a57159197ad82e390c5
@@@ -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) {
Simple merge