Commit Graph

132 Commits

Author SHA1 Message Date
Anton Khirnov
901f7e3f72 fftools/ffmpeg_mux_init: make encoder_opts local to ost_add()
It is no longer needed after this function returns.
2024-07-03 11:38:52 +02:00
Anton Khirnov
f1664aabb1 fftools/ffmpeg: rewrite checking whether codec AVOptions have been used
Share the code between encoding and decoding. Instead of checking every
stream's options dictionary (which is also used for other purposes),
track all used options in a dedicated dictionary.
2024-07-03 11:38:52 +02:00
Michael Niedermayer
7b48360907
fftools/ffmpeg_mux: Remove unneeded initialization
Not sure this change makes sense, the code is more robust with ret set

Fixes: CID1559178 Unused value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-07-02 21:57:19 +02:00
Anton Khirnov
243a51490a fftools/ffmpeg_filter: only store complex filtergraphs in global array
Store simple filtergraphs in the stream they feed. Keeping the two
separate will be useful in following commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov
bfeb751171 fftools/ffmpeg_mux: drop OutputFile.format
It is no longer used outside of the muxing code (where we can access the
muxer directly).
2024-04-09 10:34:18 +02:00
Anton Khirnov
a4c940c86a fftools/ffmpeg_filter: move most of -apad logic to the muxer
The decision whether -apad actually does anything is made based on muxer
properties, and so more properly belongs there. Filtering code only
receives the result.
2024-04-09 10:34:18 +02:00
Anton Khirnov
b8e6802023 fftools/ffmpeg_filter: pass sws/swr opts through OutputFilterOptions
Do not read them from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov
509afedaaf fftools/ffmpeg_filter: pass vsync method through OutputFilterOptions
Do not read it from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov
8996945d45 fftools/ffmpeg_enc: set AV_PKT_FLAG_TRUSTED on encoded packets
This allows using WRAPPED_AVFRAME encoders with loopback decoders in
order to connect multiple filtergraphs together.

Clear the flag in muxers, since lavf does not need it for anything and
it would change the results of framecrc FATE tests.
2024-03-13 08:01:28 +01:00
Anton Khirnov
2ee9362419 fftools/ffmpeg: remove unncessary casts for *_thread() return values
These functions used to be passed directly to pthread_create(), which
required them to return void*. This is no longer the case, so they can
return a plain int.
2024-03-13 08:01:15 +01:00
Anton Khirnov
e48055fdce fftools/ffmpeg: remove options deprecated before 6.0 2024-03-01 16:51:11 +01:00
Andreas Rheinhardt
906fc2b2e7 fftools/ffmpeg_mux: Fix use of uninitialized variable
Broken in a2fc86378a.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-25 13:41:56 +01:00
Anton Khirnov
a2fc86378a fftools/ffmpeg: declare loop indices inside loops 2024-02-24 11:51:41 +01:00
Andreas Rheinhardt
44620ade25 fftools/ffmpeg_mux_init: Fix attachment_filename use-after-free
The filename is freed with the OptionsContext and therefore
there will be a use-after-free when reporting the filename
in print_stream_maps(). So create a copy of the string.

This is a regression since 8aed3911fc.
fate-lavf-mkv_attachment exhibits it (and reports a random nonsense
filename here), but this does not make the test fail (not even with
valgrind; only with ASAN, as it aborts on use-after-free).

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-18 18:09:33 +01:00
Anton Khirnov
931192226b fftools/ffmpeg_mux: fix terminating muxer on streamcopy with -t
Reported-by: Andreas Rheinhardt
2024-02-05 11:55:12 +01:00
王昊然
344ec7a3f7 fftools/ffmpeg: use correct unit prefix symbol for binary scaled byte values
Fix bug #10501

Signed-off-by: WHR <msl0000023508@gmail.com>
2024-02-03 12:50:42 +01:00
Anton Khirnov
2ad0b8e0ea fftools/ffmpeg: use a mutex for enc_stats_write()
It may be called concurrently from different threads to write into the
same file.
2023-12-18 08:50:02 +01:00
Anton Khirnov
244d2fcc49 fftools/ffmpeg_mux: deduplicate uniniting EncStats 2023-12-18 08:50:02 +01:00
Anton Khirnov
7a7550ec28 fftools/ffmpeg_mux: factor timestamps processing out of write_packet() 2023-12-18 08:50:02 +01:00
Anton Khirnov
3dc319587f fftools/ffmpeg: deprecate -fps_mode/vsync drop
It depends on the ability of muxers to generate timestamps, which is
itself deprecated.
2023-12-18 08:50:02 +01:00
Anton Khirnov
8a11724a02 fftools/ffmpeg_mux: stop logging to AVFormatContext
Only the muxer itself is supposed to do that. Log to OutputStream
instead.

Drop now-redundant information from the logged string.
2023-12-18 08:50:02 +01:00
Anton Khirnov
4549f20222 fftools/ffmpeg: drop OutputFile.sq_encode
It is unused since d119ae2fd8
2023-12-14 20:16:54 +01:00
Anton Khirnov
0d01e61807 fftools/ffmpeg_mux: move OutputStream.sq_idx_mux to private data
It should not be accessed outside of ffmpeg_mux*
2023-12-14 20:16:54 +01:00
Anton Khirnov
4224895a87 fftools/ffmpeg: replace OutputStream.file_index by a pointer
Reduces the need to use the output_files global array.
2023-12-14 20:16:53 +01:00
Anton Khirnov
5256b2fbe6 fftools/ffmpeg_mux: print latency information in -debug_ts muxing output 2023-12-14 08:11:05 +01:00
Anton Khirnov
c9f38210fc fftools/ffmpeg: merge DemuxPktData into FrameData
This way we can propagate arbitrary data from the demuxer all the way
into the muxer, using a single struct.
2023-12-14 08:11:05 +01:00
Anton Khirnov
d119ae2fd8 fftools/ffmpeg: convert to a threaded architecture
Change the main loop and every component (demuxers, decoders, filters,
encoders, muxers) to use the previously added transcode scheduler. Every
instance of every such component was already running in a separate
thread, but now they can actually run in parallel.

Changes the results of ffmpeg-fix_sub_duration_heartbeat - tested by
JEEB to be more correct and deterministic.
2023-12-12 08:24:18 +01:00
Anton Khirnov
9b8cc36ce0 fftools/ffmpeg: add thread-aware transcode scheduling infrastructure
See the comment block at the top of fftools/ffmpeg_sched.h for more
details on what this scheduler is for.

This commit adds the scheduling code itself, along with minimal
integration with the rest of the program:
* allocating and freeing the scheduler
* passing it throughout the call stack in order to register the
  individual components (demuxers/decoders/filtergraphs/encoders/muxers)
  with the scheduler

The scheduler is not actually used as of this commit, so it should not
result in any change in behavior. That will change in future commits.
2023-12-12 08:24:18 +01:00
Anton Khirnov
75efe530ce fftools/ffmpeg_mux: move bitstream filtering to the muxer thread
This will be the appropriate place for it after the rest of transcoding
is switched to a threaded architecture.
2023-12-12 08:24:18 +01:00
Anton Khirnov
1983507b6e fftools/ffmpeg_mux: add muxing thread private data
To be used for data that never needs to be visible outside of the muxer
thread. Start by moving the muxed AVPacket in there.
2023-12-12 08:24:18 +01:00
Anton Khirnov
7c97a0c63f fftools/ffmpeg: move a few inline function into a new header
Will allow to use them in future commits without including the whole
ffmpeg.h.
2023-11-14 18:18:26 +01:00
Leo Izen
60be62d293
fftools/ffmpeg_mux: replace monotonous with monotonic
The word "monotonous" means "spoken in a monotone" which is not what we
mean here. We mean "monotonic" i.e. nondecreasing.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2023-09-01 03:36:24 -04:00
Anton Khirnov
bff48e8d69 fftools/ffmpeg_mux: rename of_close() to of_free()
This function is primarily a destructor for OutputFile, the underlying
AVIOContext is normally closed earlier (right after writing the
trailer).
2023-08-30 11:53:50 +02:00
Anton Khirnov
8ecbb1f9af fftools/ffmpeg_mux: stop rescaling timestamps in of_streamcopy()
This function converts packet timestamps from the input stream timebase
to OutputStream.mux_timebase, which may or may not be equal to the
actual output AVStream timebase (and even when it is, this may not
always be the optimal choice due to bitstream filtering).

Just keep the timestamps in input stream timebase, they will be rescaled
as needed before bitstream filtering and/or sending the packet to the
muxer.

Move the av_rescale_delta() call for audio (needed to preserve accuracy
with coarse demuxer timebases) to write_packet.

Drop now-unused OutputStream.mux_timebase.
2023-08-30 11:53:46 +02:00
Anton Khirnov
ed5caaaf22 fftools/ffmpeg_mux: use correct timebases for bitstream filtering
Bitstream filtering input timebase is not always necessarily equal to
OutputStream.mux_timebase. Also, set AVPacket.time_base correctly for
packets output by bitstream filters

Do not rescale at all in of_output_packet() when not doing bitstream
filtering, as it's unnecessary - write_packet() will rescale to the
actual muxer timebase.
2023-08-30 11:51:42 +02:00
Anton Khirnov
e0f4259689 fftools/ffmpeg_mux: return errors from of_output_packet() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov
2e742a2c3c fftools/ffmpeg_mux: return errors from of_streamcopy() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov
9a2335444b fftools/ffmpeg_mux: forward EOF from the sync queue
EOF from sq_receive() means no packets will ever be output by the sync
queue. Since the muxing sync queue is always used by all interleaved
(i.e. non-attachment) streams, this means no further packets can make
it to the muxer and we can terminate muxing now.
2023-07-13 13:08:56 +02:00
Anton Khirnov
01897c1788 fftools/ffmpeg_dec: move decoding to a separate thread
This is only a preparatory step to a fully threaded architecture and
does not yet make decoding truly parallel - the main thread will
currently submit a packet and wait until it has been fully processed by
the decoding thread before moving on. Decoder behavior as observed by
the rest of the program should remain unchanged. That will change in
future commits after encoders and filters are moved to threads and a
thread-aware scheduler is added.
2023-06-19 09:48:55 +02:00
Anton Khirnov
141d11cb3c fftools/ffmpeg_mux: make OutputStream.pkt private
It is no longer used outside of muxing code.
2023-06-05 16:16:13 +02:00
Anton Khirnov
f94957e8f4 fftools/ffmpeg_mux: simplify calling of_output_packet()
Use NULL packets to signal EOF instead of a separate variable. This is
made possible by the previous commit.
2023-06-05 16:16:12 +02:00
Anton Khirnov
96e1325d91 fftools/ffmpeg_mux: use a dedicated packet for BSF output
Currently of_output_packet() reuses the input packet, which requires its
callers to submit blank packets even on EOF, which makes the code more
complex.
2023-06-05 16:16:12 +02:00
Anton Khirnov
d7781cfb95 fftools/ffmpeg: convert timestamps inside the muxer
Packets submitted to the muxer now have their timebase attached to them,
so the muxer can do conversion to muxing timebase and avoid exposing it
to callers.
2023-06-05 16:15:04 +02:00
Anton Khirnov
57021a68d9 fftools/ffmpeg_mux: set stream duration after the timebase is certainly known
Stop assuming the encoder knows the muxing timebase, which does not
always have to hold (e.g. due to bitstream filters).
2023-06-05 16:15:04 +02:00
Anton Khirnov
106167374c fftools/ffmpeg_mux: flush bsfs immediately on exceeding recoding time
Current code marks the output stream as finished and waits for a flush
packet, but that is both unnecessary and suspect, as in theory nothing
should be sent to a finished stream - not even flush packets.
2023-05-31 16:20:19 +02:00
Anton Khirnov
da7ae627e1 fftools/ffmpeg_filter: always pass graph description to fg_create()
Currently NULL would be passed for simple filtergraphs, which would
make the filter code extract the graph description from the output
stream when needed. This is unnecessarily convoluted.
2023-05-31 16:15:47 +02:00
Anton Khirnov
a1002bc39c fftools/ffmpeg: replace print_error() by more meaningful messages 2023-05-15 13:32:01 +02:00
Anton Khirnov
09dd9c5f41 fftools/ffmpeg_filter: add filtergraph private data
Start by moving OutputStream.filtered_frame to it, which really belongs
to the filtergraph rather than the output stream.
2023-05-02 10:59:24 +02:00
Anton Khirnov
f4a60b8ddc fftools/ffmpeg: reduce access to OutputStream.enc_ctx
It will be made private to Encoder in the future.
2023-05-02 10:59:24 +02:00
Anton Khirnov
ab0d2052a3 fftools/ffmpeg: remove unused function arguments 2023-04-24 16:56:06 +02:00