[FFmpeg-cvslog] avcodec/mpegvideo_enc: Ignore QMAX if VBV constraints are exceeded

Michael Niedermayer git at videolan.org
Thu Jul 30 05:11:05 CEST 2015


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Thu Jul 30 04:56:06 2015 +0200| [f977e69dacf092af3741abebd20239fa10b107c3] | committer: Michael Niedermayer

avcodec/mpegvideo_enc: Ignore QMAX if VBV constraints are exceeded

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f977e69dacf092af3741abebd20239fa10b107c3
---

 libavcodec/mpegvideo.h     |    1 +
 libavcodec/mpegvideo_enc.c |    8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index f8ae564..8492045 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 c7b7101..488ec51 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;
             }



More information about the ffmpeg-cvslog mailing list