diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-01-04 05:56:29 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-01-04 05:56:29 +0400 |
commit | fb17f03dadc3e344e3d996d7ea0f09e340fdd05b (patch) | |
tree | 92843c3413846672b90e2b94c768ec926ec4202f /libavcodec/mpegvideo_enc.c | |
parent | ad5e4e0f947ab686325fc7783afd18cd9cd88dc4 (diff) | |
parent | aec25b1c4650944d32706bfd40eb02bbd5587303 (diff) |
Merge commit 'aec25b1c4650944d32706bfd40eb02bbd5587303'
* commit 'aec25b1c4650944d32706bfd40eb02bbd5587303':
mpegvideo: split the encoding-only parts of frame_start() into a separate function
Conflicts:
libavcodec/mpegvideo.c
libavcodec/mpegvideo_enc.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r-- | libavcodec/mpegvideo_enc.c | 100 |
1 files changed, 97 insertions, 3 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 5828a27c50..c84837b71a 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1505,6 +1505,99 @@ static void frame_end(MpegEncContext *s) } +static void update_noise_reduction(MpegEncContext *s) +{ + int intra, i; + + for (intra = 0; intra < 2; intra++) { + if (s->dct_count[intra] > (1 << 16)) { + for (i = 0; i < 64; i++) { + s->dct_error_sum[intra][i] >>= 1; + } + s->dct_count[intra] >>= 1; + } + + for (i = 0; i < 64; i++) { + s->dct_offset[intra][i] = (s->avctx->noise_reduction * + s->dct_count[intra] + + s->dct_error_sum[intra][i] / 2) / + (s->dct_error_sum[intra][i] + 1); + } + } +} + +static int frame_start(MpegEncContext *s) +{ + int ret; + + /* mark & release old frames */ + if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && + s->last_picture_ptr != s->next_picture_ptr && + s->last_picture_ptr->f.buf[0]) { + ff_mpeg_unref_picture(s, s->last_picture_ptr); + } + + s->current_picture_ptr->f.pict_type = s->pict_type; + s->current_picture_ptr->f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; + + ff_mpeg_unref_picture(s, &s->current_picture); + if ((ret = ff_mpeg_ref_picture(s, &s->current_picture, + s->current_picture_ptr)) < 0) + return ret; + + if (s->pict_type != AV_PICTURE_TYPE_B) { + s->last_picture_ptr = s->next_picture_ptr; + if (!s->droppable) + s->next_picture_ptr = s->current_picture_ptr; + } + + if (s->last_picture_ptr) { + ff_mpeg_unref_picture(s, &s->last_picture); + if (s->last_picture_ptr->f.buf[0] && + (ret = ff_mpeg_ref_picture(s, &s->last_picture, + s->last_picture_ptr)) < 0) + return ret; + } + if (s->next_picture_ptr) { + ff_mpeg_unref_picture(s, &s->next_picture); + if (s->next_picture_ptr->f.buf[0] && + (ret = ff_mpeg_ref_picture(s, &s->next_picture, + s->next_picture_ptr)) < 0) + return ret; + } + + if (s->picture_structure!= PICT_FRAME) { + int i; + for (i = 0; i < 4; i++) { + if (s->picture_structure == PICT_BOTTOM_FIELD) { + s->current_picture.f.data[i] += + s->current_picture.f.linesize[i]; + } + s->current_picture.f.linesize[i] *= 2; + s->last_picture.f.linesize[i] *= 2; + s->next_picture.f.linesize[i] *= 2; + } + } + + if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { + s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; + s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; + } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { + s->dct_unquantize_intra = s->dct_unquantize_h263_intra; + s->dct_unquantize_inter = s->dct_unquantize_h263_inter; + } else { + s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; + s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; + } + + if (s->dct_error_sum) { + av_assert2(s->avctx->noise_reduction && s->encoding); + update_noise_reduction(s); + } + + return 0; +} + int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, AVFrame *pic_arg, int *got_packet) { @@ -1544,8 +1637,9 @@ int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, s->pict_type = s->new_picture.f.pict_type; //emms_c(); - if (ff_MPV_frame_start(s, avctx) < 0) - return -1; + ret = frame_start(s); + if (ret < 0) + return ret; vbv_retry: if (encode_picture(s, s->picture_number) < 0) return -1; @@ -1581,7 +1675,7 @@ vbv_retry: s->lambda_table[i] * (s->qscale + 1) / s->qscale); } - s->mb_skipped = 0; // done in MPV_frame_start() + s->mb_skipped = 0; // done in frame_start() // done in encode_picture() so we must undo it if (s->pict_type == AV_PICTURE_TYPE_P) { if (s->flipflop_rounding || |