From 73cbf86830b79e1827d009dcb8ef81604f243842 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 28 Oct 2010 12:15:47 +0000 Subject: [PATCH] Try to find a bit better initial states in ffv1 2pass. Difference in filesizes to foreman ffv1 version=2, context=1 coder=1 18637016 adv-pass2-g300.avi 18638806 adv-pass1-g300.avi 18640534 ref-pass2-g300.avi 18918214 adv-pass2-g1.avi 18982048 ref-pass2-g1.avi 21516230 adv-pass1-g1.avi Originally committed as revision 25594 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/ffv1.c | 52 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 6c5408d6bf..e52d6f9b9f 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -302,6 +302,48 @@ static inline int get_context(PlaneContext *p, int_fast16_t *src, int_fast16_t * return p->quant_table[0][(L-LT) & 0xFF] + p->quant_table[1][(LT-T) & 0xFF] + p->quant_table[2][(T-RT) & 0xFF]; } +static void find_best_state(uint8_t best_state[256][256], const uint8_t one_state[256]){ + int i,j,k,m; + double l2tab[256]; + + for(i=1; i<256; i++) + l2tab[i]= log2(i/256.0); + + for(i=0; i<256; i++){ + double best_len[256]; + double p= i/256.0; + + for(j=0; j<256; j++) + best_len[j]= 1<<30; + + for(j=FFMAX(i-10,1); jstats_in){ char *p= avctx->stats_in; + uint8_t best_state[256][256]; int gob_count=0; char *next; @@ -1002,15 +1045,16 @@ static av_cold int encode_init(AVCodecContext *avctx) } sort_stt(s, s->state_transition); + find_best_state(best_state, s->state_transition); + for(i=0; iquant_table_count; i++){ for(j=0; jcontext_count[i]; j++){ for(k=0; k<32; k++){ - int p= 128; + double p= 128; if(s->rc_stat2[i][j][k][0]+s->rc_stat2[i][j][k][1]){ - p=256*s->rc_stat2[i][j][k][1] / (s->rc_stat2[i][j][k][0]+s->rc_stat2[i][j][k][1]); + p=256.0*s->rc_stat2[i][j][k][1] / (s->rc_stat2[i][j][k][0]+s->rc_stat2[i][j][k][1]); } - p= av_clip(p, 1, 254); - s->initial_states[i][j][k]= p; + s->initial_states[i][j][k]= best_state[av_clip(round(p), 1, 255)][av_clip((s->rc_stat2[i][j][k][0]+s->rc_stat2[i][j][k][1])/gob_count, 0, 255)]; } } }