Commit Graph

63 Commits

Author SHA1 Message Date
Anton Khirnov 83646146fe fftools/ffmpeg_mux: make ts_copy_start private to muxing code
It is no longer used outside of ffmpeg_mux*
2023-04-17 12:01:40 +02:00
Anton Khirnov a34f483291 fftools/ffmpeg: add muxer-input codec parameters to OutputStream
It stores codec parameters of the stream submitted to the muxer, which
may be different from the codec parameters in AVStream due to bitstream
filtering.

This avoids the confusing back and forth synchronisation between the
encoder, bitstream filters, and the muxer, now information flows only in
one direction. It also reduces the need for non-muxing code to access
AVStream.
2023-04-17 12:01:40 +02:00
Anton Khirnov a064aed4c3 fftools/ffmpeg: store stream media type in OutputStream
Reduces access to a deeply nested muxer property
OutputStream.st->codecpar->codec_type for this fundamental and immutable
stream property.

Besides making the code shorter, this will allow making the AVStream
(OutputStream.st) private to the muxer in the future.
2023-04-17 12:01:40 +02:00
Anton Khirnov de38e17583 fftools/ffmpeg: initialize no-filter streams earlier
There is no reason to postpone it until transcode_init() anymore, it can
be done right at the end of of_open().
2023-04-17 12:01:40 +02:00
Anton Khirnov ff92ecad2f fftools/ffmpeg: stop setting InputStream fields from muxing/filtering code
Set InputStream.decoding_needed/discard/etc. only from
ist_{filter,output},add() functions. Reduces the knowledge of
InputStream internals in muxing/filtering code.
2023-04-17 12:01:40 +02:00
Anton Khirnov c7438e8737 fftools/ffmpeg_mux_init: consolidate input stream flagging code
Makes it easier to see where the input stream is modified from muxer
code.
2023-04-17 12:01:40 +02:00
Anton Khirnov a0452ee837 fftools/ffmpeg_mux_init: remove a redundant check 2023-04-17 12:00:06 +02:00
Anton Khirnov 12f3f41bbf fftools/ffmpeg: move init_output_stream_streamcopy() to ffmpeg_mux_init
Everything in it can be done immediately when creating the output
stream, there is no reason to postpone it.
2023-04-17 12:00:06 +02:00
Anton Khirnov 9bae55165d fftools/ffmpeg_mux_init: restructure output stream creation
Creating a new output stream of a given type is currently done by
calling new_<type>_stream(), which all start by calling
new_output_stream() to allocate the stream and do common init, followed
by type-specific init.

Reverse this structure - the caller now calls the common function
ost_add() with the type as a parameter, which then calls the
type-specific function internally. This will allow adding common code
that runs after type-specific code in future commits.
2023-04-17 12:00:06 +02:00
Anton Khirnov a7f26b1c63 fftools/ffmpeg_mux_init: move new_output_stream() lower in the file
Reduces the diff in the following commit.

Temporarily add a forward declaration for new_output_stream(), it will
be removed in the next commit.
2023-04-17 12:00:06 +02:00
Anton Khirnov 89c9a3ac35 fftools/ffmpeg: avoid possible invalid reads with short -tag values
Fixes #10319 and #10309.
2023-04-17 11:49:34 +02:00
Anton Khirnov a85e7e5dea fftools/ffmpeg: track a list of non-lavfi outputs in InputStream
Currently, output streams where an input stream is sent directly (i.e.
not through lavfi) are determined by iterating over ALL the output
streams and skipping the irrelevant ones. This is awkward and
inefficient.
2023-04-13 15:11:56 +02:00
Anton Khirnov 798da60e6a fftools/ffmpeg_mux_init: print more meaningful error messages 2023-04-13 15:11:56 +02:00
Anton Khirnov fd91ac11ed fftools/ffmpeg: move OutputStream.last_filter_pts to OutputFilter
This value is associated with the filtergraph output rather than the
output stream, so this is a more appropriate place for it.
2023-04-13 15:11:56 +02:00
Anton Khirnov 87ae84e4af fftools/ffmpeg: move OutputStream.sq_frame to Encoder
It is audio/video encoding-only and does not need to be visible outside
of ffmpeg_enc.c
2023-04-13 15:11:56 +02:00
Anton Khirnov f30b620e98 fftools/ffmpeg: add encoder private data
Start by moving OutputStream.last_frame to it. In the future it will
hold other encoder-internal state.
2023-04-09 15:47:45 +02:00
Anton Khirnov 923c6ab170 fftools/ffmpeg: use sync queues for enforcing audio frame size
The code currently uses lavfi for this, which creates a sort of
configuration dependency loop - the encoder should be ideally
initialized with information from the first audio frame, but to get this
frame one needs to first open the encoder to know the frame size. This
necessitates an awkward workaround, which causes audio handling to be
different from video.

With this change, audio encoder initialization is congruent with video.
2023-04-09 15:47:45 +02:00
Anton Khirnov 8e23a62eff fftools/ffmpeg: drop InputStream.processing_needed
It is equivalent to !InputStream.discard.
2023-04-09 15:47:45 +02:00
Thilo Borgmann 653ee3f159 fftools/ffmpeg_mux_init: Use all metadata selectors if none is specified.
Fixes regression from 3c7dd5ed37.
Fixes ticket #10157.
2023-03-25 20:28:41 +01:00
Anton Khirnov 1e406692e5 fftools/ffmpeg_mux_init: avoid invalid reads in forced keyframe parsing
Fixes #10243
2023-03-20 10:53:03 +01:00
James Almer 6d6ae3595b avformat: remove FF_API_AVSTREAM_CLASS
Signed-off-by: James Almer <jamrial@gmail.com>
2023-02-09 15:35:14 +01:00
Anton Khirnov 42a0dd6e7e fftools/ffmpeg: add an option for writing pre-muxing stats
Analogous to -enc_stats*, but happens right before muxing. Useful
because bitstream filters and the sync queue can modify packets after
encoding and before muxing. Also has access to the muxing timebase.
2023-02-09 15:24:15 +01:00
Jan Ekström 9a820ec8b1 ffmpeg: add video heartbeat capability to fix_sub_duration
Splits the currently handled subtitle at random access point
packets that can be configured to follow a specific output stream.
Currently only subtitle streams which are directly mapped into the
same output in which the heartbeat stream resides are affected.

This way the subtitle - which is known to be shown at this time
can be split and passed to muxer before its full duration is
yet known. This is also a drawback, as this essentially outputs
multiple subtitles from a single input subtitle that continues
over multiple random access points. Thus this feature should not
be utilized in cases where subtitle output latency does not matter.

Co-authored-by: Andrzej Nadachowski <andrzej.nadachowski@24i.com>
Co-authored-by: Bernard Boulay <bernard.boulay@24i.com>

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2023-02-03 16:17:29 +02:00
Anton Khirnov 806ecace91 fftools/ffmpeg: support input frame params in encoding stats 2023-01-31 09:09:23 +01:00
Anton Khirnov 9b5036fabd fftools/ffmpeg: add an AVClass to MuxStream/OutputStream
Use it for logging. This makes log messages related to this output
stream more consistent.
2023-01-29 09:12:22 +01:00
Anton Khirnov d2c983c213 fftools/ffmpeg: add an AVClass to Muxer/OutputFile
Use it for logging. This makes log messages related to this output file
more consistent.
2023-01-29 09:10:57 +01:00
Anton Khirnov 425b2c4a56 fftools/ffmpeg: add options for writing encoding stats
Similar to -vstats, but more flexible:
- works for audio as well as video
- frame and/or packet information
- user-specifiable format
2023-01-29 09:09:59 +01:00
Anton Khirnov 260f391893 fftools/ffmpeg: always generate CFR output when -r is used
Current code may, depending on the muxer, decide to use VSYNC_VFR tagged
with the specified framerate, without actually performing framerate
conversion. This is clearly wrong and against the documentation, which
states unambiguously that -r should produce CFR output for video
encoding.

FATE test changes:
* nuv-rtjpeg: replace -r with '-enc_time_base -1', which keeps the
  original timebase. Output frames are now produced with proper
  durations.
* filter-mpdecimate: just drop the -r option, it is unnecessary
* filter-fps-r: remove, this test makes no sense and actually
  produces broken VFR output (with incorrect frame durations).
2023-01-10 11:49:28 +01:00
Anton Khirnov 2fa2e146cc fftools/ffmpeg: avoid storing full forced keyframe spec
It is not needed after the spec is parsed. Also avoids ugly string
comparisons for each video frame.
2022-11-28 10:28:14 +01:00
Anton Khirnov 334e52e094 fftools/ffmpeg: parse forced keyframes in of_open()
Allows to remove the ugly of_get_chapters() wrapper.
2022-11-28 10:28:14 +01:00
Anton Khirnov b1143330c8 fftools/ffmpeg: move force-keyframe-related vars to a separate struct
There are 8 of them and they are typically used together. Allows to pass
just this struct to forced_kf_apply(), which makes it clear that the
rest of the OutputStream is not accessed there.
2022-11-28 10:28:14 +01:00
Anton Khirnov 95af0bcc34 fftools/ffmpeg_mux_init: postpone matching -disposition to streams
Do it in set_dispositions() rather than during stream creation.

Since at this point all other stream information is known, this allows
setting disposition based on metadata, which implements #10015. This
also avoids an extra allocated string in OutputStream that was unused
after of_open().
2022-11-23 10:36:23 +01:00
Anton Khirnov fd8bf8d3b5 fftools/ffmpeg: remove the input_streams global
Replace it with an array of streams in each InputFile. This is a more
accurate reflection of the actual relationship between InputStream and
InputFile.

Analogous to what was previously done to output streams in
7ef7a22251.
2022-11-23 10:36:23 +01:00
Anton Khirnov 86e2ffedfe fftools/ffmpeg_mux_init: simplify inner loop in map_auto_{video,audio}
Skip unusable streams early and do not compute any scores for them.
2022-11-23 10:36:23 +01:00
Anton Khirnov 4c40581614 fftools/ffmpeg: replace OutputStream.source_index with a pointer to InputStream
This is simpler. The indirection via an index exists for historical
reasons that longer apply.
2022-11-23 10:36:23 +01:00
Anton Khirnov b58264217b fftools/ffmpeg_mux_init: drop an always-false check
It cannot be true since 1959351aec. Effectively reverts 6a3833e141.
2022-11-17 10:52:58 +01:00
Anton Khirnov 13947aff3f fftools/ffmpeg_mux_init: use av_dict_iterate() where appropriate 2022-11-17 10:52:58 +01:00
Anton Khirnov 19e192eae6 fftools/ffmpeg_mux_init: do not call av{codec,format}_get_class() repeatedly 2022-11-17 10:52:58 +01:00
Anton Khirnov 52380a055b fftools/ffmpeg_mux_init: move validating codec avoptions to a separate function 2022-11-17 10:52:58 +01:00
Anton Khirnov 0fb7d111e8 fftools/ffmpeg: move OutputStream.max_frames to MuxStream
It no longer needs to be visible outside of the muxing code.
2022-11-17 10:52:58 +01:00
Anton Khirnov 6a8145a4b1 fftools/ffmpeg_mux_init: move more code from of_open() to create_streams()
Specificaly, the of_add_attachments() call (which can add attachment
streams to the output) and the check whether the output file contains
any streams. They both logically belong in create_streams().
2022-11-17 10:52:58 +01:00
Anton Khirnov c15eb2773a fftools/ffmpeg_[de]mux: constify all uses of OptionsContext 2022-11-16 08:41:14 +01:00
Anton Khirnov 4119480681 fftools/ffmpeg_mux_init: stop using OptionsContext as storage in copy_metadata()
It should be input-only to this code. Will allow making it const in
future commits.
2022-11-16 08:41:14 +01:00
Anton Khirnov 3c7dd5ed37 fftools/ffmpeg_mux_init: drop a duplicated block in copy_metadata()
It does the same thing as the block right below it.
2022-11-16 08:41:14 +01:00
Anton Khirnov 0d821edb40 fftools/ffmpeg_mux_init: stop modifying OptionsContext.*_disable
The current code will override the *_disable fields (set by -vn/-an
options) when creating output streams for unlabeled complex filtergraph
outputs, in order to disable automatic mapping for the corresponding
media type.

However, this will apply not only to automatic mappings, but to manual
ones as well, which should not happen. Avoid this by adding local
variables that are used only for automatic mappings.
2022-10-25 11:12:22 +02:00
Anton Khirnov 69da53ade9 fftools/ffmpeg_mux_init: move code creating streams into a new function
Makes it easy to see where all the streams are created. Will also be
useful in the following commit.
2022-10-25 11:12:05 +02:00
Anton Khirnov 006df0b6fe fftools/ffmpeg_mux_init: stop modifying some OptionsContext fields
Specifically recording_time and stop_time - use local variables instead.
OptionsContext should be input-only to this code. Will allow making it
const in future commits.
2022-10-25 11:11:35 +02:00
Anton Khirnov ccab823559 fftools/ffmpeg_mux_init: constify metadata specifier arguments 2022-10-25 11:04:42 +02:00
Anton Khirnov aa0ce91f57 fftools/ffmpeg_mux_init: avoid modifying OptionsContext.chapters_input_file
Use a local variable instead. This will allow making OptionsContext
const in future commits.
2022-10-25 11:04:42 +02:00
Anton Khirnov 5ccc151bf2 fftools/ffmpeg: factor out copying metadata/chapters from of_open()
This code shares variables like OptionsContext.metadata_*_manual, so it
makes sense to group it together.
2022-10-25 11:04:42 +02:00