Commit Graph

170 Commits

Author SHA1 Message Date
James Almer
14f74f575b fftools/ffmpeg_mux_init: add missing IAMF Param Definition copies
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-27 11:25:11 +02:00
James Almer
cf82e6c8fe fftools/ffmpeg_mux_init: remove leftover debug log messages
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-27 11:25:11 +02:00
James Almer
1ef56868d5 fftools/ffmpeg_mux_init: allow mapping a stream group from one of the inputs
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-24 22:10:41 +02:00
Anton Khirnov
2b3c84d90e fftools/ffmpeg_filter: drop OutputFilter.ost
All remaining code accessing it only needs to know whether this
filtergraph output has been bound or not.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:03 +02:00
Anton Khirnov
14c9f93ebc fftools/ffmpeg_filter: accept encoder thread count through OutputFilterOptions
Stop digging through encoder options manually.

Will allow decoupling filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:03 +02:00
Anton Khirnov
2c1642d8cb fftools/ffmpeg_mux: drop OutputFile.format
It is no longer used outside of the muxing code (where we can access the
muxer directly).

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:03 +02:00
Anton Khirnov
77bc901adf fftools/ffmpeg_mux: drop OutputFile.shortest
It is no longer needed outside of of_open() and its children.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:03 +02:00
Anton Khirnov
f555f8c59c 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.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:03 +02:00
Anton Khirnov
13aec0833c fftools/ffmpeg_filter: pass trim parameters through OutputFilterOptions
Do not read them from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:03 +02:00
Anton Khirnov
bdd3452e28 fftools/ffmpeg_filter: pass autoscale through OutputFilterOptions
Do not read it from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:03 +02:00
Anton Khirnov
e442206f07 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.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:03 +02:00
Anton Khirnov
d3e99533f6 fftools/ffmpeg_filter: accept a caller-provided output name
Do not construct it from OutputStream manually.

Will allow decoupling filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:02 +02:00
Anton Khirnov
7cc7066f87 fftools/ffmpeg: drop OutputStream.is_cfr
It is used in a single place in the filtering code, so it is better to
inline it there.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:02 +02:00
Anton Khirnov
9c6534bdb6 fftools/ffmpeg_filter: pass vsync method through OutputFilterOptions
Do not read it from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:02 +02:00
Anton Khirnov
6bcaf6f67e fftools/ffmpeg_filter: stop accessing encoder AVCodecContext
Pass all the necessary value through OutputFilterOptions.

Will allow decoupling filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:01 +02:00
Anton Khirnov
1045a81b06 fftools/ffmpeg_filter: move the MJPEG format selection hack to muxer setup
That, if anywhere, is a more appropriate place for it.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:01 +02:00
Anton Khirnov
d8494d49ee fftools/ffmpeg_filter: pass enc_timebase through OutputFilterOptions
Reduces the need to access OutputStream, which will allow decoupling
filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:01 +02:00
Anton Khirnov
1acee9c561 fftools/ffmpeg: warn about ignored -enc_time_base for subtitles earlier
Can do it as soon as that option is parsed, no need to postpone it until
opening the encoder.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:01 +02:00
Anton Khirnov
8f5cfb3d23 fftools/ffmpeg_filter: pass keep_pix_fmt through OutputFilterOptions
Reduces the need to access OutputStream, which will allow decoupling
filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:01 +02:00
Anton Khirnov
b9fdbe196f fftools/ffmpeg_filter: pass ts offset through OutputFilterOptions
Reduces the need to access OutputFile, which will allow decoupling
filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:00 +02:00
Anton Khirnov
d613104d92 fftools/ffmpeg_filter: stop accessing AVCodecContext.codec
Instead pass the encoder through a newly-added output options struct,
analogous to previously added input options.

Will allow decoupling filtering from encoding in future commits.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-04-09 11:51:00 +02:00
Andreas Rheinhardt
80a48b9fb8 fftools/ffmpeg_mux_init: Fix double-free on error
MATCH_PER_STREAM_OPT iterates over all options of a given
OptionDef and tests whether they apply to the current stream;
if so, they are set to ost->apad, otherwise, the code errors
out. If no error happens, ost->apad is av_strdup'ed in order
to take ownership of this pointer.

But this means that setting it originally was premature,
as it leads to double-frees when an error happens lateron.
This can simply be reproduced with
ffmpeg -filter_complex anullsrc  -apad bar -apad:n baz -f null -
This is a regression since 83ace80bfd.

Fix this by using a temporary variable instead of directly
setting ost->apad. Also only strdup the string if it actually
is != NULL.

Reviewed-by: Marth64 <marth64@proxyid.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-03-26 17:29:20 +01:00
James Almer
659d657332 avutil: remove deprecated FF_API_OLD_CHANNEL_LAYOUT
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-03-17 19:41:07 +01:00
Anton Khirnov
597f5919f0 fftools/ffmpeg: remove options deprecated before 6.0
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-03-01 19:21:18 +01:00
Anton Khirnov
416a926aaa fftools/ffmpeg: declare loop indices inside loops
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-02-24 15:27:54 +01:00
Andreas Rheinhardt
b5034d5458 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 8aed3911fc454e79697e183660bf30d31334a64b.
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>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-02-24 15:27:44 +01:00
Anton Khirnov
9bd250a686 all: use designated initializers for AVOption.unit
Makes it robust against adding fields before it, which will be useful in
following commits.

Majority of the patch generated by the following Coccinelle script:

