[FFmpeg-cvslog] vc2enc: macro out slice size rounding
Rostislav Pehlivanov
git at videolan.org
Wed Mar 23 19:08:52 CET 2016
ffmpeg | branch: master | Rostislav Pehlivanov <atomnuker at gmail.com> | Wed Mar 23 17:46:23 2016 +0000| [14b41e061db641150bee90e476bf86731be89a6e] | committer: Rostislav Pehlivanov
vc2enc: macro out slice size rounding
Signed-off-by: Rostislav Pehlivanov <atomnuker at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=14b41e061db641150bee90e476bf86731be89a6e
---
libavcodec/vc2enc.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index 209413f..3f65424 100644
--- a/libavcodec/vc2enc.c
+++ b/libavcodec/vc2enc.c
@@ -36,6 +36,9 @@
* (COEF_LUT_TAB*MAX_QUANT_INDEX) since the sign is appended during encoding */
#define COEF_LUT_TAB 2048
+/* The limited size resolution of each slice forces us to do this */
+#define SSIZE_ROUND(b) (FFALIGN((b), s->size_scaler) + 4 + s->prefix_bytes)
+
/* Decides the cutoff point in # of slices to distribute the leftover bytes */
#define SLICE_REDIST_TOTAL 150
@@ -688,7 +691,7 @@ static int rate_control(AVCodecContext *avctx, void *arg)
bits_last = bits;
}
slice_dat->quant_idx = av_clip(quant, 0, s->q_ceil-1);
- slice_dat->bytes = FFALIGN((bits >> 3), s->size_scaler) + 4 + s->prefix_bytes;
+ slice_dat->bytes = SSIZE_ROUND(bits >> 3);
slice_dat->bytes_left = s->slice_max_bytes - slice_dat->bytes;
return 0;
}
@@ -748,7 +751,7 @@ static int calc_slice_sizes(VC2EncContext *s)
prev_bytes = args->bytes;
new_idx = FFMAX(args->quant_idx - 1, 0);
bits = count_hq_slice(args, new_idx);
- bytes = FFALIGN((bits >> 3), s->size_scaler) + 4 + s->prefix_bytes;
+ bytes = SSIZE_ROUND(bits >> 3);
diff = bytes - prev_bytes;
if ((bytes_left - diff) > 0) {
args->quant_idx = new_idx;
@@ -1016,16 +1019,16 @@ static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
/* Rate control */
max_frame_bytes = (av_rescale(r_bitrate, s->avctx->time_base.num,
s->avctx->time_base.den) >> 3) - header_size;
+ s->slice_max_bytes = av_rescale(max_frame_bytes, 1, s->num_x*s->num_y);
/* Find an appropriate size scaler */
while (sig_size > 255) {
- s->slice_max_bytes = FFALIGN(av_rescale(max_frame_bytes, 1,
- s->num_x*s->num_y), s->size_scaler);
- s->slice_max_bytes += 4 + s->prefix_bytes;
- sig_size = s->slice_max_bytes/s->size_scaler; /* Signalled slize size */
+ int r_size = SSIZE_ROUND(s->slice_max_bytes);
+ sig_size = r_size/s->size_scaler; /* Signalled slize size */
s->size_scaler <<= 1;
}
+ s->slice_max_bytes = SSIZE_ROUND(s->slice_max_bytes);
s->slice_min_bytes = s->slice_max_bytes - s->slice_max_bytes*(s->tolerance/100.0f);
ret = encode_frame(s, avpkt, frame, aux_data, header_size, s->interlaced);
More information about the ffmpeg-cvslog
mailing list