[FFmpeg-devel] [PATCH 2/4] avfilter/f_loop: fix length of aloop leftover buffer

Marton Balint cus at passwd.hu
Mon Nov 11 21:32:41 EET 2024



On Tue, 5 Nov 2024, Marton Balint wrote:

>
>
> On Mon, 4 Nov 2024, James Almer wrote:
>
>>  On 11/4/2024 5:30 PM, Marton Balint wrote:
>>>   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 at passwd.hu>
>>>   ---
>>>     libavfilter/f_loop.c | 5 ++---
>>>     1 file changed, 2 insertions(+), 3 deletions(-)
>>>
>>>   diff --git a/libavfilter/f_loop.c b/libavfilter/f_loop.c
>>>   index 9b01a85405..3372c77fee 100644
>>>   --- a/libavfilter/f_loop.c
>>>   +++ b/libavfilter/f_loop.c
>>>   @@ -170,14 +170,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->nb_samples += ret - drain;
>>>   -            drain = frame->nb_samples - written;
>>>   -            if (s->nb_samples == s->size && drain > 0) {
>>>   +            if (s->nb_samples == s->size && frame->nb_samples >
>>>   written)
>>>   {
>>>                     int ret2;
>>>
>>>                     ret2 = av_audio_fifo_write(s->left, (void
>>>                     **)frame->extended_data, frame->nb_samples);
>>>                     if (ret2 < 0)
>>>                        return ret2;
>>>   -                av_audio_fifo_drain(s->left, drain);
>>>   +                av_audio_fifo_drain(s->left, written);
>>>                }
>>>                 frame->nb_samples = ret;
>>>                 s->pts += av_rescale_q(ret, (AVRational){1,
>>>                 outlink->sample_rate}, outlink->time_base);
>>
>>  Does this fix ticket #11283?
>> 
>
> It is not clear which problem the ticket is referring to, this one (which is 
> a very old issue), or the newer one, which was fixed by the next patch in the
> series. To fix the ticket (by every interpretation) you need both fixes.

Will apply patches 2 and 3.

Regards,
Marton


More information about the ffmpeg-devel mailing list