X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fsnowenc.c;h=beb25c13c3d58490f119d59bd9db57474a6f397b;hb=0b7829901bc93af8407bfb832049d3d97c881c62;hp=9c804acbd4e4566cedb16272b751919c890d79f3;hpb=c6965f62a2e34667814ab1854a9f127e2ea54efa;p=ffmpeg diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 9c804acbd4e..beb25c13c3d 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -32,6 +32,8 @@ #include "mpegvideo.h" #include "h263.h" +#define FF_ME_ITER 50 + static av_cold int encode_init(AVCodecContext *avctx) { SnowContext *s = avctx->priv_data; @@ -39,16 +41,22 @@ static av_cold int encode_init(AVCodecContext *avctx) int i; if(avctx->prediction_method == DWT_97 - && (avctx->flags & CODEC_FLAG_QSCALE) + && (avctx->flags & AV_CODEC_FLAG_QSCALE) && avctx->global_quality == 0){ av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); return -1; } +#if FF_API_MOTION_EST +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->me_method == ME_ITER) + s->motion_est = FF_ME_ITER; +FF_ENABLE_DEPRECATION_WARNINGS +#endif s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type - s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; - s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; + s->mv_scale = (avctx->flags & AV_CODEC_FLAG_QPEL) ? 2 : 4; + s->block_max_depth= (avctx->flags & AV_CODEC_FLAG_4MV ) ? 1 : 0; for(plane_index=0; plane_index<3; plane_index++){ s->plane[plane_index].diag_mc= 1; @@ -83,18 +91,18 @@ static av_cold int encode_init(AVCodecContext *avctx) s->max_ref_frames = av_clip(avctx->refs, 1, MAX_REF_FRAMES); - if(avctx->flags&CODEC_FLAG_PASS1){ + if(avctx->flags&AV_CODEC_FLAG_PASS1){ if(!avctx->stats_out) avctx->stats_out = av_mallocz(256); if (!avctx->stats_out) return AVERROR(ENOMEM); } - if((avctx->flags&CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){ + if((avctx->flags&AV_CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){ if(ff_rate_control_init(&s->m) < 0) return -1; } - s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); + s->pass1_rc= !(avctx->flags & (AV_CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); switch(avctx->pix_fmt){ case AV_PIX_FMT_YUV444P: @@ -128,7 +136,7 @@ static av_cold int encode_init(AVCodecContext *avctx) if ((ret = ff_snow_get_buffer(s, s->input_picture)) < 0) return ret; - if(s->avctx->me_method == ME_ITER){ + if(s->motion_est == FF_ME_ITER){ int size= s->b_width * s->b_height << 2*s->block_max_depth; for(i=0; imax_ref_frames; i++){ s->ref_mvs[i]= av_mallocz_array(size, sizeof(int16_t[2])); @@ -241,7 +249,7 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ s->input_picture->data[2] + ((x*block_w)>>s->chroma_h_shift) + ((y*uvstride*block_w)>>s->chroma_v_shift)}; int P[10][2]; int16_t last_mv[3][2]; - int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL); //unused + int qpel= !!(s->avctx->flags & AV_CODEC_FLAG_QPEL); //unused const int shift= 1+qpel; MotionEstContext *c= &s->m.me; int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); @@ -1206,7 +1214,7 @@ static void encode_blocks(SnowContext *s, int search){ int w= s->b_width; int h= s->b_height; - if(s->avctx->me_method == ME_ITER && !s->keyframe && search) + if(s->motion_est == FF_ME_ITER && !s->keyframe && search) iterative_me(s); for(y=0; yavctx->me_method == ME_ITER || !search) + if(s->motion_est == FF_ME_ITER || !search) encode_q_branch2(s, 0, x, y); else encode_q_branch (s, 0, x, y); @@ -1555,7 +1563,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t rc_header_bak[sizeof(s->header_state)]; uint8_t rc_block_bak[sizeof(s->block_state)]; - if ((ret = ff_alloc_packet2(avctx, pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + FF_MIN_BUFFER_SIZE)) < 0) + if ((ret = ff_alloc_packet2(avctx, pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0) return ret; ff_init_range_encoder(c, pkt->data, pkt->size); @@ -1578,10 +1586,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->new_picture = pict; s->m.picture_number= avctx->frame_number; - if(avctx->flags&CODEC_FLAG_PASS2){ + if(avctx->flags&AV_CODEC_FLAG_PASS2){ s->m.pict_type = pic->pict_type = s->m.rc_context.entry[avctx->frame_number].new_pict_type; s->keyframe = pic->pict_type == AV_PICTURE_TYPE_I; - if(!(avctx->flags&CODEC_FLAG_QSCALE)) { + if(!(avctx->flags&AV_CODEC_FLAG_QSCALE)) { pic->quality = ff_rate_estimate_qscale(&s->m, 0); if (pic->quality < 0) return -1; @@ -1597,7 +1605,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->qlog = qscale2qlog(pic->quality); s->lambda = pic->quality * 3/2; } - if (s->qlog < 0 || (!pic->quality && (avctx->flags & CODEC_FLAG_QSCALE))) { + if (s->qlog < 0 || (!pic->quality && (avctx->flags & AV_CODEC_FLAG_QSCALE))) { s->qlog= LOSSLESS_QLOG; s->lambda = 0; }//else keep previous frame's qlog until after motion estimation @@ -1650,10 +1658,13 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->m.b8_stride= 2*s->m.mb_width+1; s->m.f_code=1; s->m.pict_type = pic->pict_type; +#if FF_API_MOTION_EST s->m.me_method= s->avctx->me_method; +#endif + s->m.motion_est= s->motion_est; s->m.me.scene_change_score=0; s->m.me.dia_size = avctx->dia_size; - s->m.quarter_sample= (s->avctx->flags & CODEC_FLAG_QPEL)!=0; + s->m.quarter_sample= (s->avctx->flags & AV_CODEC_FLAG_QPEL)!=0; s->m.out_format= FMT_H263; s->m.unrestricted_mv= 1; @@ -1722,7 +1733,7 @@ redo_frame: if( plane_index==0 && pic->pict_type == AV_PICTURE_TYPE_P - && !(avctx->flags&CODEC_FLAG_PASS2) + && !(avctx->flags&AV_CODEC_FLAG_PASS2) && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ ff_init_range_encoder(c, pkt->data, pkt->size); ff_build_rac_states(c, (1LL<<32)/20, 256-8); @@ -1808,7 +1819,7 @@ redo_frame: predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); } } - if(s->avctx->flags&CODEC_FLAG_PSNR){ + if(s->avctx->flags&AV_CODEC_FLAG_PSNR){ int64_t error= 0; if(pict->data[plane_index]) //FIXME gray hack @@ -1840,7 +1851,7 @@ redo_frame: if(s->pass1_rc) if (ff_rate_estimate_qscale(&s->m, 0) < 0) return -1; - if(avctx->flags&CODEC_FLAG_PASS1) + if(avctx->flags&AV_CODEC_FLAG_PASS1) ff_write_pass1_stats(&s->m); s->m.last_pict_type = s->m.pict_type; avctx->frame_bits = s->m.frame_bits; @@ -1850,6 +1861,11 @@ redo_frame: emms_c(); + ff_side_data_set_encoder_stats(pkt, s->current_picture->quality, + s->current_picture->error, + (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? 4 : 0, + s->current_picture->pict_type); + pkt->size = ff_rac_terminate(c); if (s->current_picture->key_frame) pkt->flags |= AV_PKT_FLAG_KEY; @@ -1874,6 +1890,7 @@ static av_cold int encode_end(AVCodecContext *avctx) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { FF_MPV_COMMON_OPTS + { "iter", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_ITER }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, { "memc_only", "Only do ME/MC (I frames -> ref, P frame -> ME+MC).", OFFSET(memc_only), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, { "no_bitstream", "Skip final bitstream writeout.", OFFSET(no_bitstream), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, { "intra_penalty", "Penalty for intra blocks in block decission", OFFSET(intra_penalty), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },