FFmpeg/fftools
Niklas Haas 9e3030bc44 fftools/ffmpeg_filter: close all no-longer needed inputs
Currently, the thread loop of ffmpeg_filter essentially works like this:

while (1) {
    frame, idx = get_from_decoder();
    err = send_to_filter_graph(frame);
    if (err) { // i.e. EOF
        close_input(idx);
        continue;
    }

    while (filtered_frame = get_filtered_frame())
        send_to_encoder(filtered_frame);
}

The exact details are not 100% correct since the actual control flow is a bit
more complicated as a result of the scheduler, but this is the general flow.

Notably, this leaves the possibility of leaving a no-longer-needed input
permanently open if the filter graph starts producing infinite frames (during
the second loop) *after* it finishes reading from an input, e.g. in a filter
graph like -af atrim,apad.

This patch avoids this issue by always querying the status of all filter graph
inputs and explicitly closing any that were closed downstream; after each round
of reading output frames. As a result, information about the filtergraph being
closed can now propagate back upstream, even if the filter is no longer
requesting any input frames (i.e. input_idx == fg->nb_inputs).

Fixes: https://trac.ffmpeg.org/ticket/11061
See-Also: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20457#issuecomment-6208

Backported-from: 38a5fcc02c

During backporting, I had to change the signature of `close_input()` to
`void close_input(FilterGraph *fg, int input_idx)` since this version of
FFmpeg does not contain a reference to the input index in the InputFilterPriv.
2025-11-27 13:27:54 +01:00
..
Makefile
cmdutils.c
cmdutils.h
ffmpeg.c fftools/ffmpeg: fix gracefully shutdown 2025-09-14 00:31:17 +02:00
ffmpeg.h
ffmpeg_dec.c
ffmpeg_demux.c
ffmpeg_enc.c
ffmpeg_filter.c fftools/ffmpeg_filter: close all no-longer needed inputs 2025-11-27 13:27:54 +01:00
ffmpeg_hw.c
ffmpeg_mux.c
ffmpeg_mux.h
ffmpeg_mux_init.c
ffmpeg_opt.c
ffmpeg_sched.c fftools/ffmpeg_sched: prevent demuxers from getting stuck 2025-11-13 13:38:43 +01:00
ffmpeg_sched.h
ffmpeg_utils.h
ffplay.c
ffplay_renderer.c
ffplay_renderer.h
ffprobe.c
fftools.manifest
fftoolsres.rc
fopen_utf8.h
objpool.c
objpool.h
opt_common.c
opt_common.h
sync_queue.c
sync_queue.h
thread_queue.c
thread_queue.h