aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/vc2enc.c
diff options
context:
space:
mode:
authorRostislav Pehlivanov <atomnuker@gmail.com>2016-02-26 15:38:26 +0000
committerRostislav Pehlivanov <atomnuker@gmail.com>2016-02-26 15:38:26 +0000
commitbc7beb657499bbbebff707ff7e7e31acc562d840 (patch)
treedfb73e0df8753787428e94f361ab4c32d5863061 /libavcodec/vc2enc.c
parent2b811e4605ebd570c647f8a4ed0e021b64fc4208 (diff)
downloadffmpeg-bc7beb657499bbbebff707ff7e7e31acc562d840.tar.gz
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@gmail.com>
Diffstat (limited to 'libavcodec/vc2enc.c')
-rw-r--r--libavcodec/vc2enc.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index 53e2f143ec..fd2abd5456 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");