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
..
cmdutils.c fftools/cmdutils: don't try to load arguments from file if not needed 2025-09-08 02:13:09 +02:00
cmdutils.h fftools/ffmpeg: add support for multiview video 2024-09-23 17:15:02 +02:00
ffmpeg.c fftools/ffmpeg: fix gracefully shutdown 2025-09-14 00:31:17 +02:00
ffmpeg.h fftools/ffmpeg: add support for multiview video 2024-09-23 17:15:02 +02:00
ffmpeg_dec.c fftools/ffmpeg: add support for multiview video 2024-09-23 17:15:02 +02:00
ffmpeg_demux.c fftools/ffmpeg_demux: ensure the display_rotation option is honored 2025-09-10 09:31:58 -03:00
ffmpeg_enc.c fftools/ffmpeg_mux_init: apply encoder options manually 2024-07-03 11:38:52 +02:00
ffmpeg_filter.c fftools/ffmpeg_filter: close all no-longer needed inputs 2025-11-27 13:27:54 +01:00
ffmpeg_hw.c avutil/common: Don't auto-include mem.h 2024-03-31 00:08:43 +01:00
ffmpeg_mux.c fftools/ffmpeg_mux_init: make encoder_opts local to ost_add() 2024-07-03 11:38:52 +02:00
ffmpeg_mux.h fftools/ffmpeg: replace MATCH_PER_STREAM_OPT(.., str, ..) with a function 2024-08-13 10:28:54 +02:00
ffmpeg_mux_init.c fftools/ffmpeg_mux_init: Use 64bit for score computation in map_auto_video() 2025-09-08 02:13:31 +02:00
ffmpeg_opt.c fftools/ffmpeg: add support for multiview video 2024-09-23 17:15:02 +02:00
ffmpeg_sched.c fftools/ffmpeg_sched: prevent demuxers from getting stuck 2025-11-13 13:38:43 +01:00
ffmpeg_sched.h fftools/ffmpeg_sched: allow decoders to have multiple outputs 2024-09-23 17:15:02 +02:00
ffmpeg_utils.h fftools/ffmpeg: prefer real errors over EOF in err_merge() 2024-07-24 08:20:21 +02:00
ffplay.c fftools/ffplay: fix crash when vk renderer is null 2024-11-06 16:50:56 +08:00
ffplay_renderer.c fftools/ffplay_renderer: use correct NULL value for Vulkan type 2024-06-25 00:19:03 +02:00
ffplay_renderer.h fftools/ffplay: add hwaccel decoding support 2023-11-15 01:20:11 +08:00
ffprobe.c lavu/frame: add side data storing view ID for multi-view video 2024-09-23 17:11:38 +02:00
fftools.manifest fftools: add DPI awareness manifest 2022-08-13 14:42:52 +02:00
fftoolsres.rc fftools: add DPI awareness manifest 2022-08-13 14:42:52 +02:00
fopen_utf8.h avutil/common: Don't auto-include mem.h 2024-03-31 00:08:43 +01:00
Makefile fftools/ffmpeg: add thread-aware transcode scheduling infrastructure 2023-12-12 08:24:18 +01:00
objpool.c fftools/objpool: Don't use return with expression when returning void 2022-07-23 18:58:35 +02:00
objpool.h fftools: add an object pool 2022-07-23 11:53:19 +02:00
opt_common.c fftools/opt_common: add missing newline after printing codecs 2024-09-09 13:03:04 +02:00
opt_common.h fftools/cmdutils: hide some information listing options from basic help 2024-01-20 10:37:32 +01:00
sync_queue.c fftools/ffmpeg_demux, sync_queue: Constify a bit 2024-03-02 02:51:59 +01:00
sync_queue.h fftools/sync_queue: add debug logging 2023-05-28 10:47:59 +02:00
thread_queue.c fftools/thread_queue: count receive-finished streams as finished 2023-11-14 18:18:26 +01:00
thread_queue.h fftools: add a multistream thread-safe queue 2022-07-23 11:53:19 +02:00