Commit graph

1802 commits

Author SHA1 Message Date
zhanghongyuan
02da2c46d2 fftools/opt_common: print encoder-specific capabilities in print_codec()
Add printing of AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
AV_CODEC_CAP_ENCODER_FLUSH, and AV_CODEC_CAP_ENCODER_RECON_FRAME
capabilities that were defined but not displayed.
2026-06-02 20:39:56 +00:00
Zhao Zhili
6f1de91492 fftools/ffmpeg_filter: free input filter channel layout
Fixes the LeakSanitizer failure in fate-dca-xll-coded. It was exposed
by c65c8f1f49.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-06-01 14:31:21 +00:00
Kacper Michajłow
d7c7ee4e2e avformat: add AV_STREAM_GROUP_PARAMS_DOLBY_VISION
This uses existing AVStreamGroupLayeredVideo.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-05-31 03:43:29 +00:00
Nicolas Gaullier
b79a7422f5 fftools/ffprobe: print downmix_info frame side data
Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
2026-05-25 00:55:19 +00:00
Nicolas Gaullier
6b401344e8 fftools/textformat: add support for decibel formatting
Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
2026-05-25 00:55:19 +00:00
Nicolas Gaullier
0099a5fbdd fftools/textformat: stop using char * as identifiers
Add an enum instead.
As a result, fix honor -byte_binary_prefix.
In value_string(), add support for float values (beyond seconds),
and allow unit to be null or empty.
Also remove unused variable unit_second_str in ffprobe.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
2026-05-25 00:55:19 +00:00
Niklas Haas
03dfac5630 fftools/ffmpeg_sched: allow throttling decoder outputs
This is a departure from the conventional idea of decoders always outputting
data as fast as possible. Instead, this allows decoders to be throttled in the
same way filter graphs can be.

This comes into play when e.g. a demuxer is feeding into two decoders, but
only one of the two decoders is actually currently needed (e.g. due to
A/V misalignment). In that case, what typically happens is that the unneeded
decoder alse decodes all frames, and then piles them up on the "buffersrc"
filter's downstream link (growing indefinitely).

Another issue this solves manifests when e.g. a single demuxer is feeding many
decoders that all try to feed frames to the same filter graph. In this case,
all decoders run as fast as posssible, leading to lock contention on the
filter graph input queue; resulting in (again) many frames piling up on the
buffersrc (or downstream filters) for the unneeded inputs that are not actually
the bottleneck, while the input that's actually undersatisfied can end up
starved for CPU time, possibly for long enough to exhaust memory limits. The
normal rate limiting fails to apply in this scenario because all decoders share
a single demuxer, and are hence rate-limited only by the demuxer speed; whereas
the demuxer is not choked because from the PoV of the scheduler, the filter
graph is simply not getting enough frames.

In a more general sense, there's a philosophical argument to be made here.
Since a decoder is typically also a decompressor, it produces more data than
it consumes. So, it a sense, it's acting like a type of producer also - in
the same way that a filter graph can produce more input that outputs.

Solve all of these issues by allowing decoders to be output-choked, which
gives the scheduler control over when decoders are allowed to output frames.
This does mean we have to add some sort of internal packet queue, because the
decoder thread may need to continue *accepting* upstream packets from the
demuxer (or else we risk stalling the demuxer), but defer the actual decoding
by placing them inside an internal "overflow" queue.

This effectively simulates a sort of "filter graph"-type semantics but
for the decoder queue.

This overflow logic is fairly self-contained inside `sch_dec_receive`, though
it is quite nontrivial. I have added as much documentation as is hopefully
needed to understand the logic.

Importantly, we cannot simply unlimit the decoder input thread queue because
the demuxer relies on backpressure from the decoder to rate limit itself. (Note
that demuxers may only be active if there is at least one downstream decoder
that is alse active, so we always have at least one decoder providing
backpressure)

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-05-23 08:41:12 +00:00
Niklas Haas
2b72d5243c fftools/ffmpeg_sched: drain incoming frames before blocking filters
When a filter is choked, but upstream threads are trying to write to its input,
this can result in the filter's input queue getting stuck. Normally, the
unchoke_downstream() logic would prevent this from happening, since the
filter would itself get unchoked as a result of upstream decoders receiving
pressure from the demuxer.

However, upcoming changes to this logic will require weakening this upstream
unchoking logic, so preventing the deadlock in a more elegant way helps with
making the code more robust.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-05-23 08:41:12 +00:00
Niklas Haas
95391352b5 fftools/thread_queue: add THREAD_QUEUE_FLAG_NO_BLOCK
Exactly what it says on the tin. There is some ambiguity as to whether this
should also prevent reading from *choked*, as opposed to empty queue, but
I think it makes sense to consider them equivalent, as I struggle to think
of a use case where it would be beneficial to allow draining a queue that
was explicitly choked by the upstream (to e.g. prevent further reads).

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-05-23 08:41:12 +00:00
Niklas Haas
321b0e36a3 fftools/thread_queue: add flags parameter to tq_receive()
I want to use this to allow a non-blocking use of this function.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-05-23 08:41:12 +00:00
Marton Balint
f48e5d4db4 fftools/ffmpeg_filter: rate control all filter graphs
It was never reliable to detect if a filtergraph have sources, because a filter
can act as a source only after some time, for example the loop filter.

So it is better to remove the source detection entirely and always give the
scheduler an oppurtunity to stop processing.

Fixes ticket #11604.

Signed-off-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-05-23 08:41:12 +00:00
Niklas Haas
6a563dab71 fftools/ffmpeg_sched: allow choosing nodes to unchoke
This level of granularity will help for the upcoming patch.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-05-23 08:41:12 +00:00
Niklas Haas
04888287b3 fftools/ffmpeg_sched: fix sch_stop() and schedule_update_locked() race
schedule_update_locked() is supposed to be a no-op when `sch->terminate`
is 1. However, there is a TOCTOU error here, where a different thread may
currently be executing schedule_update_locked(), having successfully passed
the sch->terminate check but without actually updating the choke status.

This does not matter for the current code, but will matter with the following
commit, where it creates the theoretical possibility of a race where sch_stop()
is trying to choke the demuxers (and unchoke the decoders) while
schedule_update_locked() is simultaneously trying to choke the decoders,
leading to a deadlock if the last decoder is left choked and unable to
propagate EOF downstream.

The cleanest solution is to just take the scheduler lock while updating the
choke status here. This ensures that any other schedule_update_locked() calls
will have completed.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-05-23 08:41:12 +00:00
Niklas Haas
0d123a3c23 fftools/ffmpeg_sched: use macros for schedule_update_locked() loops
Instead of awkwardly looping over the type, just split this up into
multiple loops. The loss in complexity seems worth the loss in conciseness
to me, and more importantly, this allows us to easily add more waiter types.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-05-23 08:41:12 +00:00
James Almer
a5822fca94 avformat/avformat: add a Track Reference Stream Group
Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-17 11:16:51 -03:00
James Almer
412aa48868 fftools/ffmpeg_mux_init: propagate the muxer request for fixed frame size
Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-16 13:55:23 -03:00
James Almer
8e162daf9a fftools:/ffmpeg_enc: honor the user request for fixed size frames
And set it also for non-variable frame size encoders.

FATE changes are the result of passing a frame_size to flac and wavenc
encoders, instead of letting them choose one.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-16 13:55:22 -03:00
jiangjie
8ffaead836 fftools/ffmpeg_filter: fix frame reference leak in fg_output_step
When clone_side_data() fails in fg_output_step(), the function returns
without calling av_frame_unref(frame), leaking the frame reference.
2026-05-13 14:09:06 +00:00
Marvin Scholz
7e045dfbfc ffprobe: implement printing IAMF frame side data 2026-05-13 15:19:11 +02:00
Yong Yu
9ab345b2d1 fftools/graph: Add missing include "libavutil/mem.h" for fftools/graph/graphprint.c
when HAVE_AV_CONFIG_H is defined, include libavutil/mem.h
is skipped in libavutil/common.h.
Need this header file to build successfully.
2026-05-07 22:00:38 +00:00
Michael Niedermayer
89e128224e fftools/ffmpeg_opt: fix mismatching negative maps
Fixes:  -f lavfi -i testsrc2=size=128x128:rate=1:d=1   -filter_complex '[0:v]scale=64:64[vout]'   -map '[vout]'   -map -0:v   -f null -
Previously  -0:v matched [vout] apparently

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-03 13:19:18 +00:00
depthfirst-dev[bot]
25a98586cc fftools/ffmpeg_opt: validate stream index in negative map handling
Negative -map processing iterates previously parsed stream map entries
and dereferences input_files[m->file_index]->ctx->streams[m->stream_index]
without validating that stream_index is in range.

