[FFmpeg-cvslog] avfilter/asrc_anullsrc: make number of output samples match duration

Paul B Mahol git at videolan.org
Sun Sep 13 14:18:41 EEST 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Sep 13 13:08:35 2020 +0200| [0a17a4891d85e22a077e8d85aa424efebf6c8b76] | committer: Paul B Mahol

avfilter/asrc_anullsrc: make number of output samples match duration

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

 libavfilter/asrc_anullsrc.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c
index 0ce2cfd754..f6bd595470 100644
--- a/libavfilter/asrc_anullsrc.c
+++ b/libavfilter/asrc_anullsrc.c
@@ -93,19 +93,28 @@ static int query_formats(AVFilterContext *ctx)
     return ff_set_common_channel_layouts(ctx, ff_make_format64_list(chlayouts));
 }
 
+static av_cold int config_props(AVFilterLink *outlink)
+{
+    ANullContext *null = outlink->src->priv;
+
+    if (null->duration >= 0)
+        null->duration = av_rescale(null->duration, null->sample_rate, AV_TIME_BASE);
+
+    return 0;
+}
+
 static int activate(AVFilterContext *ctx)
 {
     ANullContext *null = ctx->priv;
     AVFilterLink *outlink = ctx->outputs[0];
 
-    if (null->duration >= 0 &&
-        av_rescale_q(null->pts, outlink->time_base, AV_TIME_BASE_Q) >= null->duration) {
+    if (null->duration >= 0 && null->pts >= null->duration) {
         ff_outlink_set_status(outlink, AVERROR_EOF, null->pts);
         return 0;
     }
 
     if (ff_outlink_frame_wanted(outlink)) {
-        AVFrame *samplesref = ff_get_audio_buffer(outlink, null->nb_samples);
+        AVFrame *samplesref = ff_get_audio_buffer(outlink, null->duration >= 0 ? FFMIN(null->nb_samples, null->duration - null->pts) : null->nb_samples);
         int ret;
 
         if (!samplesref)
@@ -128,6 +137,7 @@ static const AVFilterPad avfilter_asrc_anullsrc_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_AUDIO,
+        .config_props  = config_props,
     },
     { NULL }
 };



More information about the ffmpeg-cvslog mailing list