diff options
author | Anton Khirnov <anton@khirnov.net> | 2022-06-10 14:21:42 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2022-07-23 11:53:19 +0200 |
commit | 4740fea7ddf5f81577c9f5a0c096a8a16a54716e (patch) | |
tree | a1a5d74dc843e94bf0193116a4db8f24431b5a2c /fftools/ffmpeg.h | |
parent | 9ac78fb347e26270ebaf5ed41e55d34065853583 (diff) | |
download | ffmpeg-4740fea7ddf5f81577c9f5a0c096a8a16a54716e.tar.gz |
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.
Diffstat (limited to 'fftools/ffmpeg.h')
-rw-r--r-- | fftools/ffmpeg.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 090bf67d2d..58e093b2cb 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -26,6 +26,7 @@ #include <signal.h> #include "cmdutils.h" +#include "sync_queue.h" #include "libavformat/avformat.h" #include "libavformat/avio.h" @@ -151,6 +152,7 @@ typedef struct OptionsContext { int64_t limit_filesize; float mux_preload; float mux_max_delay; + float shortest_buf_duration; int shortest; int bitexact; @@ -484,6 +486,7 @@ typedef struct OutputStream { int64_t max_frames; AVFrame *filtered_frame; AVFrame *last_frame; + AVFrame *sq_frame; AVPacket *pkt; int64_t last_dropped; int64_t last_nb0_frames[3]; @@ -575,6 +578,9 @@ typedef struct OutputStream { /* frame encode sum of squared error values */ int64_t error[4]; + + int sq_idx_encode; + int sq_idx_mux; } OutputStream; typedef struct Muxer Muxer; @@ -585,6 +591,9 @@ typedef struct OutputFile { Muxer *mux; const AVOutputFormat *format; + SyncQueue *sq_encode; + SyncQueue *sq_mux; + AVFormatContext *ctx; int ost_index; /* index of the first stream in output_streams */ int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units |