282 Commits

Author SHA1 Message Date
79e2a845cd Revert "fftools/graphprint: Now, make it a Killer-Feature!"
This reverts commit 1f2b8d7238eff4ab8a4d8d6177e250b8180d51f4.
2025-05-16 10:37:29 +02:00
1f2b8d7238 fftools/graphprint: Now, make it a Killer-Feature!
remember this: -sg   <= means Show Graph

Signed-off-by: softworkz <softworkz@hotmail.com>
2025-05-15 23:11:08 +02:00
45926bc09a fftools/graphprint: Add execution graph printing
The key benefits are:

- Different to other graph printing methods, this is outputting:
  - all graphs with runtime state
    (including auto-inserted filters)
  - each graph with its inputs and outputs
  - all filters with their in- and output pads
  - all connections between all input- and output pads
  - for each connection:
    - the runtime-negotiated format and media type
    - the hw context
    - if video hw context, both: hw pixfmt + sw pixfmt
- Output can either be printed to stdout or written to specified file
- Output is machine-readable
- Use the same output implementation as ffprobe, supporting multiple
  formats

Signed-off-by: softworkz <softworkz@hotmail.com>
2025-05-15 23:09:17 +02:00
34bb7f5d87 fftools/ffmpeg_filter: Move some declaration to new header file
to allow filtergraph printing to access the information.

Signed-off-by: softworkz <softworkz@hotmail.com>
2025-05-15 23:04:44 +02:00
8b2372cac7 ffmpeg-filter: check for initialized graph
Don't drop frame if graph hasn't been initialized yet!
2025-03-25 01:06:03 +05:30
fee5b0a383 fftools/ffmpeg_filter: ensure ifp is set before dereferencing it
Fixes segfaults since cbbc927a67f142a02bfc5d047c03587599ee5b55.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-03-24 10:10:19 -03:00
cbbc927a67 ffmpeg: add per-stream input option drop_changed
This is a replacement in ffmpeg for the deprecated avcodec flag AV_CODEC_FLAG_DROPCHANGED.

This option is meant to be used when the filtergraph should not be
reinited upon input parameter changes as that leads to loss of state
in the filtergraph potentially leading to broken or aborted output,
e.g. inserting of silence with first_pts specified in aresample.

Generally useful to avoid corrupted yet decodable packets in live
streaming inputs.

This option when enabled takes precedence over reinit_filters
2025-03-24 16:18:17 +05:30
a6c58450da all: Fix doxy comments wrongly designated as trailing ///<
The ///< or /**< form of doxygen comments are only to be used
when the documentation follows the member and the comment
block starts on the same line as the member. This commit
fixes wrong uses of them; in particular, this fixes the comment
for mb_height in H.264 SPS's structure which was wrongly added
to mb_width.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-12 17:00:24 +01:00
01f63ef0b4 fftools/ffmpeg_filter: also remove display matrix side data from buffered frames
Some frames may be buffered before a complex filtergraph can be configured.
This change ensures the side data removal in the cases where autorotation is
enabled also applies to them.

Fixes ticket #11487

Signed-off-by: James Almer <jamrial@gmail.com>
2025-03-03 18:10:10 -03:00
0e7c2a6287 fftools/ffmpeg: use an int for nb_threads
Removes unnecessary allocations.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-02-17 09:40:13 -03:00
f632ab53d9 fftools/ffmpeg_filter: remove accidental variable shadowing
Fixes potential uses of uninitialized variables in case of alloc failure.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-01-26 20:53:11 -03:00
4f9afbb1b2 fftools/ffmpeg_filter: reinitialize the filterchain if downmix metadata changed between frames
Signed-off-by: James Almer <jamrial@gmail.com>
2025-01-25 21:56:49 -03:00
e61b9d4094 fftools/ffmpeg: propagate decoded_side_data from decoded streams to the filterchain
Global side data as exported by a decoder may no longer apply if a filter in
the chain altered the frames in some form, like changing color, dimensions,
or channel layout information.
After this change, any such changes in side data will be taken into account by
the encoder futher in the process.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-01-25 21:56:49 -03:00
e79ac9312f fftools/ffmpeg_filter: use proper logging contexts 2024-10-17 10:56:30 +02:00
9e2a231236 fftools/ffmpeg_filter: treat apad filter as a source
Ideally lavfi should have a dedicated API for detecting this.

