1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-11-23 21:54:53 +02:00
Commit Graph

12040 Commits

Author SHA1 Message Date
James Almer
b0159af6bc avfilter/f_metadata: use the return value of vsnprintf() to write the argument list
Should fix use-of-uninitialized-value under MSAN.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-22 09:47:18 -03:00
James Almer
a01dc3aa27 avfilter/x86/vf_colordetect: add missing preprocessor checks
Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-21 18:03:22 -03:00
James Almer
c62813a057 avfilter/x86/vf_colordetect: make the AVX512 functions run only on ICL targets or newer
For detect_range, the usage of vpbroadcast{b,w} requires the AVX512BW extension, and for
detect_alpha we don't want ZMM instructions downclocking old CPUs.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-21 17:25:28 -03:00
James Almer
550ec9b7e6 avfilter/version: bump version after vf_colordetect addition
Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-21 17:04:45 -03:00
James Almer
70fc4e5909 avfilter/x86/vf_colordetect_init: don't enable ASM functions on targets where it's known they will be slower
Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-21 16:58:51 -03:00
James Almer
fdca209f1f avfilter/x86/vf_colordetect: don't use rax to return a 32bit integer
Fixes compilation on x86_32 targets

Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-21 16:58:36 -03:00
James Almer
14f4478354 avfilter/x86/vf_colordetect: fix use of AVX512 instruction in AVX2 function on non Unix64 targets
Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-21 16:52:46 -03:00
Niklas Haas
8b647b3f8a avfilter/vf_colordetect: add x86 SIMD implementation
alphadetect8_full_c:                                  5658.2 ( 1.00x)
alphadetect8_full_avx2:                                215.1 (26.31x)
alphadetect8_full_avx512:                              133.5 (42.40x)
alphadetect8_limited_c:                               7391.5 ( 1.00x)
alphadetect8_limited_avx2:                             649.3 (11.38x)
alphadetect8_limited_avx512:                           330.5 (22.36x)
alphadetect16_full_c:                                 3027.4 ( 1.00x)
alphadetect16_full_avx2:                               209.4 (14.46x)
alphadetect16_full_avx512:                             141.4 (21.41x)
alphadetect16_limited_c:                              3880.9 ( 1.00x)
alphadetect16_limited_avx2:                            734.9 ( 5.28x)
alphadetect16_limited_avx512:                          349.2 (11.11x)
rangedetect8_c:                                       5854.2 ( 1.00x)
rangedetect8_avx2:                                     138.9 (42.15x)
rangedetect8_avx512:                                   106.2 (55.12x)
rangedetect16_c:                                      4122.0 ( 1.00x)
rangedetect16_avx2:                                    138.6 (29.74x)
rangedetect16_avx512:                                  104.1 (39.60x)
2025-07-21 18:10:25 +02:00
Niklas Haas
545f721b44 avfilter/vf_colordetect: add new color range detection filter
This filter can detect various properties about the image, including
whether or not there are out-of-range values, or whether the input appears
to use straight or premultiplied alpha.

Of course, these can only be heuristics, with "undetermined" as the base
case. While we can definitely prove the existence of full range or
straight alpha colors, we can never infer the opposite.
2025-07-21 18:10:25 +02:00
James Almer
722a2170e8 avfilter/vf_curves: don't add offsets to NULL pointers
Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-19 00:07:45 -03:00
Kacper Michajłow
6302ff1fd9 avfilter/vaf_spectrumsynth: don't use uninitialized variable as scale
scale was never initialized. av_tx_init() will use default scale if we
pass NULL.

Fixes: b3117f376d
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-07-19 00:36:25 +02:00
James Almer
85f2911891 avfilter/x86/vf_blackdetect: add missing preprocessor check
Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-18 15:17:02 -03:00
James Almer
ee4ff3f706 avfilter/x86/vf_blackdetect_init: don't enable the ASM functions on targets where it's known they will be slower
Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-18 13:05:44 -03:00
James Almer
f263192f0e avfilter/x86/vf_blackdetect: don't use rax to return a 32bit integer
Fixes compilation on x86_32.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-18 13:05:44 -03:00
Zhao Zhili
a218cafe4d avfilter/vf_blackdetect: Fix header guard
Fix fate-source failure.
2025-07-18 13:44:51 +02:00
Niklas Haas
75cd42c48a avfilter/vf_blackdetect: add AVX2 SIMD version
Requested by a user. Even with autovectorization enabled, the compiler
performs a quite poor job of optimizing this function, due to not being
able to take advantage of the pmaxub + pcmpeqb trick for counting the number
of pixels less than or equal-to a threshold.

