]> git.sesse.net Git - ffmpeg/commitdiff
vc2enc: calculate the minimum slice size only once
authorRostislav Pehlivanov <atomnuker@gmail.com>
Fri, 26 Feb 2016 15:38:26 +0000 (15:38 +0000)
committerRostislav Pehlivanov <atomnuker@gmail.com>
Fri, 26 Feb 2016 15:38:26 +0000 (15:38 +0000)
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@gmail.com>
libavcodec/vc2enc.c

index 53e2f143ec0cb9df4789f6cde23c5f8e77359a1a..fd2abd5456c2e1d2a2fb3ee171466d66af82f440 100644 (file)
@@ -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");