summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo_enc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2015-07-30 04:42:16 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2015-07-30 05:00:54 +0200
commitbf2474c74f2c0b956c069f50483c7d104d856d8b (patch)
tree0e5f7d92192a97779396c430b78c847be1069850 /libavcodec/mpegvideo_enc.c
parent9723d439fdebe7c9fd3819785173fc28509c434b (diff)
avcodec/mpeg12enc: extend QP range to 28 for non linear quantizers
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r--libavcodec/mpegvideo_enc.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index e39114244c..c7b710172b 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -163,9 +163,29 @@ void ff_convert_matrix(MpegEncContext *s, int (*qmat)[64],
static inline void update_qscale(MpegEncContext *s)
{
- s->qscale = (s->lambda * 139 + FF_LAMBDA_SCALE * 64) >>
- (FF_LAMBDA_SHIFT + 7);
- s->qscale = av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax);
+ if (s->q_scale_type == 1) {
+ int i;
+ int bestdiff=INT_MAX;
+ int best = 1;
+ static const uint8_t non_linear_qscale[] = {
+ 1,2,3,4,5,6,7,8,9,10,11,12,14,16,18,20,24,26,28
+ };
+
+ for (i = 0 ; i<FF_ARRAY_ELEMS(non_linear_qscale); i++) {
+ int diff = FFABS((non_linear_qscale[i]<<(FF_LAMBDA_SHIFT + 7)) - (int)s->lambda * 139);
+ if (non_linear_qscale[i] < s->avctx->qmin || non_linear_qscale[i] > s->avctx->qmax)
+ continue;
+ if (diff < bestdiff) {
+ bestdiff = diff;
+ best = non_linear_qscale[i];
+ }
+ }
+ s->qscale = best;
+ } else {
+ s->qscale = (s->lambda * 139 + FF_LAMBDA_SCALE * 64) >>
+ (FF_LAMBDA_SHIFT + 7);
+ s->qscale = av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax);
+ }
s->lambda2 = (s->lambda * s->lambda + FF_LAMBDA_SCALE / 2) >>
FF_LAMBDA_SHIFT;
@@ -616,9 +636,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
}
if (s->q_scale_type == 1) {
- if (avctx->qmax > 12) {
+ if (avctx->qmax > 28) {
av_log(avctx, AV_LOG_ERROR,
- "non linear quant only supports qmax <= 12 currently\n");
+ "non linear quant only supports qmax <= 28 currently\n");
return -1;
}
}