diff options
author | Paul B Mahol <onemda@gmail.com> | 2017-02-24 18:50:09 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2017-02-25 19:53:14 +0100 |
commit | dbc7f02a727286f353624cf690cc6f430e240e25 (patch) | |
tree | 56526e4484cfe841b686156264648595344ae9a9 /libavfilter/aeval.c | |
parent | 353f509ee34823d8567904236c729b308ed94578 (diff) | |
download | ffmpeg-dbc7f02a727286f353624cf690cc6f430e240e25.tar.gz |
avfilter/aeval: trim last frame's number of samples to match requested duration
Fixes #6181.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/aeval.c')
-rw-r--r-- | libavfilter/aeval.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libavfilter/aeval.c b/libavfilter/aeval.c index ac9dea8f64..42970f42e7 100644 --- a/libavfilter/aeval.c +++ b/libavfilter/aeval.c @@ -277,16 +277,24 @@ static int request_frame(AVFilterLink *outlink) AVFrame *samplesref; int i, j; int64_t t = av_rescale(eval->n, AV_TIME_BASE, eval->sample_rate); + int nb_samples; if (eval->duration >= 0 && t >= eval->duration) return AVERROR_EOF; - samplesref = ff_get_audio_buffer(outlink, eval->nb_samples); + if (eval->duration >= 0) { + nb_samples = FFMIN(eval->nb_samples, av_rescale(eval->duration, eval->sample_rate, AV_TIME_BASE) - eval->pts); + if (!nb_samples) + return AVERROR_EOF; + } else { + nb_samples = eval->nb_samples; + } + samplesref = ff_get_audio_buffer(outlink, nb_samples); if (!samplesref) return AVERROR(ENOMEM); /* evaluate expression for each single sample and for each channel */ - for (i = 0; i < eval->nb_samples; i++, eval->n++) { + for (i = 0; i < nb_samples; i++, eval->n++) { eval->var_values[VAR_N] = eval->n; eval->var_values[VAR_T] = eval->var_values[VAR_N] * (double)1/eval->sample_rate; @@ -298,7 +306,7 @@ static int request_frame(AVFilterLink *outlink) samplesref->pts = eval->pts; samplesref->sample_rate = eval->sample_rate; - eval->pts += eval->nb_samples; + eval->pts += nb_samples; return ff_filter_frame(outlink, samplesref); } |