A malformed earlier map can leave m->stream_index negative, which causes
an out-of-bounds read when a later negative map walks existing entries.
Check that stream_index is non-negative and below nb_streams before
calling stream_specifier_match().

*Vulnerability reported by Zhenpeng (Leo) Lin at depthfirst*
*Patch validated by Zheng Yu at depthfirst*

Fixes: DFVULN-695
2026-05-03 13:19:18 +00:00
zhanghongyuan
7e5eb2b65c fftools/opt_common: Use enum for encoder/decoder selection
Replace magic numbers (0 and 1) with SHOW_DECODER and SHOW_ENCODER
enum values throughout the opt_common.c file.
2026-05-01 23:37:55 +00:00
Marvin Scholz
afd3f01501 fftools: replace fall-through comments 2026-04-28 12:29:37 +00:00
Marvin Scholz
9e90fa505e fftools: ffprobe: fix type mismatch in assert
The enum is unsigned, so instead compare to -1 before assigning to
the unsigned type.
2026-04-27 14:31:02 +02:00
Marvin Scholz
0396831b04 fftools: ffprobe: use unsigned in print_list_fmt
Unsigned makes more sense in this context.
2026-04-27 14:31:02 +02:00
Marvin Scholz
92cbe0454f fftools: ffprobe: adjust type of nb_streams
There is no reason for this to be signed, it is never negative.
2026-04-27 14:31:02 +02:00
Marvin Scholz
7c254feb0a fftools: ffprobe: narrow variable scopes and adjust types
Prevents several integers of different sign comparison warnings.
2026-04-27 14:31:02 +02:00
Vignesh Venkat
c8dd769217 ffprobe: Support printing SMPTE 2094 APP5 side data
Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
2026-04-14 20:41:14 +00:00
Zhao Zhili
b796d72eb2 fftools/ffmpeg_filter: skip autoscale for hardware format
This fix failure:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda \
  -i The_Beauty_of_Earth-1.mp4 \
  -vf scale_cuda=2880:1440 \
  -c:v hevc_nvenc \
  -pix_fmt cuda \
  -b:v 8M -c:a copy \
  -y test_scale.mp4

> Reconfiguring filter graph because hwaccel changed
> Impossible to convert between the formats supported by the filter
> 'Parsed_scale_cuda_0' and the filter 'auto_scale_0'.
> Error reinitializing filters!

Signed-off-by: Zhao Zhili <quinkblack@foxmail.com>
2026-04-13 19:46:54 +08:00
nyanmisaka
107a309f3c fftools/ffmpeg_filter: fix the incomplete printing of reason for video filter graph reconfiguration
"Reconfiguring filter graph because video parameters changed to yuv420p10le(pc, bt709), 1920x1080, unspecified alph"

Fixup f07573f

Adding a missing space fixed this.
2026-03-29 09:34:23 +00:00
Ingo Oppermann
4bb2989cce fftools/ffmpeg_filter: remove duplicate assignment
Signed-off-by: Ingo Oppermann <ingo@datarhei.com>
2026-03-27 06:37:27 +00:00
Jeremy James
3d4461e16d fftools/ffprobe: Show stream group side data
Specifically output side data from tile groups with -show_stream_groups
which includes rotation information in HEIC images.

Signed-off-by: Jeremy James <jeremy.james@gmail.com>
2026-03-20 12:45:44 +00:00
James Almer
b50cbdc04f fftools/ffmpeg_demux: properly unnitialize the side_data_prefer_packet AVBprint buffer
Fixes Coverity issue CID 1689616.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-18 13:29:23 -03:00
James Almer
1d65e985b3 fftools/ffmpeg_demux: add options to override mastering display and content light level metadata
Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 17:52:05 -03:00
James Almer
539fc854e7 fftools/ffmpeg_mux_init: add support for LCEVC Stream Group muxing
Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-14 20:50:27 -03:00
Lynne
c102e89448 hwcontext_vulkan: deprecate AVVulkanDeviceContext.lock/unlock_queue
Without replacement, as VK_KHR_internally_synchronized_queues will be required.
2026-03-14 17:05:06 +00:00
Olivier Laflamme
10d36e5d3d fftools/ffprobe: Initialize data_dump_format_id
This was used uninitialized previously

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-13 01:19:39 +00:00
Nicolas Gaullier
b66c314c4b fftools/ffprobe: keep decoder buffers unflushed for show_streams()
When a decoder buffer is flushed, parts of the private context is reset,
which may affect show_streams().

