diff options
author | Paul B Mahol <onemda@gmail.com> | 2020-09-04 18:30:46 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2020-09-04 19:37:29 +0200 |
commit | 615d75f291c6cc3057074245ab83cbd48187dfbc (patch) | |
tree | 6ead9500c6d379f25565172fb8f7621747550eda | |
parent | 88db1745fc3b99cd8df000baa0b1af9ee2bac4ac (diff) |
avfilter/asrc_anullsrc: add support to set output duration
-rw-r--r-- | doc/filters.texi | 7 | ||||
-rw-r--r-- | libavfilter/asrc_anullsrc.c | 7 |
2 files changed, 14 insertions, 0 deletions
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); |