12340 Commits

Author SHA1 Message Date
realies
c6c11b0b6d avfilter/af_loudnorm: fix limiter buffer over-allocation
The limiter_buf was being allocated with buf_size (3000ms worth of
samples) instead of limiter_buf_size (210ms worth of samples).

This resulted in allocating approximately 14x more memory than needed
for the limiter buffer. At 192kHz stereo:
- buf_size: 1,152,000 samples = 9.2 MB
- limiter_buf_size: 80,640 samples = 0.6 MB
- Wasted: ~8.2 MB per filter instance

The bug was introduced when the limiter buffer was added but the
wrong size variable was used in av_malloc_array().
2026-01-20 20:24:36 +00:00
Lynne
8dcf02ac63 vulkan: remove IS_WITHIN macro
This is the more correct GLSL solution.
2026-01-19 16:37:15 +01:00
Dmitrii Ovchinnikov
6972b127de avfilter: Add vsrc_amf - AMF based screen capture
This patch adds screen capture support via AMF vsrc_amf:
ffmpeg -y \
    -filter_complex "vsrc_amf=framerate=120:capture_mode=keep_framerate" \
    -c:v hevc_amf \
    -frames:v 300 \
    output_grab.mp4

If the HW frames pool is insufficient,
increase extra_hw_frames in filter_complex.
2026-01-19 10:16:37 +00:00
niyinghao
a5091f6d66 avfilter/formats: add type-safe functions for AVSampleFormat/AVPixelFormat lists
This avoids undefined behavior when -fshort-enums is enabled, where accessing enum arrays through int pointers causes incorrect memory reads.

Signed-off-by: niyinghao <niyinghao@xiaomi.com>
2026-01-19 09:33:49 +00:00
Raja Rathour
408dbf3c74 avfilter/vf_blackframe: add slice threading using stdatomic
Signed-off-by: Raja Rathour <imraja729@gmail.com>
2026-01-15 16:26:09 +00:00
Michael Niedermayer
805931dfc8 avfilter/scale_eval: Avoid undefined behavior with double to int cast
We use INT32_MIN/MAX so as to ensure we dont have to deal with 64bit width or height
on a int is int64 system. int64 width would overflow in a system where we assume the product of 2
values fit in int64

Fixes: #YWH-PGM40646-14
Found-by: An0n99X
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-01-13 22:25:53 +00:00
Michael Niedermayer
5bbc8f828e avfilter/scale_eval: Use 64bit for factor_w/h
Avoids truncation and overflows

Fixes: #YWH-PGM40646-14
Found-by: An0n99X
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-01-13 22:25:53 +00:00
Lynne
80229c161b scale_vulkan: use compile-time SPIR-V generation for debayering 2026-01-12 17:28:43 +01:00
Lynne
f3b0ca4f2c avgblur_vulkan: generate SPIR-V during compilation 2026-01-12 17:28:42 +01:00
Lynne
a6391168f2 bwdif_vulkan: use compile-time SPIR-V 2026-01-12 17:28:42 +01:00
Lynne
dd69ebc9a8 vulkan_filter: don't use lg_size[2] as the number of workgroup.z
This was put there because who knows why, but it's wrong, this
ends up having double dispatches in the z direction if non-1.
2026-01-12 17:28:41 +01:00
Lynne
7ce22b085e cuda/load_helper: move zlib decompression into a separate file
Allows it to be reused for Vulkan
2026-01-12 17:28:41 +01:00
Lynne
5996a9ad3d configure: rename PTX_COMPRESSION to SHADER_COMPRESSION
Its useful for GLSL and Metal as well.
2026-01-12 17:28:40 +01:00
Lynne
f2affdfafb configure/make: support compile-time SPIR-V generation 2026-01-12 17:28:40 +01:00
Michael Niedermayer
f99df7dbb3 avfilter/vf_find_rect: Fix handling odd sized images
Fixes: out of array read
Fixes: #YWH-PGM40646-17

Found-by: An0n99X
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-01-12 02:05:11 +00:00
Raja Rathour
06d799ce1a avfilter/dnn_backend_torch: handle lifecycle of worker thread
Initialize async resources in dnn_load_model_th and ensure proper cleanup and thread joining in dnn_free_model_th.

