[FFmpeg-devel] [PATCH 4/7] vc2enc: clip and warn when user bitrate set too low

2016-02-27 Thread Rostislav Pehlivanov
The encoder crashed on verly low bitrates since there wasn't enough
space allocated.

Signed-off-by: Rostislav Pehlivanov 
---
 libavcodec/vc2enc.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index 5e11aa1..27db6c0 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*2;
+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/100.0f);
+}
+
 return 0;
 
 alloc_fail:
-- 
2.7.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/7] vc2enc: clip and warn when user bitrate set too low

2016-02-27 Thread Moritz Barsnick
On Sat, Feb 27, 2016 at 19:29:05 +, Rostislav Pehlivanov wrote:
> +av_log(avctx, AV_LOG_WARNING,
> +   "Bitrate too low, clipping to minimum = %.2lf Mbps!\n",
> +   (double)avctx->bit_rate/100.0f);

"%lf" is undefined in C90, and otherwise identical to "%f".
libavutil/softfloat.c (and only that) does also use it though. ("%f" is
already double. There's no printf format specifier for float.)

And if you're going to make the division produce a double, you could
just as well use a double constant in it.

Too much nitpicking for a warning message, sorry,
Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel