Commit dbc7f02a authored by Paul B Mahol's avatar Paul B Mahol

avfilter/aeval: trim last frame's number of samples to match requested duration

Fixes #6181.
Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 353f509e
...@@ -277,16 +277,24 @@ static int request_frame(AVFilterLink *outlink) ...@@ -277,16 +277,24 @@ static int request_frame(AVFilterLink *outlink)
AVFrame *samplesref; AVFrame *samplesref;
int i, j; int i, j;
int64_t t = av_rescale(eval->n, AV_TIME_BASE, eval->sample_rate); int64_t t = av_rescale(eval->n, AV_TIME_BASE, eval->sample_rate);
int nb_samples;
if (eval->duration >= 0 && t >= eval->duration) if (eval->duration >= 0 && t >= eval->duration)
return AVERROR_EOF; 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) if (!samplesref)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
/* evaluate expression for each single sample and for each channel */ /* 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_N] = eval->n;
eval->var_values[VAR_T] = eval->var_values[VAR_N] * (double)1/eval->sample_rate; 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) ...@@ -298,7 +306,7 @@ static int request_frame(AVFilterLink *outlink)
samplesref->pts = eval->pts; samplesref->pts = eval->pts;
samplesref->sample_rate = eval->sample_rate; samplesref->sample_rate = eval->sample_rate;
eval->pts += eval->nb_samples; eval->pts += nb_samples;
return ff_filter_frame(outlink, samplesref); return ff_filter_frame(outlink, samplesref);
} }
......
...@@ -769,5 +769,4 @@ ...@@ -769,5 +769,4 @@
0, 877824, 877824, 1152, 2304, 0xb2ae7741 0, 877824, 877824, 1152, 2304, 0xb2ae7741
0, 878976, 878976, 1152, 2304, 0x4de169e4 0, 878976, 878976, 1152, 2304, 0x4de169e4
0, 880128, 880128, 1152, 2304, 0x3cb18530 0, 880128, 880128, 1152, 2304, 0x3cb18530
0, 881280, 881280, 1152, 2304, 0x48b95d6c 0, 881280, 881280, 1152, 2304, 0x5a0c5e7b
0, 882432, 882432, 1152, 2304, 0xcff707ef
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment