Mercurial > libavcodec.hg
comparison mpegvideo.c @ 2974:e7189a8c22ed libavcodec
use correct qp & lambda for ME on the second pass
author | michael |
---|---|
date | Mon, 19 Dec 2005 13:41:27 +0000 |
parents | bb0222145083 |
children | bfabfdf9ce55 |
comparison
equal
deleted
inserted
replaced
2973:bb0222145083 | 2974:e7189a8c22ed |
---|---|
5243 assert(put_bits_count(&dst->pb) % 8 ==0); | 5243 assert(put_bits_count(&dst->pb) % 8 ==0); |
5244 ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); | 5244 ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); |
5245 flush_put_bits(&dst->pb); | 5245 flush_put_bits(&dst->pb); |
5246 } | 5246 } |
5247 | 5247 |
5248 static void estimate_qp(MpegEncContext *s, int dry_run){ | |
5249 if (!s->fixed_qscale) | |
5250 s->current_picture_ptr->quality= | |
5251 s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run); | |
5252 | |
5253 if(s->adaptive_quant){ | |
5254 switch(s->codec_id){ | |
5255 case CODEC_ID_MPEG4: | |
5256 ff_clean_mpeg4_qscales(s); | |
5257 break; | |
5258 case CODEC_ID_H263: | |
5259 case CODEC_ID_H263P: | |
5260 case CODEC_ID_FLV1: | |
5261 ff_clean_h263_qscales(s); | |
5262 break; | |
5263 } | |
5264 | |
5265 s->lambda= s->lambda_table[0]; | |
5266 //FIXME broken | |
5267 }else | |
5268 s->lambda= s->current_picture.quality; | |
5269 //printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); | |
5270 update_qscale(s); | |
5271 } | |
5272 | |
5248 static void encode_picture(MpegEncContext *s, int picture_number) | 5273 static void encode_picture(MpegEncContext *s, int picture_number) |
5249 { | 5274 { |
5250 int i; | 5275 int i; |
5251 int bits; | 5276 int bits; |
5252 | 5277 |
5270 else s->no_rounding=0; | 5295 else s->no_rounding=0; |
5271 }else if(s->pict_type!=B_TYPE){ | 5296 }else if(s->pict_type!=B_TYPE){ |
5272 if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) | 5297 if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) |
5273 s->no_rounding ^= 1; | 5298 s->no_rounding ^= 1; |
5274 } | 5299 } |
5300 | |
5301 if(s->flags & CODEC_FLAG_PASS2) | |
5302 estimate_qp(s, 1); | |
5303 | |
5275 | 5304 |
5276 s->mb_intra=0; //for the rate distortion & bit compare functions | 5305 s->mb_intra=0; //for the rate distortion & bit compare functions |
5277 for(i=1; i<s->avctx->thread_count; i++){ | 5306 for(i=1; i<s->avctx->thread_count; i++){ |
5278 ff_update_duplicate_context(s->thread_context[i], s); | 5307 ff_update_duplicate_context(s->thread_context[i], s); |
5279 } | 5308 } |
5367 } | 5396 } |
5368 } | 5397 } |
5369 } | 5398 } |
5370 } | 5399 } |
5371 | 5400 |
5372 if (!s->fixed_qscale) | 5401 estimate_qp(s, 0); |
5373 s->current_picture_ptr->quality= | |
5374 s->current_picture.quality = ff_rate_estimate_qscale(s); | |
5375 | |
5376 if(s->adaptive_quant){ | |
5377 switch(s->codec_id){ | |
5378 case CODEC_ID_MPEG4: | |
5379 ff_clean_mpeg4_qscales(s); | |
5380 break; | |
5381 case CODEC_ID_H263: | |
5382 case CODEC_ID_H263P: | |
5383 case CODEC_ID_FLV1: | |
5384 ff_clean_h263_qscales(s); | |
5385 break; | |
5386 } | |
5387 | |
5388 s->lambda= s->lambda_table[0]; | |
5389 //FIXME broken | |
5390 }else | |
5391 s->lambda= s->current_picture.quality; | |
5392 //printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); | |
5393 update_qscale(s); | |
5394 | 5402 |
5395 if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE)) | 5403 if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE)) |
5396 s->qscale= 3; //reduce clipping problems | 5404 s->qscale= 3; //reduce clipping problems |
5397 | 5405 |
5398 if (s->out_format == FMT_MJPEG) { | 5406 if (s->out_format == FMT_MJPEG) { |