blackdetect8_c:                                       4625.0 ( 1.00x)
blackdetect8_avx2:                                     155.1 (29.83x)
blackdetect16_c:                                      2529.4 ( 1.00x)
blackdetect16_avx2:                                    163.6 (15.46x)
2025-07-18 10:47:31 +02:00
Niklas Haas
bc8d06d541 avfilter/vf_thumbnail: unroll and use multiple histograms
This naive hist[p[x]]++ loop suffers badly when there are large regions of
identical values in the image, because of store-to-load forwarding delay.

Splitting up the histogram into four "parallel" histograms and processing
them one at a time speeds things up significantly, about 40% on my end.
2025-07-17 12:33:59 +02:00
Niklas Haas
e44a1aaeec avfilter/x86/scene_sad: add high bit depth AVX2/AVX512 version
Since psadbw only exists for 8-bits, we have to emulate it for 16-bit
inputs. The simplest sequence is to use a normal subtraction, which is safe
as long as the inputs do not exceed 32767 - so limit this implementation
to 15-bit inputs and below.

For 16-bit inputs, we could in theory instead use a pminw / pmaxw to ensure
the resulting difference does not overflow, but this is slower, and also
breaks the subsequent use of pmaddwd, so I opted to skip 16-bit SIMD for
now.

scene_sad10_c:                                      114175.6 ( 1.00x)
scene_sad10_avx2:                                     9617.7 (11.87x)
scene_sad10_avx512:                                   5208.8 (21.92x)
scene_sad12_c:                                      114537.8 ( 1.00x)
scene_sad12_avx2:                                     9614.0 (11.91x)
scene_sad12_avx512:                                   5186.3 (22.08x)
scene_sad14_c:                                      114113.9 ( 1.00x)
scene_sad14_avx2:                                     9612.9 (11.87x)
scene_sad14_avx512:                                   5186.0 (22.00x)
scene_sad15_c:                                      114108.9 ( 1.00x)
scene_sad15_avx2:                                     9612.3 (11.87x)
scene_sad15_avx512:                                   5186.4 (22.00x)
scene_sad16_c:                                      114136.0 ( 1.00x)
2025-07-17 12:26:06 +02:00
Niklas Haas
91f2d146d4 avfilter/x86/scene_sad: add AVX512 implementation
Trivial to add, but a lot faster (on my machine).

scene_sad8_c:                                       114476.4 ( 1.00x)
scene_sad8_sse2:                                      8644.3 (13.24x)
scene_sad8_avx2:                                      4520.1 (25.33x)
scene_sad8_avx512:                                    3153.0 (36.31x)
2025-07-17 12:26:06 +02:00
Niklas Haas
dc61b74c1d avfilter/scene_sad: pass true depth to ff_scene_sad_get_fn()
I need to be able to distinguish between 10/12/14 and 16 bit depths, for
overflow reasons.
2025-07-17 12:26:05 +02:00
Marton Balint
b24155cae1 avfilter/avfilter: add AVFilterGraph->max_buffered_frames to limit buffered frames
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-14 22:05:10 +02:00
Marton Balint
71468e85ae avfilter/framequeue: add support for limiting and tracking buffered frames in the queues
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-14 22:03:36 +02:00
Niklas Haas
0a5ae743ef avfilter/vf_thumbnail: switch to query_func2
Instead of enumerating a static list of planar formats to support, walk
through the format list and enable all supported formats.

As of writing, this generates the following format list:
- gbrap
- gbrap10le
- gbrap12le
- gbrap14le
- gbrap16le
- gbrp
- gbrp10le
- gbrp12le
- gbrp14le
- gbrp16le
- gbrp9le
- gray
- gray10le
- gray12le
- gray14le
- gray16le
- gray9le
- ya16le
- ya8
- yuv410p
- yuv411p
- yuv420p
- yuv420p10le
- yuv420p12le
- yuv420p14le
- yuv420p16le
- yuv420p9le
- yuv422p
- yuv422p10le
- yuv422p12le
- yuv422p14le
- yuv422p16le
- yuv422p9le
- yuv440p
- yuv440p10le
- yuv440p12le
- yuv444p
- yuv444p10le
- yuv444p12le
- yuv444p14le
- yuv444p16le
- yuv444p9le
- yuva420p
- yuva420p10le
- yuva420p16le
- yuva420p9le
- yuva422p
- yuva422p10le
- yuva422p12le
- yuva422p16le
- yuva422p9le
- yuva444p
- yuva444p10le
- yuva444p12le
- yuva444p16le
- yuva444p9le
- yuvj411p
- yuvj420p
- yuvj422p
- yuvj440p
- yuvj444p
2025-07-12 12:52:33 +02:00
Niklas Haas
cf18b280f0 avfilter/vf_thumbnail: support more planar formats
This adds support for high bit depth formats, as well as formats with fewer
than 3 planes. The implementation for HBD is the same as for 8 bit formats,
just right shifted to 8 bits.

