ffmpeg/fftools
Anton Khirnov 4740fea7dd fftools/ffmpeg: rework -shortest implementation
The -shortest option (which finishes the output file at the time the
shortest stream ends) is currently implemented by faking the -t option
when an output stream ends. This approach is fragile, since it depends
on the frames/packets being processed in a specific order. E.g. there
are currently some situations in which the output file length will
depend unpredictably on unrelated factors like encoder delay. More
importantly, the present work aiming at splitting various ffmpeg
components into different threads will make this approach completely
unworkable, since the frames/packets will arrive in effectively random
order.

This commit introduces a "sync queue", which is essentially a collection
of FIFOs, one per stream. Frames/packets are submitted to these FIFOs
and are then released for further processing (encoding or muxing) when
it is ensured that the frame in question will not cause its stream to
get ahead of the other streams (the logic is similar to libavformat's
interleaving queue).

These sync queues are then used for encoding and/or muxing when the
-shortest option is specified.

A new option – -shortest_buf_duration – controls the maximum number of
queued packets, to avoid runaway memory usage.

This commit changes the results of the following tests:
- copy-shortest[12]: the last audio frame is now gone. This is
  correct, since it actually outlasts the last video frame.
- shortest-sub: the video packets following the last subtitle packet are
  now gone. This is also correct.
2022-07-23 11:53:19 +02:00
..
Makefile fftools/ffmpeg: rework -shortest implementation 2022-07-23 11:53:19 +02:00
cmdutils.c fftools: Fix preset search pathes 2022-07-08 13:58:49 +02:00
cmdutils.h fftools/cmdutils: split common option handlers into their own file 2022-03-22 18:49:43 +01:00
ffmpeg.c fftools/ffmpeg: rework -shortest implementation 2022-07-23 11:53:19 +02:00
ffmpeg.h fftools/ffmpeg: rework -shortest implementation 2022-07-23 11:53:19 +02:00
ffmpeg_filter.c ffmpeg: convert to new channel layout-API 2022-03-15 09:42:46 -03:00
ffmpeg_hw.c ffmpeg_hw: make hardware selection for filters more user friendly 2021-09-12 13:33:50 -03:00
ffmpeg_mux.c fftools/ffmpeg: rework -shortest implementation 2022-07-23 11:53:19 +02:00
ffmpeg_opt.c fftools/ffmpeg: rework -shortest implementation 2022-07-23 11:53:19 +02:00
ffplay.c fftools/ffplay: fix YUV conversion mode 2022-06-27 12:17:59 +02:00
ffprobe.c ffprobe: print AVFrame.duration 2022-07-19 12:27:18 +02:00
fopen_utf8.h fftools/fopen_utf8: support long paths on Windows for fftools 2022-06-19 01:38:23 +03:00
objpool.c fftools: add an object pool 2022-07-23 11:53:19 +02:00
objpool.h fftools: add an object pool 2022-07-23 11:53:19 +02:00
opt_common.c opt_common: note D and T type streams for completeness. 2022-05-20 23:42:23 +05:30
opt_common.h fftools/cmdutils: split common option handlers into their own file 2022-03-22 18:49:43 +01:00
sync_queue.c fftools/ffmpeg: rework -shortest implementation 2022-07-23 11:53:19 +02:00
sync_queue.h fftools/ffmpeg: rework -shortest implementation 2022-07-23 11:53:19 +02:00