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)]; } } }