aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2015-07-30 04:56:06 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2015-07-30 05:00:54 +0200
commitf977e69dacf092af3741abebd20239fa10b107c3 (patch)
tree35fbd9b03ea10afe0079329504a443d25c96a9cb
parentbf2474c74f2c0b956c069f50483c7d104d856d8b (diff)
downloadffmpeg-f977e69dacf092af3741abebd20239fa10b107c3.tar.gz
avcodec/mpegvideo_enc: Ignore QMAX if VBV constraints are exceeded
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/mpegvideo.h1
-rw-r--r--libavcodec/mpegvideo_enc.c8
2 files changed, 7 insertions, 2 deletions
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index f8ae564392..84920452e4 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -539,6 +539,7 @@ typedef struct MpegEncContext {
float rc_buffer_aggressivity;
float border_masking;
int lmin, lmax;
+ int vbv_ignore_qmax;
char *rc_eq;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index c7b710172b..488ec5140f 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -173,7 +173,8 @@ static inline void update_qscale(MpegEncContext *s)
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)
+ if (non_linear_qscale[i] < s->avctx->qmin ||
+ (non_linear_qscale[i] > s->avctx->qmax && !s->vbv_ignore_qmax))
continue;
if (diff < bestdiff) {
bestdiff = diff;
@@ -184,7 +185,7 @@ static inline void update_qscale(MpegEncContext *s)
} 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->qscale = av_clip(s->qscale, s->avctx->qmin, s->vbv_ignore_qmax ? 31 : s->avctx->qmax);
}
s->lambda2 = (s->lambda * s->lambda + FF_LAMBDA_SCALE / 2) >>
@@ -1748,6 +1749,8 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
int i, stuffing_count, ret;
int context_count = s->slice_context_count;
+ s->vbv_ignore_qmax = 0;
+
s->picture_in_gop_number++;
if (load_input_picture(s, pic_arg) < 0)
@@ -1844,6 +1847,7 @@ vbv_retry:
PutBitContext *pb = &s->thread_context[i]->pb;
init_put_bits(pb, pb->buf, pb->buf_end - pb->buf);
}
+ s->vbv_ignore_qmax = 1;
av_log(s->avctx, AV_LOG_VERBOSE, "reencoding frame due to VBV\n");
goto vbv_retry;
}