summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorRostislav Pehlivanov <atomnuker@gmail.com>2016-02-27 18:38:09 +0000
committerRostislav Pehlivanov <atomnuker@gmail.com>2016-02-28 19:06:29 +0000
commit6e5c6d61bddab12b1d9002ac422cbd2506a30177 (patch)
treea59a1699ce5e38f9e8e49fa7c77e3159cd259e3e /libavcodec
parent0a2adf0f47ce6f7acc53e633e0544d4e05448346 (diff)
vc2enc: clip and warn when user bitrate set too low
The encoder crashed on verly low bitrates since there wasn't enough space allocated. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/vc2enc.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index 5e11aa1e43..27db6c0194 100644
--- a/libavcodec/vc2enc.c
+++ b/libavcodec/vc2enc.c
@@ -1008,12 +1008,24 @@ static av_cold int vc2_encode_end(AVCodecContext *avctx)
return 0;
}
+static int minimum_frame_bits(VC2EncContext *s)
+{
+ int slice_x, slice_y, bits = 0;
+ s->size_scaler = 64;
+ for (slice_y = 0; slice_y < s->num_y; slice_y++) {
+ for (slice_x = 0; slice_x < s->num_x; slice_x++) {
+ bits += count_hq_slice(s, NULL, NULL, slice_x, slice_y, s->q_ceil);
+ }
+ }
+ return bits;
+}
static av_cold int vc2_encode_init(AVCodecContext *avctx)
{
Plane *p;
SubBand *b;
int i, j, level, o, shift;
+ int64_t bits_per_frame, min_bits_per_frame;
VC2EncContext *s = avctx->priv_data;
s->picture_number = 0;
@@ -1161,6 +1173,17 @@ static av_cold int vc2_encode_init(AVCodecContext *avctx)
}
}
+ bits_per_frame = av_rescale(avctx->bit_rate, avctx->time_base.num,
+ avctx->time_base.den);
+ min_bits_per_frame = minimum_frame_bits(s) + 8*sizeof(LIBAVCODEC_IDENT) + 8*40 + 8*20000;
+ if (bits_per_frame < min_bits_per_frame) {
+ avctx->bit_rate = av_rescale(min_bits_per_frame, avctx->time_base.den,
+ avctx->time_base.num);
+ av_log(avctx, AV_LOG_WARNING,
+ "Bitrate too low, clipping to minimum = %.2lf Mbps!\n",
+ (double)avctx->bit_rate/1000000.0f);
+ }
+
return 0;
alloc_fail: