[FFmpeg-devel] [PATCH] aacenc: Fix issues with huge values of bit_rate.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Fri Apr 6 15:26:25 CEST 2012


Do not pointlessly call ff_alloc_packet2 multiple times,
and fix an infinite loop by clamping lambda.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
 libavcodec/aacenc.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index fd72daf..9918198 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -571,11 +571,11 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         }
         start_ch += chans;
     }
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 768 * s->channels)))
+        return ret;
     do {
         int frame_bits;
 
-        if ((ret = ff_alloc_packet2(avctx, avpkt, 768 * s->channels)))
-            return ret;
         init_put_bits(&s->pb, avpkt->data, avpkt->size);
 
         if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEXACT))
@@ -643,6 +643,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         }
 
         s->lambda *= avctx->bit_rate * 1024.0f / avctx->sample_rate / frame_bits;
+        s->lambda = FFMIN(s->lambda, 65536.f);
 
     } while (1);
 
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list