diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2005-12-19 13:41:27 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2005-12-19 13:41:27 +0000 |
commit | 8ed9f9ab324f5370d891a67f4ae6162db80f84a1 (patch) | |
tree | 5b1d781e63f8c91d450712a3c79ebe43c229b178 /libavcodec | |
parent | 2ceff404b5416035ae05caad39bbdfe56a31064a (diff) | |
download | ffmpeg-8ed9f9ab324f5370d891a67f4ae6162db80f84a1.tar.gz |
use correct qp & lambda for ME on the second pass
Originally committed as revision 4757 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/mpegvideo.c | 52 | ||||
-rw-r--r-- | libavcodec/mpegvideo.h | 2 | ||||
-rw-r--r-- | libavcodec/ratecontrol.c | 12 |
3 files changed, 38 insertions, 28 deletions
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 393a98f55d..6a72866d9d 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -5245,6 +5245,31 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src) flush_put_bits(&dst->pb); } +static void estimate_qp(MpegEncContext *s, int dry_run){ + if (!s->fixed_qscale) + s->current_picture_ptr->quality= + s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run); + + if(s->adaptive_quant){ + switch(s->codec_id){ + case CODEC_ID_MPEG4: + ff_clean_mpeg4_qscales(s); + break; + case CODEC_ID_H263: + case CODEC_ID_H263P: + case CODEC_ID_FLV1: + ff_clean_h263_qscales(s); + break; + } + + s->lambda= s->lambda_table[0]; + //FIXME broken + }else + s->lambda= s->current_picture.quality; +//printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); + update_qscale(s); +} + static void encode_picture(MpegEncContext *s, int picture_number) { int i; @@ -5273,6 +5298,10 @@ static void encode_picture(MpegEncContext *s, int picture_number) s->no_rounding ^= 1; } + if(s->flags & CODEC_FLAG_PASS2) + estimate_qp(s, 1); + + s->mb_intra=0; //for the rate distortion & bit compare functions for(i=1; i<s->avctx->thread_count; i++){ ff_update_duplicate_context(s->thread_context[i], s); @@ -5369,28 +5398,7 @@ static void encode_picture(MpegEncContext *s, int picture_number) } } - if (!s->fixed_qscale) - s->current_picture_ptr->quality= - s->current_picture.quality = ff_rate_estimate_qscale(s); - - if(s->adaptive_quant){ - switch(s->codec_id){ - case CODEC_ID_MPEG4: - ff_clean_mpeg4_qscales(s); - break; - case CODEC_ID_H263: - case CODEC_ID_H263P: - case CODEC_ID_FLV1: - ff_clean_h263_qscales(s); - break; - } - - s->lambda= s->lambda_table[0]; - //FIXME broken - }else - s->lambda= s->current_picture.quality; -//printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); - update_qscale(s); + estimate_qp(s, 0); if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE)) s->qscale= 3; //reduce clipping problems diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index da9f0ba3fb..7dc83d0a3c 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -972,7 +972,7 @@ void ff_mjpeg_stuffing(PutBitContext * pbc); /* rate control */ int ff_rate_control_init(MpegEncContext *s); -float ff_rate_estimate_qscale(MpegEncContext *s); +float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run); void ff_write_pass1_stats(MpegEncContext *s); void ff_rate_control_uninit(MpegEncContext *s); double ff_eval(char *s, double *const_value, const char **const_name, diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 7f87696669..8dd9d2b6d8 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -609,7 +609,7 @@ static void adaptive_quantization(MpegEncContext *s, double q){ } //FIXME rd or at least approx for dquant -float ff_rate_estimate_qscale(MpegEncContext *s) +float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) { float q; int qmin, qmax; @@ -634,7 +634,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s) fps= 1/av_q2d(s->avctx->time_base); //printf("input_pic_num:%d pic_num:%d frame_rate:%d\n", s->input_picture_number, s->picture_number, s->frame_rate); /* update predictors */ - if(picture_number>2){ + if(picture_number>2 && !dry_run){ const int last_var= s->last_pict_type == I_TYPE ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum; update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits); } @@ -735,9 +735,11 @@ float ff_rate_estimate_qscale(MpegEncContext *s) else q= (int)(q + 0.5); - rcc->last_qscale= q; - rcc->last_mc_mb_var_sum= pic->mc_mb_var_sum; - rcc->last_mb_var_sum= pic->mb_var_sum; + if(!dry_run){ + rcc->last_qscale= q; + rcc->last_mc_mb_var_sum= pic->mc_mb_var_sum; + rcc->last_mb_var_sum= pic->mb_var_sum; + } #if 0 { static int mvsum=0, texsum=0; |