Fixes #11168 and #11061
2024-10-15 10:38:48 +02:00
0f5592cfc7 fftools/ffmpeg: supply hw device context to probe-filtergraphs
I.e. those that are only used to figure out input/output counts, since
some filters might expect a valid hw device in init and refuse to
initalize otherwise.

This requires complex filtergraphs to be created in a separate step
after parsing global options, after all hw devices are guaranteed to
exist.
2024-10-10 09:09:29 +02:00
84c2ca6fa0 fftools/ffmpeg_filter: do not leak graph_desc on fg_create() failure
fg_create() is passed a malloced string and assumed to always take
ownership of it.
2024-10-10 09:09:29 +02:00
496b8d7a13 fftools/ffmpeg_filter: stop setting a no-op option 2024-10-07 10:53:13 +02:00
f25c9cc213 fftools: log unconnected filter output label 2024-10-04 14:27:20 +02:00
5beeb3a1f9 fftools: do not access out of bounds filtergraph
The log message was logged for `filtergraphs[j]` which would cause a
heap buffer overflow in certain circumstances.

Correctly it should be logged for the current filtergraph, so just
use `fg` here.
2024-10-04 14:27:20 +02:00
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
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
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
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
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
cefc7d1ff4 fftools/ffmpeg_filter: clarify error message 2024-09-26 18:29:38 +02:00
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
68c198fae2 fftools/ffmpeg_sched: allow decoders to have multiple outputs
Will be useful for multilayer video.
2024-09-23 17:15:02 +02:00
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
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
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
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
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
2ff7d10c30 fftools/ffmpeg_filter: use the correct specifier for crop arguments
Signed-off-by: James Almer <jamrial@gmail.com>
2024-07-18 23:27:20 -03:00
bf87688a9f fftools/ffmpeg: support applying container level cropping
Signed-off-by: James Almer <jamrial@gmail.com>
2024-07-08 13:30:24 -03:00
62929f40ee fftools/ffmpeg_filter: Fix leak on error
Do this by attaching the FilterGraph directly to more permanent
storage from which it will be automatically freed.
Fixes Coverity issue #1596533.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-20 14:15:23 +02:00
4c8a6631ad fftools/ffmpeg_filter: Fix check
Fixes Coverity issues #1596529, #1596531.
Introduced in 8e35e33d42efb89ff7e3da92b841a3b43a5a95bc.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-27 17:00:12 +02:00
3bd7c57125 fftools/ffmpeg_filter: implement filtergraph chaining
This allows one complex filtergraph's output to be sent as input to
another one, which is useful in certain situations (one is described in
the docs).

Chaining filtergraphs was already effectively possible by using a
wrapped_avframe encoder connected to a loopback decoder, but it is ugly,
non-obvious and inefficient.
2024-04-09 10:34:18 +02:00
3d01996b24 fftools/ffmpeg_filter: change processing order in fg_finalise_bindings()
First bind all inputs in all filtergraphs, only then check that all
outputs are bound.

Needed by the following commit.
2024-04-09 10:34:18 +02:00
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
d74cbcb963 fftools/ffmpeg_filter: drop OutputFilter.ost
All remaining code accessing it only needs to know whether this
filtergraph output has been bound or not.
2024-04-09 10:34:18 +02:00
f2c919252d fftools/ffmpeg_filter: accept encoder thread count through OutputFilterOptions
Stop digging through encoder options manually.

Will allow decoupling filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
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
a2892dbe06 fftools/ffmpeg_filter: pass trim parameters 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
83304f7c1f fftools/ffmpeg_filter: pass autoscale 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
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
23c23077fc fftools/ffmpeg_filter: drop an unnecessary use of OutputStream
OutputFilter.type contains the same information.
2024-04-09 10:34:18 +02:00
fc6354c39c fftools/ffmpeg_filter: add an AVClass to OutputFilter
Use it for logging where appropriate, avoid logging to OutputStream as
we do not own it.

This is a step towards decoupling filtering from encoding.
2024-04-09 10:34:18 +02:00
3c3e04c8a3 fftools/ffmpeg_filter: simplify retrieving filter type 2024-04-09 10:34:18 +02:00
114cbaa316 fftools/ffmpeg_filter: drop a redundant check
fg_finalise_bindings() already checks that all filtergraph outputs are
connected.
2024-04-09 10:34:18 +02:00