[FFmpeg-cvslog] avfilter/af_aresample: Calculate output buffer size more precisely.

Michael Niedermayer git at videolan.org
Wed Nov 6 23:55:53 CET 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Nov  6 22:59:16 2013 +0100| [ea6331b2c6025819cf56b0c104b1a26b08818435] | committer: Michael Niedermayer

avfilter/af_aresample: Calculate output buffer size more precisely.

Fixes accumulation of data in case of significant silence injections

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ea6331b2c6025819cf56b0c104b1a26b08818435
---

 libavfilter/af_aresample.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
index 86e7b74..e21b3e4 100644
--- a/libavfilter/af_aresample.c
+++ b/libavfilter/af_aresample.c
@@ -170,11 +170,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
 {
     AResampleContext *aresample = inlink->dst->priv;
     const int n_in  = insamplesref->nb_samples;
-    int n_out       = n_in * aresample->ratio * 2 + 256;
+    int64_t delay;
+    int n_out       = n_in * aresample->ratio + 32;
     AVFilterLink *const outlink = inlink->dst->outputs[0];
-    AVFrame *outsamplesref = ff_get_audio_buffer(outlink, n_out);
+    AVFrame *outsamplesref;
     int ret;
 
+    delay = swr_get_delay(aresample->swr, outlink->sample_rate);
+    if (delay > 0)
+        n_out += delay;
+
+    outsamplesref = ff_get_audio_buffer(outlink, n_out);
+
     if(!outsamplesref)
         return AVERROR(ENOMEM);
 



More information about the ffmpeg-cvslog mailing list