Signed-off-by: Raja Rathour <imraja729@gmail.com>
Reviewed-by: Wenbin Chen <wenbin.chen@intel.com>
Reviewed-by: Guo Yejun <yejun.guo@intel.com>
2026-01-12 08:53:42 +08:00
Raja Rathour
5e8ad5c39b avfilter/dnn_backend_torch: implement async execution logic
Update execute_model_th to support asynchronous execution by pushing tasks to the pending queue and notifying the worker thread.

Signed-off-by: Raja Rathour <imraja729@gmail.com>
Reviewed-by: Wenbin Chen <wenbin.chen@intel.com>
Reviewed-by: Guo Yejun <yejun.guo@intel.com>
2026-01-12 08:53:42 +08:00
Raja Rathour
910270b179 avfilter/dnn_backend_torch: add async infrastructure
Add worker thread, mutex, and condition variable to THModel.

Signed-off-by: Raja Rathour <imraja729@gmail.com>
Reviewed-by: Wenbin Chen <wenbin.chen@intel.com>
Reviewed-by: Guo Yejun <yejun.guo@intel.com>
2026-01-12 08:53:42 +08:00
James Almer
af136db1c3 avfilter/vf_lcevc: attach a reference to the source frame to each passed in base picture
And free them once they are guaranteed to be no longer needed, instead of freeing them
when returned with an enhanced output.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-01-11 17:59:15 -03:00
Jun Zhao
91ae6d10ab lavfi/nlmeans: add aarch64 neon for compute_weights_line
Implement NEON optimization for compute_weights_line.

Also update the function signature to use ptrdiff_t for stack arguments
(max_meaningful_diff, startx, endx). This is done to unify the stack
layout between Apple platforms (which pack 32-bit stack arguments tightly)
and the generic AAPCS64 ABI (which requires 8-byte stack slots for 32-bit
arguments). Using ptrdiff_t ensures 8-byte slots are used on all AArch64
platforms, avoiding ABI mismatches with the assembly implementation.

The x86 AVX2 prototype is updated to match the new signature.

Performance benchmark (AArch64) in MacOS M4:
./tests/checkasm/checkasm --test=vf_nlmeans --bench
compute_weights_line_c:     151.1 ( 1.00x)
compute_weights_line_neon:  62.6 ( 2.42x)

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2026-01-09 16:10:10 +00:00
Nicolas Gaullier
931b26528c avfilter/src_movie: fix support multiple frames per packet
Do not output more than one frame in one activate callback, though.

Fixes #20827.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
2026-01-05 20:41:59 +00:00
Ayose
120987543a avfilter/tests/drawvg: fix warnings on WIN32
The compiler was emitting a warning on every Cairo function replaced by
the `MOCK_FN_n` macros:

    warning: 'cairo_...': redeclared without dllimport attribute after
    being referenced with dll linkage

The macro `CAIRO_WIN32_STATIC_BUILD` prevents the attribute `dllimport` on
the declarations for these functions.

Signed-off-by: Ayose <ayosec@gmail.com>
2026-01-04 13:42:20 +00:00
Ayose
c7a2646bc7 avfilter/vf_drawvg: values from the p() function can be used as colors.
To be able to reuse colors from the original frame, the last value returned by
`p()` is tracked in the eval state, and if it is assigned to a variable, the
original color components are copied to `color_vars`. Thus, commands like
`setcolor` and `colorstop` can use those variables:

    setvar pixel (p(0, 0))
    ...
    setcolor pixel

`fate-filter-drawvg-video` now also verifies the `p()` function.

Signed-off-by: Ayose <ayosec@gmail.com>
2026-01-04 13:42:20 +00:00
Ayose
46c9584dc5 avfilter/vf_drawvg: support color expressions as setvar/call arguments.
The arguments for `setvar` and `call` commands can be colors (like `#rrggbb`).
This replaces the previous trick of using `0xRRGGBBAA` values to use colors as
procedure arguments.

The parser stores colors as the value expected by Cairo (a `double[4]`). This
array is allocated on the heap so the size of the union in `VGSArgument` is
not increased (i.e. it is still 8 bytes, instead of 32).

Signed-off-by: Ayose <ayosec@gmail.com>
2026-01-04 13:42:20 +00:00
Ayose
6300e340d3 avfilter/vf_drawvg: skip conversions when a color is assigned to a variable.
In libcairo, colors are defined as 4 separate components, and each one is double
between 0 and 1. Before this commit, colors stored in variables (like `defhsla`)
were converted to a `0xRRGGBBAA` value, which introduced some issues due to
rounding errors.

Now, when a color is assigned to a variable, the original values (a `double[4]`)
are stored in a dedicated array (`color_vars`), so no conversion is needed.

This change also reduces the cost of reading a color from a variable (no need
for `av_be2ne32`, or the `color[i] / 255` operations).

Signed-off-by: Ayose <ayosec@gmail.com>
2026-01-04 13:42:20 +00:00
James Almer
4fad136704 avfilter/vf_stack: add checks for the final canvas dimensions
Prevents potential integer overflows when trying to stitch absurdly huge images together.

Fixes #YWH-PGM40646-38.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-01-03 21:31:30 -03:00
Zhao Zhili
85b5927083 avfilter/vf_libopencv: fix null pointer dereference
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-01-02 23:46:42 +08:00
Zhao Zhili
35eebc5045 avfilter/vf_libopencv: use av_unreachable
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-01-02 23:46:19 +08:00
Zhao Zhili
4d46eeed02 avfilter/vf_libopencv: fix memleak
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-01-02 23:45:52 +08:00
Lynne
9ab3e962b4 nlmeans_vulkan: use ff_vk_buf_barrier() 2025-12-31 15:00:46 +01:00
Kacper Michajłow
20ac8c3688 avfilter/vulkan_filter: fix logic error when checking for encode support
Both FF_VK_EXT_VIDEO_ENCODE_QUEUE and FF_VK_EXT_VIDEO_MAINTENANCE_1 are
required, not only one of them.

Found by VVL.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-12-31 10:30:36 +00:00
nikitalita
0629780cf6 avfilter/vf_libplacebo: replace preproc directive in function-like macros
MSVC build was failing due to preprocessor directives being used within function-like macro argument lists, which is undefined behavior according to the C11 spec. Fixed by replacing the directive blocks with macro definitions outside of the macro invocations.
2025-12-27 18:13:13 +00:00
Andreas Rheinhardt
26a7fc2ac4 avfilter/vf_waveform: Avoid relocations
Reviewed-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-23 11:02:04 +01:00
Andreas Rheinhardt
6460d3bc81 avfilter/vf_waveform: don't cast const away
Reviewed-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-23 11:01:42 +01:00
Araz Iusubov
4479d28103 avcodec/avfilter_amf: correct handling of AMF errors
Fix several AMF-related issues.

Check the return value of amf_init_frames_context() correctly in amfdec,
as it returns int rather than AMF_RESULT.

Handle possible NULL surfaces returned from QueryInterface() in
vf_amf_common to avoid passing invalid data to amf_amfsurface_to_avframe().

Remove FILTER_SINGLE_PIXFMT from vf_sr_amf since it must not be used
together with a query formats function.
2025-12-22 14:58:59 +00:00
Rémi Denis-Courmont
7ee5c907e5 lavfi/vf_blackdetect: R-V V count_pixels_16
SpacemiT X60:
blackdetect16_c:                                      7171.0 ( 1.00x)
blackdetect16_rvv_i32:                                 383.6 (18.69x)
2025-12-16 17:30:29 +02:00
Rémi Denis-Courmont
570908af09 lavfi/vf_blackdetect: R-V V count_pixels_8
SpacemiT X60:
blackdetect8_c:                                      14911.0 ( 1.00x)
blackdetect8_rvv_i32:                                  369.5 (40.35x)
2025-12-16 17:30:23 +02:00
Niklas Haas
4ac3b3a6da avfilter/vf_libplacebo: rotate all input frames, not just reference
In commit 6e0034ab7e, the image crop adjustment
was moved after the fitting logic. However, this moved the adjustment inside the
`if (src == ref)` branch, thus missing applying the same un-rotation to input
frames that are *not* the reference frame.

Fix this by pulling the logic back out of the branch again. While we could just
move it after the fitting logic, I think it's more clear to the intent of the
code to just preserve the (rotated) crop rect as a separate variable
`crop_orig`.

Fixes: 6e0034ab7e
2025-12-15 11:29:58 +01:00
Gyan Doshi
b89f1581b0 lavfi/sidedata: fix typo
S12M_TIMECOD --> S12M_TIMECODE

Old version is marked deprecated.
Should be removed at lavfi bump to 12.
2025-12-14 12:41:00 +05:30
Ruikai Peng
cc43670268 avfilter/x86/vf_noise: Use unaligned access
Regression since: 3ba570de8b (port from MMX to SSE2).

The SSE2 inline asm in libavfilter/x86/vf_noise.c (line_noise_sse2 and
line_noise_avg_sse2) uses aligned loads/stores (movdqa, movntdq) but never
checks pointer alignment. When the filter reuses an input frame (common
path when av_frame_is_writable() is true), it may receive misaligned data
from upstream filters that adjust frame->data[i] in place, notably vf_crop:

- vf_crop adjusts plane pointers by arbitrary byte offsets
(frame->data[plane] += ...), so an x offset of 1 on 8-bit formats produces
a 1‑byte misalignment.
- The noise filter then calls the SSE2 path directly on those pointers
without realigning or falling back.

Repro on x86_64/SSE2 (current HEAD at that commit):

./ffmpeg -v error -f lavfi -i testsrc=s=320x240:rate=1 \
-vf "format=yuv420p,crop=w=319:x=1:h=240:exact=1,noise=alls=50" \
-frames:v 1 -f null -

This crashes with SIGSEGV at the aligned load in line_noise_sse2 (movdqa
(%r9,%rax),%xmm0; effective address misaligned by 1 byte).

Impact: denial of service via crafted filtergraphs (e.g., crop + noise).
Applies to planar 8-bit formats where upstream filters can shift data
pointers without reallocating.

Found-by: Pwno OSS Team
2025-12-12 19:25:21 +00:00
Niklas Haas
440d58f5b1 avfilter/avfiltergraph: add missing newlines to format printing 2025-12-09 21:31:58 +00:00
Niklas Haas
978a0821ee avfilter/avfiltergraph: always retry format negotiation after auto-filters
There is an edge case not covered by the current logic: If there is only
a single auto-filter inserted, but the auto-inserted filter is incompatible
with a *different* format attribute (after settling the previous formats),
we may need a second auto-filter (e.g. `scale`) to settle the newly introduced
incompatibility.

A regression test demonstrating the issue is added.
2025-12-09 21:31:58 +00:00
Kacper Michajłow
cca872b6fd avfilter/vf_libopencv: make sure there is space for null-terminator in shape_str
Fixes: warning: 'sscanf' may overflow; destination buffer in argument 7 has size 32, but the corresponding specifier may require size 33 [-Wfortify-source]
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-12-08 21:31:13 +00:00
Kacper Michajłow
1fa5e001bc avfilter/vf_neighbor_opencl: add error condition when filter name doesn't match
This cannot really happen, but to suppress compiler warnings, we can
just return AVERROR_BUG here.

Fixes: warning: variable 'kernel_name' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-12-08 21:31:13 +00:00
Timo Rothenpieler
338889c0d9 avfilter/vf_scale_d3d12: fix integer overflow in input framerate calculation
Also removes pointless intermediate variables that caused
the overflow and truncation to happen in the first place.

Fixes #YWH-PGM40646-1
2025-12-08 14:22:16 +01:00
Araz Iusubov
c4d22f2d2c avfilter: D3D12 scale video filter support
This filter allows scaling of video frames using Direct3D 12 acceleration.

Example:
    ffmpeg -hwaccel d3d12va -hwaccel_output_format d3d12 \
           -i input.mp4 -vf scale_d3d12=1920:1280 \
           -c:v hevc_d3d12va -y output_1920x1280.mp4
2025-12-07 21:22:23 +00:00
Marton Balint
315446da2f avfilter/af_amerge: fix indentation
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-12-07 19:36:49 +00:00
Marton Balint
3d667b147a avfilter/af_amerge: add layout_mode option to control output channel layout
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-12-07 19:36:49 +00:00
Marton Balint
4e0a8b745a avfilter/af_amerge: rework routing calculation
No change in functionality.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-12-07 19:36:49 +00:00
Marton Balint
e8b10a9b09 avfilter/af_amerge: fix possible crash with custom layouts
The check if a native layout can be created from the sources was incomplete and
casued a crash with custom layouts if the layout contained a native channel
multiple times, as in this example command line:

ffmpeg -lavfi "sine[a0];sine,pan=FL+FL[a1];[a0][a1]amerge[aout]" -map "[aout]" -t 1 -f framecrc -

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-12-07 19:36:49 +00:00