diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-02-04 17:33:07 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-02-11 19:25:41 +0100 |
commit | 0aa1d848ece6120ecaa2a43c67fc8705ec6712c5 (patch) | |
tree | 8ebe2796143926a3ed786282c1ec608072eaf5f5 /libavcodec | |
parent | c177f2ec4a21d62fdefd925ad69c24a2f9dad303 (diff) | |
download | ffmpeg-0aa1d848ece6120ecaa2a43c67fc8705ec6712c5.tar.gz |
ffv1enc: better heuristic to calculate initial states
Slightly improves compression of 2pass files
Tested-by: "Peter B." <pb@das-werkstatt.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/ffv1enc.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index a012df334f..2fe51c3f77 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -856,18 +856,29 @@ static av_cold int encode_init(AVCodecContext *avctx) find_best_state(best_state, s->state_transition); for (i = 0; i < s->quant_table_count; i++) { - for (j = 0; j < s->context_count[i]; j++) - for (k = 0; k < 32; k++) { + for (k = 0; k < 32; k++) { + double a=0, b=0; + int jp = 0; + for (j = 0; j < s->context_count[i]; j++) { double p = 128; - if (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]); + if (s->rc_stat2[i][j][k][0] + s->rc_stat2[i][j][k][1] > 200 && j || a+b > 200) { + if (a+b) + p = 256.0 * b / (a + b); + s->initial_states[i][jp][k] = + best_state[av_clip(round(p), 1, 255)][av_clip((a + b) / gob_count, 0, 255)]; + for(jp++; jp<j; jp++) + s->initial_states[i][jp][k] = s->initial_states[i][jp-1][k]; + a=b=0; + } + a += s->rc_stat2[i][j][k][0]; + b += s->rc_stat2[i][j][k][1]; + if (a+b) { + p = 256.0 * b / (a + b); } 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)]; + best_state[av_clip(round(p), 1, 255)][av_clip((a + b) / gob_count, 0, 255)]; } + } } } |