Commit Graph

1547 Commits

Author SHA1 Message Date
Anton Khirnov
c27b1e6c59 fftools/ffmpeg: drop unused OSTFinished 2024-09-30 09:29:18 +02:00
Anton Khirnov
64f3feb849 fftools/ffmpeg_mux: move OutputStream.enc_ctx to Encoder
The encoding AVCodecContext is a part of the encoder, and so should live
there.
2024-09-30 09:29:18 +02:00
Anton Khirnov
434377a764 fftools/ffmpeg_enc: split Encoder into a private and public part
Similar to what was previously done for other components, e.g. decoders
(see 3b84140a1b).

Start by moving {samples,frames}_encoded into the public struct.
2024-09-30 09:29:18 +02:00
Anton Khirnov
f295b4d8a0 fftools/ffmpeg_demux: drop ist_output_add()
It is now a trivial wrapper over ist_use(), so export that directly.
2024-09-30 09:29:18 +02:00
Anton Khirnov
8e805b9c3c fftools/ffmpeg_demux: drop InputStream.[nb_]outputs
It is write-only after d119ae2fd8.
2024-09-30 09:29:18 +02:00
Anton Khirnov
b97ccc537d fftools/ffplay: switch to new buffersink options 2024-09-30 09:14:04 +02:00
Anton Khirnov
577708a70a fftools/ffplay: stop using avfilter_graph_create_filter() incorrectly
This function creates AND initializes a filter, so setting any filter
options after it is wrong. It happens to work when the filter's init
function does not touch the options in question, but is forbidden by the
API and is not guaranteed to remain functional.

Instead, use avfilter_graph_alloc_filter(), followed by setting the
options, and avfilter_init_dict().
2024-09-28 17:04:33 +02:00
Anton Khirnov
53c71777e1 fftools/ffmpeg_filter: stop using avfilter_graph_create_filter() incorrectly
This function creates AND initializes a filter, so setting any filter
options after it is wrong. It happens to work when the filter's init
function does not touch the options in question, but is forbidden by the
API and is not guaranteed to remain functional.

Instead, use avfilter_graph_alloc_filter(), followed by setting the
options, and avfilter_init_dict().
2024-09-28 17:04:33 +02:00
Anton Khirnov
d103b61cd8 fftools/ffmpeg_filter: remove remaining OutputStream usage in init_simple_filtergraph()
With this, nothing in ffmpeg_filter acesses OutputStream anymore, thus
there are no more direct ties between filtering and muxing.

Rename init_simple_filtergraph() to fg_create_simple() for consistency.
2024-09-26 18:29:40 +02:00
Anton Khirnov
72cd0c20da fftools/ffmpeg_filter: drop the OutputStream parameter to ofilter_bind_ost()
It is no longer used for anything besides a sanity-checking assert.
Rename the function to ofilter_bind_enc(), as it no longer has any
assumptions about the target being an output stream.
2024-09-26 18:29:40 +02:00
Anton Khirnov
addc29f67a fftools/ffmpeg_filter: stop accessing OutputStream.[max_]frame_rate
Pass them to ofilter_bind_ost() via OutputFilterOptions, as is done for
most other data it needs. OutputStream.[max_]frame_rate/force_fps are no
longer used outside of ffmpeg_mux*, and so can be made private.

This is a step toward decoupling encoders from muxers.
2024-09-26 18:29:40 +02:00
Anton Khirnov
ac578ccb8e fftools/ffmpeg_filter: drop a redundant check
OutputFilterOptions.frame_rates are always NULL if the conditional is
true.
2024-09-26 18:29:40 +02:00
Anton Khirnov
cefc7d1ff4 fftools/ffmpeg_filter: clarify error message 2024-09-26 18:29:38 +02:00
Anton Khirnov
e3e66b14af fftools/ffmpeg_enc: don't write frame rate/SAR to AVStream directly
Have the muxer code read them out of the encoder context in
of_stream_init() instead.

This is a step towards decoupling encoders from muxers.
2024-09-26 18:25:21 +02:00
Anton Khirnov
7f7fe2a10b fftools/ffmpeg_enc: move set_encoder_id() to ffmpeg_mux_init
This code uses no encoder properties or state besides its name, and is
mostly muxer logic, and thus belongs more properly into the muxer.

The results of several test change due to different metadata tag order
(the "encoder" tag is now set first).
2024-09-26 18:25:21 +02:00
Anton Khirnov
6525fe4e77 fftools/ffmpeg_enc: remove unnecessary pointer references from enc_open() 2024-09-26 18:25:21 +02:00
Anton Khirnov
78038d51c5 fftools/ffmpeg_enc: do not set output stream codec parameters directly
Have the muxer code read them out of the encoder context in
of_stream_init() instead.

OutputStream.par_in no longer needs to be public, so can be moved to
MuxStream.

This is a step towards decoupling encoders from muxers.
2024-09-26 18:25:21 +02:00
Anton Khirnov
238f439992 fftools/ffmpeg_enc: do not set AVStream timebase directly
Instead, pass the encoder context to of_stream_init() and have the muxer
take the timebase from there. Note that the muxer can currently access
the codec context directly, but that will change in future commits.

