[FFmpeg-cvslog] vc2enc: calculate the minimum slice size only once

Rostislav Pehlivanov git at videolan.org
Fri Feb 26 16:41:25 CET 2016


ffmpeg | branch: master | Rostislav Pehlivanov <atomnuker at gmail.com> | Fri Feb 26 15:38:26 2016 +0000| [bc7beb657499bbbebff707ff7e7e31acc562d840] | committer: Rostislav Pehlivanov

vc2enc: calculate the minimum slice size only once

This commit moves the minimum bits per slice calculations outside of the
rate control function as it is identical for every slice.

Signed-off-by: Rostislav Pehlivanov <atomnuker at gmail.com>

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

 libavcodec/vc2enc.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index 53e2f14..fd2abd5 100644
--- a/libavcodec/vc2enc.c
+++ b/libavcodec/vc2enc.c
@@ -68,6 +68,7 @@ typedef struct SliceArgs {
     int y;
     int quant_idx;
     int bits_ceil;
+    int bits_floor;
     int bytes;
 } SliceArgs;
 
@@ -118,6 +119,7 @@ typedef struct VC2EncContext {
 
     /* Rate control stuff */
     int slice_max_bytes;
+    int slice_min_bytes;
     int q_ceil;
     int q_start;
 
@@ -651,9 +653,8 @@ static int rate_control(AVCodecContext *avctx, void *arg)
     const int sy = slice_dat->y;
     int bits_last = INT_MAX, quant_buf[2] = {-1, -1};
     int quant = s->q_start, range = s->q_start/3;
-    const int64_t top = slice_dat->bits_ceil;
-    const double percent = s->tolerance;
-    const double bottom = top - top*(percent/100.0f);
+    const int top = slice_dat->bits_ceil;
+    const int bottom = slice_dat->bits_floor;
     int bits = count_hq_slice(s, sx, sy, quant);
     range -= range & 1; /* Make it an even number */
     while ((bits > top) || (bits < bottom)) {
@@ -688,6 +689,7 @@ static void calc_slice_sizes(VC2EncContext *s)
             args->x = slice_x;
             args->y = slice_y;
             args->bits_ceil = s->slice_max_bytes << 3;
+            args->bits_floor = s->slice_min_bytes << 3;
         }
     }
 
@@ -940,6 +942,8 @@ static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         s->size_scaler <<= 1;
     }
 
+    s->slice_min_bytes = s->slice_max_bytes - s->slice_max_bytes*(s->tolerance/100.0f);
+
     ret = ff_alloc_packet2(avctx, avpkt, max_frame_bytes*2, 0);
     if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");



More information about the ffmpeg-cvslog mailing list