avfilter/f_loop: fix length of aloop leftover buffer

If the audio loop stops inside an audio frame, the leftover buffer contains the
end of the frame, which is not looped. The length supposed to be the part which
was not written to the loop buffer, so we need to drain exactly that number of
bytes from the leftover buffer.

Signed-off-by: Marton Balint <cus@passwd.hu>
(cherry picked from commit b33a594160)
This commit is contained in:
Marton Balint 2024-11-03 22:32:51 +01:00
parent dcdfd7fb62
commit ff0f25a154
1 changed files with 2 additions and 3 deletions

View File

@ -150,14 +150,13 @@ static int afilter_frame(AVFilterLink *inlink, AVFrame *frame)
s->pts += av_rescale_q(s->start - s->ignored_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); s->pts += av_rescale_q(s->start - s->ignored_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base);
} }
s->nb_samples += ret - drain; s->nb_samples += ret - drain;
drain = frame->nb_samples - written; if (s->nb_samples == s->size && frame->nb_samples > written) {
if (s->nb_samples == s->size && drain > 0) {
int ret2; int ret2;
ret2 = av_audio_fifo_write(s->left, (void **)frame->extended_data, frame->nb_samples); ret2 = av_audio_fifo_write(s->left, (void **)frame->extended_data, frame->nb_samples);
if (ret2 < 0) if (ret2 < 0)
return ret2; return ret2;
av_audio_fifo_drain(s->left, drain); av_audio_fifo_drain(s->left, written);
} }
frame->nb_samples = ret; frame->nb_samples = ret;
s->pts += av_rescale_q(ret, (AVRational){1, outlink->sample_rate}, outlink->time_base); s->pts += av_rescale_q(ret, (AVRational){1, outlink->sample_rate}, outlink->time_base);