ffmpeg | branch: master | Paul B Mahol <[email protected]> | Fri Sep  4 18:30:46 
2020 +0200| [615d75f291c6cc3057074245ab83cbd48187dfbc] | committer: Paul B Mahol

avfilter/asrc_anullsrc: add support to set output duration

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

 doc/filters.texi            | 7 +++++++
 libavfilter/asrc_anullsrc.c | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index ebe0d3301e..d0ff3d470f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6076,6 +6076,13 @@ Specifies the sample rate, and defaults to 44100.
 @item nb_samples, n
 Set the number of samples per requested frames.
 
+@item duration, d
+Set the duration of the sourced audio. See
+@ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) 
manual,ffmpeg-utils}
+for the accepted syntax.
+
+If not specified, or the expressed duration is negative, the audio is
+supposed to be generated forever.
 @end table
 
 @subsection Examples
diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c
index 7093f08275..ab56d84424 100644
--- a/libavfilter/asrc_anullsrc.c
+++ b/libavfilter/asrc_anullsrc.c
@@ -40,6 +40,7 @@ typedef struct ANullContext {
     uint64_t channel_layout;
     char   *sample_rate_str;
     int     sample_rate;
+    int64_t duration;
     int nb_samples;             ///< number of samples per requested frame
     int64_t pts;
 } ANullContext;
@@ -54,6 +55,8 @@ static const AVOption anullsrc_options[]= {
     { "r",              "set sample rate",    OFFSET(sample_rate_str)   , 
AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
     { "nb_samples",     "set the number of samples per requested frame", 
OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS },
     { "n",              "set the number of samples per requested frame", 
OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS },
+    { "duration",       "set the audio duration",                        
OFFSET(duration),   AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
+    { "d",              "set the audio duration",                        
OFFSET(duration),   AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
     { NULL }
 };
 
@@ -108,6 +111,10 @@ static int request_frame(AVFilterLink *outlink)
     ANullContext *null = outlink->src->priv;
     AVFrame *samplesref;
 
+    if (null->duration >= 0 &&
+        av_rescale_q(null->pts, outlink->time_base, AV_TIME_BASE_Q) >= 
null->duration)
+        return AVERROR_EOF;
+
     samplesref = ff_get_audio_buffer(outlink, null->nb_samples);
     if (!samplesref)
         return AVERROR(ENOMEM);

_______________________________________________
ffmpeg-cvslog mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to