It's worth pointing out that this also works for HDR formats (and even DV),
because the underlying implementation is just trying to minimize the histogram
difference. If anything, using a HDR format will result in a *more* accurate
detection, because HDR formats tend to be more perceptually uniform.
2025-07-12 12:52:33 +02:00
Jorge Estrada
cd91469114 avfilter/overlay_cuda: add timeline editing support
Enables timeline editing options for overlay_cuda similar to what overlay allows

Example overlaying an image on a video between 30 to 60 seconds:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i sample-video.mp4 -i sample-image.jpg
-filter_complex "[1:v]hwupload_cuda[image],[0:v]scale_npp=format=yuv420p[video],[video][image]overlay_cuda=enable='between(t,30,60)'"
-c:v h264_nvenc -c:a copy -y overlay-output-gpu.mp4

Signed-off-by: Jorge Estrada <jestrada.list@gmail.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2025-07-11 17:49:58 +02:00
Lidong Yan
a4a71b5e9d avfilter/asrc_sinc: fix leak in config_input()
In config_input(), fir_to_phase() allocates memory in h[longer], which
would leak if av_calloc() to s->coeffs failed. lpf() allocates memory
in h[0] and h[1], which would leak if fir_to_phase() failed. To fix
this leak, add av_free(h[longer]) in as cleanup code, and replace
return AVERROR* with goto cleanup to prevent from leaks.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-07-05 21:10:36 +02:00
Jorge Estrada
ad0a44028d avfilter: add pad_cuda filter
This patch adds the pad_cuda video filter. A filter similar to the existing pad filter but accelerated by CUDA.

The filter shares the same options as the software pad filter.

Example usage:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf "pad_cuda=w=iw+100:h=ih+100:x=-1:y=-1:color=red" out.mp4

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2025-07-04 01:32:27 +02:00
Marton Balint
af189e424b avfilter/f_select: port to activate
Multi-input or multi-output filters should use activate now.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-03 21:41:54 +02:00
Marton Balint
223c2b03da avfilter/buffersink: keep requesting frames if one activation of the graph does not provide one
A frame graph activation might not produce a frame in the requested sink, so
keep on requesting a frame there unless we encounter a filter activation with
buffersrc empty error.

This makes av_buffersink_get_frame(_flags) work according to its documentation
which claims that EAGAIN is only returned if additional frames must be inserted
into the graph.

Fate changes are because audio frames will have different sizes at segment
boundaries, but content is the same.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-03 21:41:54 +02:00
Marton Balint
d41bac1333 avfilter: signal an empty buffersrc with an explicit activate error code
No change in functionality.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-03 21:41:54 +02:00
Marton Balint
44546751db avfilter/avfilter: make filter_activate_default request frames on behalf of sinks
Sinks without an activate callback have no means to request frames in their
input, therefore the default activate callback should do it for them.

Fixes ticket #11624.
Fixes ticket #10988.
Fixes ticket #10990.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-03 21:41:54 +02:00
Marton Balint
4440e499ba avfilter/avfilter: always forward request frame in filter_activate_default
Even if all inputs are blocked an activate callback should request a frame on
some if its inputs if a frame is requested on any of its outputs.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-03 21:41:54 +02:00
Marton Balint
a736ac72bb avfilter/avfilter: fix forwarding EOF for simple API filters in filter_activate_default
EOF only need to be forwarded back if all outputs have reached EOF.

Fixes infinte loop with ffprobe -f lavfi -i "smptebars=d=1,select=n=2:e=1[out0][out1]"
Regression since d9e41ead82.