This is a step towards decoupling encoders from muxers.
2024-09-26 18:25:21 +02:00
Anton Khirnov
1ebd521a4e fftools/ffmpeg_enc: stop using OutputStream in hw_device_setup_for_encode()
The only variable accessed from it is AVCodecContext, which we can
pass directly.

Also, this function currently logs into the AVCodecContext, which is
wrong. Log to Encoder instead.
2024-09-26 18:25:21 +02:00
Anton Khirnov
70f7bbeade fftools/ffmpeg_enc: add an AVClass to Encoder
Log decoder messages to the encoder rather than OutputStream.

This is a step towards decoupling encoders from muxers, similarly to
what was previously done to decoders and demuxers.
2024-09-26 18:25:21 +02:00
Anton Khirnov
da420ac6e1 fftools/ffmpeg: add support for multiview video
This extends the syntax for specifying input streams in -map and complex
filtergraph labels, to allow selecting a view by view ID, index, or
position. The corresponding decoder is then set up to decode the
appropriate view and send frames for that view to the correct
filtergraph input(s).
2024-09-23 17:15:02 +02:00
Anton Khirnov
68c198fae2 fftools/ffmpeg_sched: allow decoders to have multiple outputs
Will be useful for multilayer video.
2024-09-23 17:15:02 +02:00
Anton Khirnov
6940a6de2f lavu/frame: add side data storing view ID for multi-view video 2024-09-23 17:11:38 +02:00
James Almer
a48eba0021 fftools/ffmpeg_filter: ensure that the inserted filters exist
If not, report it as a bug. avfilter_graph_create_filter() will return ENOMEM if the
passed filter argument is NULL, which is misleading.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-09-23 09:02:23 -03:00
Gyan Doshi
0d5b68c27c ffmpeg_mux_init: correct log suggestion
The option is enc_time_base, not enc_timebase
2024-09-19 15:35:15 +05:30
Anton Khirnov
0c9fe2b232 fftools/cmdutils: extend stream specifiers to match by disposition 2024-09-18 11:01:02 +02:00
Anton Khirnov
00f5a34c9a fftools/cmdutils: tighten condition for media type stream specifiers
Require the character indicating media type to be followed by a
non-alphanumeric character (or end of string).

Needed by future syntax extensions.
2024-09-15 22:21:17 +02:00
Marvin Scholz
dd002f1588 fftools/ffmpeg_demux: narrow variable scope 2024-09-13 19:41:23 +02:00
Marvin Scholz
3ebc68d25d fftools/ffmpeg_mux_init: fix variable shadowing 2024-09-13 19:38:40 +02:00
Marvin Scholz
25f0fff9ec fftools/ffmpeg_demux: fix variable shadowing 2024-09-13 19:37:40 +02:00
Marvin Scholz
bb91425eb8 fftools/ffmpeg_mux_init: remove unused variable
This dict is declared and freed but nothing is ever written to it.
2024-09-13 00:31:19 +02:00
Marvin Scholz
4c6d07dd28 fftools/cmdutils: fix variable shadowing 2024-09-13 00:20:12 +02:00
Marvin Scholz
990b80c004 fftools/ffmpeg_opt: fix variable shadowing 2024-09-13 00:17:53 +02:00
Marvin Scholz
504c1ffcd8 fftools/ffmpeg: remove useless error check
When ret is checked here, it was never assigned anything, making this
check useless, as highlighted by Coverity.

It seems to be a copy paste mistake given that opt_match_per_stream_str
does not return an error code that could be checked and the previous
value assigned to ret is already checked above. So just remove this
check.

Fixes: CID1616292
2024-09-12 05:11:14 +02:00
Lynne
1709f3830e
fftools/opt_common: add missing newline after printing codecs
This fixes
ffmpeg -help bsf=trace_headers =>

Supported codecs: av1 h264 hevc vvc mjpeg mpeg2video vp8 vp9<no newline>
2024-09-09 13:03:04 +02:00
Niklas Haas
8517ff2082 fftools/ffmpeg_filter: remove YUVJ hack
This is no longer needed, since we now correctly negotiate the required
range from the mjpeg encoder via avcodec_get_supported_config().

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2024-09-08 13:59:29 +02:00
Niklas Haas
a850f80e2c fftools/ffmpeg_filter: propagate codec yuv metadata to filters
To convert between color spaces/ranges, if needed by the codec
properties.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2024-09-08 13:59:29 +02:00
Niklas Haas
33d5a4ec4e fftools/ffmpeg_filter: switch to avcodec_get_supported_config()
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2024-09-08 13:59:29 +02:00
Anton Khirnov
f3e265c690 fftools/ffmpeg_mux_init: factor out binding filters to output streams 2024-09-08 13:59:29 +02:00
Niklas Haas
7d6cd13ccb fftools/ffmpeg_filter: simplify choose_pix_fmts
The only meaningful difference between choose_pix_fmts and the default
code was the inclusion of an extra branch for `keep_pix_fmt` being true.

