X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmpegvideo_enc.c;h=b2eb9cf3185269ba5e58585160c8e16c30d8f043;hb=f66ac83c22d8c088832ce8df922b08a0caa11833;hp=9fdab31a25fdc3cbf76f946aab07c413b7698158;hpb=f3881c04e93ee70567bd3fe087f49b996b026d30;p=ffmpeg diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 9fdab31a25f..b2eb9cf3185 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -38,7 +38,6 @@ #include "libavutil/mathematics.h" #include "libavutil/pixdesc.h" #include "libavutil/opt.h" -#include "libavutil/timer.h" #include "avcodec.h" #include "dct.h" #include "idctdsp.h" @@ -165,7 +164,7 @@ void ff_convert_matrix(MpegEncContext *s, int (*qmat)[64], } } if (shift) { - av_log(NULL, AV_LOG_INFO, + av_log(s->avctx, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", QMAT_SHIFT - shift); } @@ -2005,7 +2004,7 @@ FF_ENABLE_DEPRECATION_WARNINGS av_log(s->avctx, AV_LOG_ERROR, "Internal error, negative bits\n"); - assert(s->repeat_first_field == 0); + av_assert1(s->repeat_first_field == 0); vbv_delay = bits * 90000 / s->avctx->rc_max_rate; min_delay = (minbits * 90000LL + s->avctx->rc_max_rate - 1) / @@ -3056,7 +3055,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ if(r % d == 0){ current_packet_size=0; s->pb.buf_ptr= s->ptr_lastgob; - assert(put_bits_ptr(&s->pb) == s->ptr_lastgob); + av_assert1(put_bits_ptr(&s->pb) == s->ptr_lastgob); } } @@ -3592,8 +3591,8 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src) } } - assert(put_bits_count(&src->pb) % 8 ==0); - assert(put_bits_count(&dst->pb) % 8 ==0); + av_assert1(put_bits_count(&src->pb) % 8 ==0); + av_assert1(put_bits_count(&dst->pb) % 8 ==0); avpriv_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); flush_put_bits(&dst->pb); } @@ -3642,11 +3641,11 @@ static void set_frame_distances(MpegEncContext * s){ if(s->pict_type==AV_PICTURE_TYPE_B){ s->pb_time= s->pp_time - (s->last_non_b_time - s->time); - assert(s->pb_time > 0 && s->pb_time < s->pp_time); + av_assert1(s->pb_time > 0 && s->pb_time < s->pp_time); }else{ s->pp_time= s->time - s->last_non_b_time; s->last_non_b_time= s->time; - assert(s->picture_number==0 || s->pp_time > 0); + av_assert1(s->picture_number==0 || s->pp_time > 0); } } @@ -3761,14 +3760,14 @@ static int encode_picture(MpegEncContext *s, int picture_number) s->f_code= FFMAX3(s->f_code, a, b); } - ff_fix_long_p_mvs(s); - ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0); + ff_fix_long_p_mvs(s, s->intra_penalty ? CANDIDATE_MB_TYPE_INTER : CANDIDATE_MB_TYPE_INTRA); + ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, !!s->intra_penalty); if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) { int j; for(i=0; i<2; i++){ for(j=0; j<2; j++) ff_fix_long_mvs(s, s->p_field_select_table[i], j, - s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0); + s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, !!s->intra_penalty); } } } @@ -4262,7 +4261,6 @@ static int dct_quantize_trellis_c(MpegEncContext *s, return last_non_zero; } -//#define REFINE_STATS 1 static int16_t basis[64][64]; static void build_basis(uint8_t *perm){ @@ -4301,15 +4299,6 @@ static int dct_quantize_refine(MpegEncContext *s, //FIXME breaks denoise? uint8_t * last_length; int lambda; int rle_index, run, q = 1, sum; //q is only used when s->mb_intra is true -#ifdef REFINE_STATS -static int count=0; -static int after_last=0; -static int to_zero=0; -static int from_zero=0; -static int raise=0; -static int lower=0; -static int messed_sign=0; -#endif if(basis[0][0] == 0) build_basis(s->idsp.idct_permutation); @@ -4353,16 +4342,11 @@ static int messed_sign=0; } last_non_zero = s->block_last_index[n]; -#ifdef REFINE_STATS -{START_TIMER -#endif dc += (1<<(RECON_SHIFT-1)); for(i=0; i<64; i++){ rem[i] = dc - (orig[i] << RECON_SHIFT); // FIXME use orig directly instead of copying to rem[] } -#ifdef REFINE_STATS -STOP_TIMER("memset rem[]")} -#endif + sum=0; for(i=0; i<64; i++){ int one= 36; @@ -4380,9 +4364,7 @@ STOP_TIMER("memset rem[]")} sum += w*w; } lambda= sum*(uint64_t)s->lambda2 >> (FF_LAMBDA_SHIFT - 6 + 6 + 6 + 6); -#ifdef REFINE_STATS -{START_TIMER -#endif + run=0; rle_index=0; for(i=start_i; i<=last_non_zero; i++){ @@ -4401,41 +4383,21 @@ STOP_TIMER("memset rem[]")} run++; } } -#ifdef REFINE_STATS -if(last_non_zero>0){ -STOP_TIMER("init rem[]") -} -} -{START_TIMER -#endif for(;;){ int best_score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0], 0); int best_coeff=0; int best_change=0; int run2, best_unquant_change=0, analyze_gradient; -#ifdef REFINE_STATS -{START_TIMER -#endif analyze_gradient = last_non_zero > 2 || s->quantizer_noise_shaping >= 3; if(analyze_gradient){ -#ifdef REFINE_STATS -{START_TIMER -#endif for(i=0; i<64; i++){ int w= weight[i]; d1[i] = (rem[i]*w*w + (1<<(RECON_SHIFT+12-1)))>>(RECON_SHIFT+12); } -#ifdef REFINE_STATS -STOP_TIMER("rem*w*w")} -{START_TIMER -#endif s->fdsp.fdct(d1); -#ifdef REFINE_STATS -STOP_TIMER("dct")} -#endif } if(start_i){ @@ -4597,9 +4559,6 @@ STOP_TIMER("dct")} run++; } } -#ifdef REFINE_STATS -STOP_TIMER("iterative step")} -#endif if(best_change){ int j= perm_scantable[ best_coeff ]; @@ -4609,36 +4568,13 @@ STOP_TIMER("iterative step")} if(best_coeff > last_non_zero){ last_non_zero= best_coeff; av_assert2(block[j]); -#ifdef REFINE_STATS -after_last++; -#endif }else{ -#ifdef REFINE_STATS -if(block[j]){ - if(block[j] - best_change){ - if(FFABS(block[j]) > FFABS(block[j] - best_change)){ - raise++; - }else{ - lower++; - } - }else{ - from_zero++; - } -}else{ - to_zero++; -} -#endif for(; last_non_zero>=start_i; last_non_zero--){ if(block[perm_scantable[last_non_zero]]) break; } } -#ifdef REFINE_STATS -count++; -if(256*256*256*64 % count == 0){ - av_log(s->avctx, AV_LOG_DEBUG, "after_last:%d to_zero:%d from_zero:%d raise:%d lower:%d sign:%d xyp:%d/%d/%d\n", after_last, to_zero, from_zero, raise, lower, messed_sign, s->mb_x, s->mb_y, s->picture_number); -} -#endif + run=0; rle_index=0; for(i=start_i; i<=last_non_zero; i++){ @@ -4658,12 +4594,6 @@ if(256*256*256*64 % count == 0){ break; } } -#ifdef REFINE_STATS -if(last_non_zero>0){ -STOP_TIMER("iterative search") -} -} -#endif return last_non_zero; }