* 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 */
#include "bytestream.h"
#include "wmv2.h"
#include "rv10.h"
+ #include "libxvid.h"
#include <limits.h>
+#include "sp5x.h"
#define QUANT_BIAS_SHIFT 8
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)
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 &&
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;
}
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) {