Fixes ticket #10959.
Fixes ticket #11366.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-03 21:41:53 +02:00
Marton Balint
29e696c9c0 avfilter/filters: simplify FF_FILTER_FORWARD_WANTED_ANY
The status check is unneeded because an outlink with a nonzero status should
always return 0 for ff_outlink_frame_wanted(). Also use unsigned for index
because nb_outputs is unsigned as well.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-03 21:41:53 +02:00
Marton Balint
f3b7aa6c22 avfilter: factorize requesting an input frame from multi output filters
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-07-03 21:41:53 +02:00
James Almer
dbe347f074 avfilter/vf_showinfo: add support for 3D Reference Displays Information side data
Signed-off-by: James Almer <jamrial@gmail.com>
2025-07-01 22:46:22 +02:00
Lidong Yan
a17596f55b avfilter/vf_lut3d: fix leak if allocate_3dlut failed
In parse_cinespace(), memory allocated in in_prelut[] and out_prelut[]
would leak if allocate_3dlut() failed. Replace return ret with goto end
to free memory before return error code.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-06-28 23:54:40 +02:00
Niklas Haas
f67ca10f2e avfilter/f_ebur128: properly propagate true peak
After 3b26b782ee, `ebur128->true_peak` was only set to the maximum of the
current "true peak per frame" values, when it should report the true peak for
the entire stream.

Fixes: 3b26b782ee
2025-06-24 12:12:37 +02:00
Timothee
c94a419e32 avfilter/codecview: Enable QP visualization for H.264
The codecviewfilter, when used with qp=1, did not display quantization parameter values for H.264 streams because the QP table extraction was restricted to MPEG-2 video.

This patch enables H.264 support by updating ff_qp_table_extractto accept AV_VIDEO_ENC_PARAMS_H264. This allows for correct QP overlay on H.264 video

Signed-off-by: Timothee <timothee.informatique@regaud-chapuy.fr>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-06-23 13:40:52 +02:00
James Almer
dbe94e1110 avfilter/x86/f_ebur128: replace AVX2 instruction with AVX equivalent
Using vpbroadcastq in an AVX function will result in SIGILL errors on pre
Haswell/Zen processors.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-06-22 09:31:44 -03:00
Marton Balint
32153fac84 avfilter/af_aresample: rework activate logic to follow the advised flow more strictly
This should prevent the possibility of audio data accumulating.

The commit also cleans up and simplifies the code a bit so all frame producers
(filter_frame(), flush_frame()) functions follow similar logic as
ff_inlink_consume_frame() for the return code.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-06-21 20:24:57 +02:00
Marton Balint
a21429e134 avfilter/af_aresample: make aresample return FFERROR_NOT_READY when no progress can be made
FF_FILTER_FORWARD_WANTED() already sets the ready status as needed.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-06-21 20:24:57 +02:00
Marton Balint
ffcdd2cdc1 avfilter/af_aresample: merge request_frame into activate function
No functional change.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-06-21 20:24:57 +02:00
Marton Balint
28a7b9c863 avfilter/split: consume all frames before forwarding inlink status
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-06-21 20:24:30 +02:00
Niklas Haas
daef348574 avfilter/x86/f_ebur128: implement AVX peak calculation
Stereo only, for simplicity. Slightly faster than the C code.
2025-06-21 17:28:39 +02:00
Niklas Haas
3b26b782ee avfilter/f_ebur128: move peak detection to reusable DSP function
True peak and sample peak share almost the same logic. Define this logic in
a separate function for reusability, and so we can write SIMD versions.
2025-06-21 17:21:58 +02:00
Niklas Haas
4c046517e7 avfilter/f_ebur128: move variable declarations to usage site
This is actually allowed by non-ancient versions of C.
2025-06-21 17:21:58 +02:00
Niklas Haas
f362bacd27 avfilter/f_ebur128: lift sample peak calculation out of main loop
This is substantially faster (~55%) than the transposed loop, and also
avoids an unnecessary macro.
2025-06-21 17:21:58 +02:00
Niklas Haas
229393d8dc avfilter/f_ebur128: move true peak calculation out of main loop
Easier to read, less convoluted, and ~30% faster. Most importantly, this
avoids repeating the redundant recalculation of the true peak on every
single sample, by moving the FIND_PEAK() loop out of the main loop. (Note
that FIND_PEAK() does not depend on the current sample index at all, so
there is no reason for it to ever be recomputed here)
2025-06-21 17:21:58 +02:00
Niklas Haas
a96175e76f avfilter/f_ebur128: remove pointless macro
This macro is not shortening the code nor aiding readability.
2025-06-21 17:21:58 +02:00