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

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


Do not pointlessly call ff_alloc_packet2 multiple times,
and fix an infinite loop by clamping the maximum
number of bits to target in the algorithm that does
not use lambda.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
 libavcodec/aaccoder.c       |    3 +++
 libavcodec/aacenc.c         |    4 ++--
 tests/ref/acodec/aac        |    4 ++++
 tests/ref/acodec/dca        |    4 ++++
 tests/ref/acodec/nellymoser |    4 ++++
 tests/ref/acodec/ra144      |    4 ++++
 6 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 tests/ref/acodec/aac
 create mode 100644 tests/ref/acodec/dca
 create mode 100644 tests/ref/acodec/nellymoser
 create mode 100644 tests/ref/acodec/ra144

diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 25187b7..b6fefd3 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -721,6 +721,9 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
     int allz = 0;
     float minthr = INFINITY;
 
+    // for values above this the decoder might end up in an endless loop
+    // due to always having more bits than what can be encoded.
+    destbits = FFMIN(destbits, 5800);
     //XXX: some heuristic to determine initial quantizers will reduce search time
     //determine zero bands and upper limits
     for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index fd72daf..44f6ebf 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))
diff --git a/tests/ref/acodec/aac b/tests/ref/acodec/aac
new file mode 100644
index 0000000..471951d
--- /dev/null
+++ b/tests/ref/acodec/aac
@@ -0,0 +1,4 @@
+f7670b2e171cfa10fdebc73ab9af6b4a *./tests/data/acodec/aac.aac
+96185 ./tests/data/acodec/aac.aac
+fed805b125513260ac93feda0d967da6 *./tests/data/aac.acodec.out.wav
+stddev:10989.22 PSNR: 15.51 MAXDIFF:65526 bytes:  1064960/  1058400
diff --git a/tests/ref/acodec/dca b/tests/ref/acodec/dca
new file mode 100644
index 0000000..2e89e68
--- /dev/null
+++ b/tests/ref/acodec/dca
@@ -0,0 +1,4 @@
+66bd0e602be7fb97dc19151554c0ee29 *./tests/data/acodec/dca.dts
+1097124 ./tests/data/acodec/dca.dts
+e1842f7616c65612b10b23245645ac40 *./tests/data/dca.acodec.out.wav
+stddev: 8944.44 PSNR: 17.30 MAXDIFF:56478 bytes:  1060864/  1058400
diff --git a/tests/ref/acodec/nellymoser b/tests/ref/acodec/nellymoser
new file mode 100644
index 0000000..03eb6ae
--- /dev/null
+++ b/tests/ref/acodec/nellymoser
@@ -0,0 +1,4 @@
+46830431216729f78e15c634e91e6ebf *./tests/data/acodec/nellymoser.flv
+82916 ./tests/data/acodec/nellymoser.flv
+ae1e5ec9f206e0e665e54c1c4559fc61 *./tests/data/nellymoser.acodec.out.wav
+stddev:10148.84 PSNR: 16.20 MAXDIFF:55923 bytes:  1058816/  1058400
diff --git a/tests/ref/acodec/ra144 b/tests/ref/acodec/ra144
new file mode 100644
index 0000000..7768049
--- /dev/null
+++ b/tests/ref/acodec/ra144
@@ -0,0 +1,4 @@
+d6740bee5e20fa665e6c94298125b834 *./tests/data/acodec/ra144.ra
+53227 ./tests/data/acodec/ra144.ra
+16d1a0d6cae06cf8a4db009d0fe7a952 *./tests/data/ra144.acodec.out.wav
+stddev: 9525.99 PSNR: 16.75 MAXDIFF:55906 bytes:  1059200/  1058400
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list