However, in this case, we either:
1. Force the specific `ofp->format` that we inherited from
   ofilter_bind_ost, or if no format was set:
2. Print an empty format list

Both of these goals can be accomplished by simply moving the decision
logic to ofilter_bind_ost, to avoid setting any format list when
keep_pix_fmt is enabled. This is arguably cleaner as it moves format
selection logic to a single function. In the case of branch 1, nothing
else needs to be done as we already force the format provided in
ofp->format, if any is set. Add an assertion to verify this assumption
just in case.

(Side note: The "choose_*" family of functions are arguably misnomers,
as they should really be called "print_*" - their current behavior is to
print the relevant format lists to the `vf/af_format` filter arguments)

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-09-08 13:59:29 +02:00
Niklas Haas
7b0eca1e51 fftools/ffmpeg_mux_init: switch to avcodec_get_supported_config() 2024-09-08 13:59:29 +02:00
Niklas Haas
377652da19 fftools: drop unused/hacky macros
Having macros initialize local variables seems strange to me, and there
are no more current users of these macros. (The one that was commented
out was incorrect anyway, since the macro has changed in the meantime)
2024-09-08 13:59:29 +02:00
Niklas Haas
69b8405482 fftools/opt_common: switch to avcodec_get_supported_config()
While rewriting this macro, I decided to make it a bit more flexible so
it can work for all of the fields (including future fields) in a more
generic way, and to also print the channel layout using an AVBPrint to
avoid hard-coding the assumption that the length is less than 128
characters.
2024-09-08 13:59:29 +02:00
Nicolas Gaullier
ee9ae4e8ba fftools/ffmpeg: Fix honor -r output option with streamcopy
Fix "ost->st->avg_frame_rate = ost->frame_rate" in streamcopy_init()
being reset to input's frame rate a few lines below.
Note that in current code, there are some discrepancies amongst the
muxers. For example, avienc relies on time_base, so it is not affected
by this patch, whereas mxfenc and matroskaenc do use avg_frame_rate,
so this patch fixes -r being honored.

In the updated fate test, the input is (wrongly) probed as 50fps. With
this patch, the correct value (25fps) is successfully forced with -r.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2024-09-04 13:01:37 +02:00
Zhao Zhili
523189c744 fftools/ffplay: handle flip in display matrix
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-08-24 00:26:59 +08:00
Jan Garcia via ffmpeg-devel
598f541ba4 fftools/ffmpeg: show video stats in progress output without filters
Since ffmpeg 6.1 video stats are accidentally hidden from streamcopy progress output.
This patch re-enables video stats (like frames=) in the progress output.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2024-08-14 15:17:58 +02:00
Anton Khirnov
9e3b5b8a26 fftools/ffmpeg: switch -map parsing to new stream specifier API
Makes optional map handling less hacky, fixes combining optional maps
with metadata matching on tags/values containing the '?' character/

Forward errors from stream specifier parsing, previously the code would
ignore them.
2024-08-13 10:28:54 +02:00
Anton Khirnov
d1bdd89c2f fftools/ffmpeg: use new stream specifier API in opt_match_per_stream*()
Removes a lot of error checking code, as matching cannot fail.
2024-08-13 10:28:54 +02:00
Anton Khirnov
46cbe4ab5c fftools/cmdutils: split stream specifier parsing and matching
This approach has the major advantage that only parsing can fail (due to
a malformed specifier or memory allocation failure). Since parsing is
done generically, while matching is per-option, this will allow to
remove substantial amounts of error checking code in following commits.

The new code also explicitly allows stream specifiers to be followed by
additional characters, which should allow cleaner handling of optional
maps, i.e. -map <stream_specifier>?, which is currently implemented in a
hacky way that breaks when the stream specifier itself contains the '?'
character (this can happen when matching metadata). It will also allow
further extending the syntax, which will be useful in following commits.

This introduces some minor behaviour changes:
* Matching metadata tags now requires the ':' character in keys or
  values to be escaped. Previously it could not be present in keys, and
  would be used verbatim in values. The change is required in order to
  know where the value terminates.
* Multiple stream types in a single specifier are now rejected - such a
  specifier makes no sense.
* Non-existent stream group ID or index is now ignored with a warning
  rather than causing a failure. This is consistent with program
  handling and is required to make matching fail-free.
2024-08-13 10:28:54 +02:00
Anton Khirnov
e1b38680b7 fftools/cmdutils: put stream specifier handling back into cmdutils
Stream specifiers were originally designed exclusively for CLI use and
were not intended to be public API. Handling them in avformat places
major restrictions on how they are used. E.g. if ffmpeg CLI wishes to
override some stream parameters, it has to change the demuxer fields
(since avformat_match_stream_specifier() does not have access to
anything else). However, such fields are supposed to be read-only for
the caller.

Furthermore having this code in avformat restricts extending the
specifier syntax. An example of such an extension will be added in
following commits.
2024-08-13 10:28:54 +02:00