@@
typedef AVOption;
identifier arr_name;
initializer list il;
initializer list[8] il1;
expression tail;
@@
AVOption arr_name[] = { il, { il1,
- tail
+ .unit = tail
}, ...  };

with some manual changes, as the script:
* has trouble with options defined inside macros
* sometimes does not handle options under an #else branch
* sometimes swallows whitespace
2024-02-24 15:27:39 +01:00
Anton Khirnov
93d73e9dcd fftools/ffmpeg: optimize inter-thread queue sizes
Use 8 packets/frames by default rather than 1, which seems to provide
better throughput.

Allow -thread_queue_size to set the muxer queue size manually again.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-02-07 23:22:04 +01:00
James Almer
a888b62ded fftools/ffmpeg_mux_init: don't free the AVDictionaryEntry until after it's been used
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-02-07 23:21:55 +01:00
James Almer
242b574626 fftools/ffmpeg_mux_init: remove whitespaces from input arguments when parsing stream groups
If the arguments are read from a file, things like line breaks could be present

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-02-07 23:21:54 +01:00
Anton Khirnov
f271ff4762 fftools/ffmpeg: deprecate -filter_script
It is equivalent to -/filter.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2024-02-07 23:21:52 +01:00
Andreas Rheinhardt
8ec1f86945 all: Don't set AVClass.item_name to its default value
Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9;
also avoids relocations.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-22 16:49:25 +01:00
Anton Khirnov
da15370fd5 fftools/ffmpeg: mark -vsync for future removal
It has already been deprecated over a year ago.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-22 13:27:38 +01:00
Anton Khirnov
8bd6686e46 fftools/ffmpeg: improve WARN_MULTIPLE_OPT_USAGE()
Currently it requires every single OPT_SPEC option to be accompanied by
an array of alternate names for this option. The vast majority of
options have no alternate names, resulting in a large numbers of
unnecessary single-element arrays that merely contain the option name.

Extend the option parsing API to allow marking options as having
alternate names, or as being the canonical name for some existing
alternatives. Use this new information to avoid the need for
abovementioned unnecessary single-element arrays.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-22 13:27:37 +01:00
Anton Khirnov
9d6123c658 fftools/ffmpeg: change the MATCH_PER_TYPE_OPT macro into a function
There is no reason for it to be a macro anymore, this makes the code
using it cleaner and simpler.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-22 13:27:37 +01:00
Anton Khirnov
77cb00a517 fftools/cmdutils: add a struct for a list of SpecifierOpt
Significantly simplifies the code dealing with OPT_SPEC.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-22 13:27:37 +01:00
James Almer
83e299feaf ffmpeg_mux_init: use strtoll() to parse stream and group indexes
Long is 32 bits signed on Windows, and nb_stream{s,_groups} are both unsigned
int. In a realistic scenario this wont make a difference, but it's still
proper.

Also ensure the parsed string is an integer while at it.

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-21 15:03:47 +01:00
James Almer
a647e4963e ffmpeg: add support for muxing AVStreamGroups
Starting with IAMF support.

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-19 21:25:00 +01:00
Anton Khirnov
5c1686e25d fftools/ffmpeg: use a mutex for enc_stats_write()
It may be called concurrently from different threads to write into the
same file.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-18 09:53:49 +01:00
Anton Khirnov
6d7053948a fftools/ffmpeg: print keyframe information with -stats_*
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-18 09:53:46 +01:00
Anton Khirnov
759848809a fftools/ffmpeg_mux_init: change 1-bit bitfields from int to unsigned
They cannot store 1 as signed, only 0 and -1.

Avoids warnings such as:
  implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-18 09:53:45 +01:00
Anton Khirnov
9142e54ebd fftools/ffmpeg_mux: move OutputStream.sq_idx_mux to private data
It should not be accessed outside of ffmpeg_mux*

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-14 20:39:46 +01:00
Anton Khirnov
10c3abea1a fftools/ffmpeg: replace OutputStream.file_index by a pointer
Reduces the need to use the output_files global array.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-14 20:39:45 +01:00
Anton Khirnov
0bc09d96ad fftools/ffmpeg: replace InputStream.file_index by a pointer
Reduces the need to use the input_files global array.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-14 20:39:45 +01:00
Anton Khirnov
5699286f3e 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.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-12 09:34:43 +01:00
Anton Khirnov
281b9b45e5 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.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2023-12-12 09:34:09 +01:00
Andreas Rheinhardt
02064ba3a3 fftools/ffmpeg_mux_init: Restrict disabling automatic copying of metadata
Fixes ticket #10638 (and should also fix ticket #10482)
by restoring the behaviour from before
3c7dd5ed37.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-11-02 13:24:21 +01:00
Anton Khirnov
d2c416fdf1 fftools/ffmpeg_enc: merge -force_key_frames source/source_no_drop
Always use the functionality of the latter, which makes more sense as it
avoids losing keyframes due to vsync code dropping frames.

Deprecate the 'source_no_drop' value, as it is now redundant.
2023-10-10 12:41:31 +02:00
James Almer
3fd37b5268 fftools/ffmpeg: stop using AVStream.side_data
Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:11:00 -03:00
Anton Khirnov
5d58a35f98 fftools/ffmpeg: deprecate the -top option
It is badly named (should have been -top_field_first, or at least -tff),
underdocumented and underspecified, and (most importantly) entirely
redundant with the setfield filter.
2023-09-18 17:16:06 +02:00