mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
avfilter/asrc_anullsrc: add support to set output duration
This commit is contained in:
parent
88db1745fc
commit
615d75f291
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user