Example:
ffprobe -of flat fate-suite/ac3/mp3ac325-4864-small.ts \
    -analyze_frames -show_entries stream=ltrt_cmixlev
Before: ltrt_cmixlev="0.000000"
After:  ltrt_cmixlev="0.707107"

Currently, it seems that only ac3 downmix info is concerned.
(ac3 downmix options are exported since 376bb8481a).

Fix regression since 045a8b15b1.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
2026-03-12 12:18:58 +00:00
Nicolas Gaullier
8a0ae6b344 fftools/ffmpeg_sched: report progress using max dts instead of trailing_dts()
This is to reapply 18217bb0f5.
Its commit msg is still meaningful:
"Using the max instead of the min avoids the progress stopping
with gaps in sparse streams (subtitles)."

Also on a very similar issue: currently, a single stream with
no data makes ffmpeg reports N/A for both time and speed.
Fix this by ignoring missing dtses.

Fix regressions since d119ae2fd8.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
2026-03-12 12:15:15 +00:00
Romain Beauxis
9dc44b43b2 fftools/ffplay.c: Also print demuxer-level metadata updates. 2026-03-12 02:45:13 +00:00
nyanmisaka
3f10a054dc fftools/ffmpeg: fix read_key() always return 255 when there was no input
fixup 08d327e

When an uchar is set to -1, it will become 255 when read as an int.
Duplicate variables for two terminal types can also avoid unused variable warnings.

Signed-off-by: nyanmisaka <nst799610810@gmail.com>
2026-03-09 16:13:18 +00:00
James Almer
c6057f4d96 fftools/ffmpeg_mux_init: don't autoselect video codecs known to lack decoders
They should not be given priority even in a stream copy scenario.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-07 19:21:44 -03:00
Michael Niedermayer
1e7d7c4f52
fftools/ffmpeg_demux: Check metadata provided filename
Fixes: path traversal with  -dump_attachment:t
Fixes: malicious.mkv

Based on code from libavformat/concatdec.c
This will be factored out possibly into libavutil once there is agreement on the API

Found-by: Shangzhi Xu <mxu490469@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-07 11:51:39 +01:00
Nicolas Gaullier
fe86fd07d3 fftools/ffprobe: do not show refs when not processing frames
refs does not belong to AVCodecParameters, so require a decoder:
it should only be showed when frames are actually processed by ffprobe.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
2026-03-05 13:49:59 +00:00
zhanghongyuan
e686f53424 fftools/ffplay: improve keyboard shortcut documentation
Clarify the behavior of seek keyboard shortcuts in both the
documentation and command-line help text. Specifically:
- left/right: mention custom interval option support
- page down/up: improve wording for chapter seeking fallback
2026-03-04 21:30:40 +00:00
Kacper Michajłow
4e32fb4c2a
fftools/cmdutils: constify string
Fixes:
warning: initializing 'char *' with an expression of type 'const char *'
discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-02-28 13:42:01 +01:00
Michael Niedermayer
0833dd3665 fftools/ffmpeg_opt: limit recursion of presets
Fixes: stack overflow

This should have limited security impact as it requires access to arbitrary
options.

Found-by: Zhenpeng (Leo) Lin from depthfirst
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-02-17 13:41:37 +00:00
Andreas Rheinhardt
bf44a683eb fftools/ffmpeg_mux_init: Improve type-safety
This makes fftools -fshort-enums compatible.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-02-10 16:36:58 +01:00
Niklas Haas
be88553fc8 fftools/ffmpeg_demux: mirror DemuxStream name to AVFormatContext
Results in basically the same name, except less ambiguous because
it includes the input index.
2026-02-09 14:01:14 +00:00