Commit Graph

141 Commits

Author SHA1 Message Date
Anton Khirnov 08bebeb1be Revert "all: Don't set AVClass.item_name to its default value"
Some callers assume that item_name is always set, so this may be
considered an API break.

This reverts commit 0c6203c97a.
2024-01-20 10:34:48 +01:00
Anton Khirnov a8bc79c3fd fftools/ffmpeg: deprecate -filter_script
It is equivalent to -/filter.
2024-01-20 10:23:24 +01:00
Andreas Rheinhardt 0c6203c97a 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>
2023-12-22 15:12:33 +01:00
Anton Khirnov 7f982065a8 fftools/ffmpeg: mark -vsync for future removal
It has already been deprecated over a year ago.
2023-12-22 11:39:57 +01:00
Anton Khirnov 41716214c2 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.
2023-12-22 11:39:57 +01:00
Anton Khirnov 148fac277a 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.
2023-12-22 11:39:57 +01:00
Anton Khirnov 0ba70a6792 fftools/cmdutils: add a struct for a list of SpecifierOpt
Significantly simplifies the code dealing with OPT_SPEC.
2023-12-22 11:39:57 +01:00
James Almer fa961bb383 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>
2023-12-21 10:32:53 -03:00
James Almer ed670b9b98 ffmpeg: add support for muxing AVStreamGroups
Starting with IAMF support.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-12-18 15:18:09 -03: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 02a4393647 fftools/ffmpeg: print keyframe information with -stats_* 2023-12-18 08:50:02 +01:00
Anton Khirnov 23c00d8c89 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]
2023-12-18 08:50:02 +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 0fcea80b2a fftools/ffmpeg: replace InputStream.file_index by a pointer
Reduces the need to use the input_files global array.
2023-12-14 20:16:53 +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
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
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
Andreas Rheinhardt 2a44c4bc9e fftools/ffmpeg_mux_init: Fix leak on error
Fixes Coverity issue #1539098.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-07-23 17:55:38 +02:00
Anton Khirnov 87f0333af1 fftools/cmdutils: add error handling to filter_codec_opts() 2023-07-20 20:47:46 +02:00
Anton Khirnov 49ac7fc485 fftools: remove parse_time_or_die()
Replace it with calling av_parse_time() directly, which provides
graceful error handling and more accurate error messages.
2023-07-20 20:47:46 +02:00
Anton Khirnov 9cb47c78d6 fftools: return errors from parse_number_or_die() instead of aborting
Rename the function to just parse_number().
2023-07-20 20:47:40 +02:00
Anton Khirnov 6c6f13baf3 fftools/ffmpeg: return errors from find_codec_or_die() instead of aborting
Rename the function to just find_codec().
2023-07-20 20:40:26 +02:00
Anton Khirnov 2e6afa799e fftools/cmdutils: add error handling to GROW_ARRAY() 2023-07-20 20:40:26 +02:00
Anton Khirnov 6be4a29397 fftools/cmdutils: add error handling to allocate_array_elem() 2023-07-20 20:40:26 +02:00
Anton Khirnov 26e1e80152 fftools/ffmpeg_opt: reimplement -streamid using a dictionary
This does not require an arbitrary limit on the number of streams.

Also, return error codes from opt_streamid() instead of aborting.
2023-07-20 20:40:26 +02:00
Anton Khirnov ab16e324ea fftools/ffmpeg_filter: return error codes from ofilter_bind_ost() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov c4b074676a fftools/ffmpeg_mux_init: avoid invalid memory access in set_dispositions()
This function assumes AVMEDIA_* are always positive, while in fact it
can also handle AVMEDIA_TYPE_UNKNOWN, which is -1.
2023-07-20 20:30:13 +02:00
Anton Khirnov 037d364797 fftools/ffmpeg_filter: move "smart" pixfmt selection to ffmpeg_mux_init
This code works on encoder information and has no interaction with
filtering, so it does not belong in ffmpeg_filter.
2023-07-20 20:30:04 +02:00
Anton Khirnov 249bca763d fftools/ffmpeg_mux_init: handle pixel format endianness
When -pix_fmt designates a BE/LE pixel format, it gets translated into
the native one by av_get_pix_fmt(). This may not always be the best
choice, as the encoder might only support one endianness. In such a
case, explicitly choose the endianness supported by the encoder.

While this is currently redundant with choose_pixel_fmt() in
ffmpeg_filter.c, the latter code will be deprecated in following commits.
2023-07-20 20:30:04 +02:00
Anton Khirnov 153cf85b24 fftools/ffmpeg_mux_init: fix an array declaration
map_func is supposed to be an array of const pointer to function
returning int, not an array of pointer to function returning const int.

Reported-By: Martin Storsjö
2023-07-16 11:10:00 +02:00
Anton Khirnov dff3a283cd fftools/ffmpeg: rework -enc_time_base handling
Read the timebase from FrameData rather than the input stream. This
should fix #10393 and generally be more reliable.

Replace the use of '-1' to indicate demuxing timebase with the string
'demux'. Also allow to request filter timebase with
'-enc_time_base filter'.
2023-07-15 11:02:11 +02:00
Anton Khirnov 20c42213ea fftools/ffmpeg_mux_init: drop an obsolete assignment
This line was added in c30a4489b4 along with
AVStream.sample_aspect_ratio. However, configuring SAR for video
encoding is now done after this code (specifically in enc_open(), which
is called when the first video frame to be encoded is obtained), so this
line cannot have any meaningful effect.
2023-07-15 11:02:11 +02:00
Anton Khirnov 858b635613 fftools/ffmpeg_mux_init: replace all remaining aborts with returning error codes
Mainly concerns new_stream_*() and their callees.
2023-07-15 11:02:11 +02:00
Anton Khirnov 45473258ff fftools/ffmpeg_mux_init: return error codes from metadata processing instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov dd44871eb9 fftools/ffmpeg_mux_init: improve of_add_programs()
Replace duplicated(!) and broken* custom string parsing with
av_dict_parse_string(). Return error codes instead of aborting.

* e.g. it treats NULL returned from av_get_token() as "separator not
  found", when in fact av_get_token() only returns NULL on memory
  allocation failure
2023-07-15 11:02:11 +02:00
Anton Khirnov fd40197170 fftools/ffmpeg_mux_init: return error codes from validate_enc_avopt() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 4e3557aadb fftools/ffmpeg_mux_init: return error codes from parse_forced_key_frames() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 6691d131d8 fftools/ffmpeg_mux_init: return error codes from copy_meta() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 54cbe6f57d fftools/ffmpeg_mux_init: return error codes from ost_add() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 38a2fc2c29 fftools/ffmpeg_mux_init: move allocation out of prologue
ost_add() has a very large variable declaration prologue, performing
"active" actions that can fail in there is confusing.
2023-07-15 11:02:11 +02:00
Anton Khirnov 4e366100e9 fftools/ffmpeg_mux_init: return error codes from map_*() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov eee09cdf39 fftools/ffmpeg_mux_init: improve error handling in of_add_attachments()
* return error codes instead of aborting
* avoid leaking the AVIOContext on failure
* check the return code of avio_read()
2023-07-15 11:02:11 +02:00
Anton Khirnov b3eedca5e5 fftools/ffmpeg_mux_init: return errors from create_streams() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov cce294638b fftools/ffmpeg: return errors from assert_file_overwrite() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov c313cdd70c fftools/ffmpeg_mux_init: return errors from of_open() instead of aborting 2023-07-15 11:02:11 +02:00