[FFmpeg-devel] [PATCH] vc2enc: implement adaptive quantization
Rostislav Pehlivanov
atomnuker at gmail.com
Fri Mar 18 14:23:50 CET 2016
Actually this breaks lossless mode, made the following 2 changes locally:
-fix lossless mode
-set default slice sizes to 32x16 (greater quality and speed)
---
libavcodec/vc2enc.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index addc5d4..9ff867d 100644
--- a/libavcodec/vc2enc.c
+++ b/libavcodec/vc2enc.c
@@ -687,7 +687,7 @@ static int calc_slice_sizes(VC2EncContext *s)
{
SliceArgs *enc_args = s->slice_args;
SliceArgs **tmp = &s->slice_ratings[s->num_x*s->num_y];
- int i, slice_x, slice_y, bytes_left = 0;
+ int i, slice_x, s_q_avg = 0, slice_y, bytes_left = 0;
int median_ener = 0, total_bytes_needed = 0;
int best = s->num_x*s->num_y/5;
@@ -715,6 +715,7 @@ static int calc_slice_sizes(VC2EncContext *s)
SliceArgs *args = &enc_args[i];
s->slice_ratings[i] = args;
bytes_left += s->slice_max_bytes - args->bytes;
+ s_q_avg = (s_q_avg + args->quant_idx)/2;
median_ener = (median_ener + args->hh_ener)/2;
}
@@ -725,7 +726,7 @@ static int calc_slice_sizes(VC2EncContext *s)
SliceArgs *h = s->slice_ratings[s->num_x*s->num_y - i - 1];
int h_step, h_n_idx, h_bits, h_bytes, h_needs;
- if (l_pos <= 0 && bytes_left <= 0)
+ if (!s_q_avg || (l_pos <= 0 && bytes_left <= 0))
break;
h_step = ff_log2(FFABS(h->hh_ener - median_ener));
@@ -1257,8 +1258,8 @@ alloc_fail:
#define VC2ENC_FLAGS (AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
static const AVOption vc2enc_options[] = {
{"tolerance", "Max undershoot in percent", offsetof(VC2EncContext, tolerance), AV_OPT_TYPE_DOUBLE, {.dbl = 5.0f}, 0.0f, 45.0f, VC2ENC_FLAGS, "tolerance"},
- {"slice_width", "Slice width", offsetof(VC2EncContext, slice_width), AV_OPT_TYPE_INT, {.i64 = 64}, 32, 1024, VC2ENC_FLAGS, "slice_width"},
- {"slice_height", "Slice height", offsetof(VC2EncContext, slice_height), AV_OPT_TYPE_INT, {.i64 = 32}, 8, 1024, VC2ENC_FLAGS, "slice_height"},
+ {"slice_width", "Slice width", offsetof(VC2EncContext, slice_width), AV_OPT_TYPE_INT, {.i64 = 32}, 32, 1024, VC2ENC_FLAGS, "slice_width"},
+ {"slice_height", "Slice height", offsetof(VC2EncContext, slice_height), AV_OPT_TYPE_INT, {.i64 = 16}, 8, 1024, VC2ENC_FLAGS, "slice_height"},
{"wavelet_depth", "Transform depth", offsetof(VC2EncContext, wavelet_depth), AV_OPT_TYPE_INT, {.i64 = 4}, 1, 5, VC2ENC_FLAGS, "wavelet_depth"},
{"wavelet_type", "Transform type", offsetof(VC2EncContext, wavelet_idx), AV_OPT_TYPE_INT, {.i64 = VC2_TRANSFORM_9_7}, 0, VC2_TRANSFORMS_NB, VC2ENC_FLAGS, "wavelet_idx"},
{"9_7", "Deslauriers-Dubuc (9,7)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_9_7}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
--
2.8.0.rc3
More information about the ffmpeg-devel
mailing list