Commit graph

12446 commits

Author SHA1 Message Date
Zhao Zhili
b62ae766c1 avfilter/vf_ssim360: fix integer overflow in tape_length allocation
tape_length * 8 overflows 32-bit int for large input widths. Then
av_malloc_array() allocates a tiny buffer while the subsequent
loop writes tape_length*8 BilinearMap entries, causing
heap-buffer-overflow.

Validate the value in float before converting to int and left
shifting, to avoid both float-to-int and signed left shift
overflow UB. Also split av_malloc_array() arguments to avoid
the multiplication overflow.

Fixes: #21511

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-04-13 19:49:32 +08:00
Niklas Haas
b09d57c41d avfilter/buffersrc: re-add missing overflow warning
This was originally introduced by commit 05d6cc116e. During the FFmpeg-libav
split, this function was refactored by commit 7e350379f8 into
av_buffersrc_add_frame(), replacing av_buffersrc_add_ref(). The new function
did not include the overflow warning, despite the same being done for
buffersink.

Then, when commit a05a44e205 merged the two functions back together, the
libav implementation was favored over the FFmpeg implementation, silently
removing the overflow warning in the process.

This commit re-adds that missing warning.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-12 20:02:18 +00:00
Niklas Haas
ef13a29d08 avfilter/framepool: fix frame pool uninit check
Fixes a memory leak caused by AV_MEDIA_TYPE_VIDEO == 0 being excluded by
the !pool->type check. We can just remove the entire check because
av_buffer_pool_uninit() is already safe on NULL.

Fixes: fe2691b3bb
Reported-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 22:02:00 +02:00
Niklas Haas
fe2691b3bb avfilter/framepool: stack-allocate FFFramePool
Saves a pointless free/alloc cycle on reinit. For the vast majority of filter
links, this going to be allocated anyway; and on the occasions that it's not,
the waste is marginal.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
a2ca55c563 avfilter/framepool: remove unnecessary braces (style)
As per the FFmpeg coding style guidelines, braces should be avoided on
isolated single-line statement bodies.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
5c4490a0a6 avfilter/framepool: fix whitespace (cosmetic)
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
38543781cc avfilter/framepool: move variable declarations to site of definition
This is not C89 anymore.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
6efbd99e48 avfilter/framepool: remove check for impossible condition
FFALIGN(..., pool->align) = (...) & ~(pool->align - 1), so this condition
equates to: ((...) & ~(align - 1) & (align - 1)), which is trivially 0.

(Note that all expressions are of type `int`)

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
0b43b8ef31 avfilter/framepool: make FFFramePool public
This struct is overally pretty trivial and there is little to no internal
state or invariants that need to be protected.

Making it public allows e.g. libswscale to allocate buffers for individual
planes directly.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
3e99631873 avfilter/framepool: remove pointless ternary (cosmetic)
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
53ce7265ab avfilter/framepool: use strongly typed union of pixel/sample format
Replacing the generic `int format` field. This aids in debugging, as
e.g. gdb will tend to translate the strongly typed enums back into human
readable names automatically.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
9034587d10 avfilter/framepool: make ff_sws_frame_pool_{audio,video}_init static
Not used outside of the (strictly more flexible) _reinit() anymore.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
39ecc89988 avfilter/framepool: nuke ff_frame_pool_get_*_config
This helper is of dubious utility - it was only used to reinitialize the
frame pools, which is better handled by `ff_frame_pool_reinit()`, and at
present only serves to make extending the API harder.

Users who really need to randomly query the state of the frame pool can
already keep track of the values they set.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
a0510f7f72 avfilter/framepool: update frame dimensions on reinit
The previous logic (ported from libavfilter/video.c) would leave the frame
pool intact if the linesize did not change as a result of changing the frame
dimensions. However, this caused ff_default_get_video_buffer2() to return
frames with the old width/height.

I think this bug was avoided in practice because the only filters to actually
support changing the resolution at runtime already always explicitly overrode
the width/height of allocated output buffers by the link properties.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
ad7956d5bb avfilter/{audio,video}: switch to ff_frame_pool_*_reinit()
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:17 +02:00
Niklas Haas
083a014746 avfilter/framepool: add ff_frame_pool_*_reinit() helpers
This moves the check-uninit-reinit logic out of audio.c/video.c and into
framepool.c, where it can be more conveniently re-used by future users.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:17 +02:00
Niklas Haas
143b810e75 avfilter/framepool: remove alloc argument
Not really needed by anything and makes this API a bit clunkier to extend.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:17 +02:00
Niklas Haas
82871857eb avfilter/framepool: actually use specified allocator for audio frames
This bug means audio buffers were never correctly zero'd as intended by
libavfilter/audio.c

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:17 +02:00
Lynne
d3d0b7a5ee
lavfi/v360: add a Vulkan-compute based filter
This just adds a Vulkan compute-based 360-degree video conversion.
It implements a sufficient subset of the most popular 360-degree video formats.

Options such as rotation are dynamic and can be adjusted during runtime.

Some of the work was based on Paul B. Mahol's patch from 2020. There
were spots where the arithmetic conversion was incorrect.
2026-04-09 12:31:24 +02:00
James Almer
58752ffcdd avfilter/af_whisper: don't set an AVOption accessible field to read only memory
It should also not be set to an av_malloc'd one given it's not an exported option.

Fixes issue #22741.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-04-08 11:52:44 -03:00
Andreas Rheinhardt
0c4c9c66bd avfilter/x86/vf_atadenoise: Don't load args unnecessarily
These args will be read directly from the stack into xmm register,
so loading them into GPRs is unnecessary.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-06 11:28:49 +02:00
Dana Feng
63822ae21f vf_mpdecimate: Fix keep option logic for keep > 0
Fix the following issues with the keep option:

- Add similarity check during keep period. Previously, the code
  returned early during the keep period without checking if the
  frame is actually similar to the reference.

- Reset keep_count on different frames. Previously, the counter
  could accumulate across non-consecutive similar frames, causing
  frames to be dropped earlier than expected.

- Keep the same frame reference if appropriate. Previously, the
  code made similar frames the new reference, causing reference
  drift and gradual scene changes.

Signed-off-by: Dana Feng <danaf@twosigma.com>
2026-04-05 00:26:55 +00:00
nyanmisaka
69fc910777 avfilter/scale_cuda: fix color bleeding in lanczos scaling
Prior to this, the results were not saturated into the uchar/ushort range before
being written. The characteristics of the Lanczos filter exposed this issue.

In addition, the results were truncated rather than rounded, which resulted
in checkerboard artifacts in solid color areas and were noticeable when
using Lanczos with 8-bit input.

Example:
ffmpeg -init_hw_device cuda -f lavfi -i testsrc2=s=960x540,format=yuv420p \
-vf hwupload,scale_cuda=format=yuv420p:w=-2:h=720:interp_algo=lanczos \
-c:v h264_nvenc -qp:v 20 -t 1 <OUTPUT>

Fix #20784

Signed-off-by: nyanmisaka <nst799610810@gmail.com>
2026-04-04 11:31:16 +00:00
Lynne
554dcc2885
vf_scale_vulkan: make sure that pixfmts are different when using swscale
The swscale internals currently have a quirk which causes the memcpy
backend to be called when the pixfmts match. Obviously, this doesn't do
what is expected, as hardware frames cannot just be copied.
Check for this.

Sponsored-by: Sovereign Tech Fund
2026-04-02 21:15:06 +02:00
Zhao Zhili
316531e61c avfilter/vidstabtransform: always use in-place transform path
libvidstab's vsTransformPrepare() takes different internal code paths
for in-place (src == dest) vs. separate-buffer operation. The
separate-buffer path stores a shallow copy of the source frame pointer
in td->src without allocating internal memory (srcMalloced stays 0).
When a subsequent frame takes the in-place path, vsFrameIsNull(&td->src)
is false so vsFrameAllocate() is skipped, and vsFrameCopy() writes into
the stale pointer left over from the previous frame, corrupting memory
that the caller no longer owns.

Whether a given frame is writable depends on pipeline scheduling and
frame reference management, which can change between FFmpeg versions.
Since FFmpeg 8.1, changes in the scheduler caused some frames to arrive
as non-writable, leading to alternation between in-place and
separate-buffer paths that triggered the bug.

Fix this by marking the input pad with AVFILTERPAD_FLAG_NEEDS_WRITABLE.

Fix #22595
2026-04-01 21:56:37 +08:00
Zhao Zhili
c695ad1197 avfilter/vidstabtransform: use existing ctx variable for outlink
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-04-01 21:56:37 +08:00
Andreas Rheinhardt
9fdd7e23e3 avfilter/x86/vf_atadenoise: Avoid load
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-31 16:49:51 +02:00
Dmitrii Gershenkop
6f75e879b6 avfilter/vf_vpp_amf: Minor clean up.
-vf_vpp_amf.c: Remove unused variables.
-vf_amf_common.c: Fix hdrmeta_buffer memory leak.
-hwcontext_amf.c: Fix av_amf_extract_hdr_metadata not picking up light metadata if display mastering metadata is not set.
-doc/filters.texi: Remove irrelevant example with HDR metadata for vpp_amf.
2026-03-31 11:17:51 +00:00
Kacper Michajłow
2b1d8ba3ec
avfilter/x86/vf_atadenoise: move %if ARCH_X86_64 after x86util include
This is consistent pattern with other files. Also is needed for next
commit to always include x86util.asm

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-03-29 22:22:29 +02:00
Kacper Michajłow
2b8ca0f3c5
avfilter/x86/avf_showcqt: add missing section declaration
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-03-29 22:22:29 +02:00
Niklas Haas
d33403ba50 avfilter/buffersrc: use 1 << n for flags (cosmetic)
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-29 09:38:01 +00:00
WyattBlue
33f837a9e9 avfilter/af_whisper.c: Set split_on_word
This prevents `max_len` splitting via tokens, which splits words
like "don't" and proper nouns inappropriately.
2026-03-29 09:37:41 +00:00
Andreas Rheinhardt
eb5ac9fee7 avfilter/x86/vf_idetdsp: Avoid (v)movdqa
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-29 01:05:23 +01:00
Lynne
5482deeb66
lavfi/scale_vulkan: fix width/height match check
Sponsored-by: Sovereign Tech Fund
2026-03-28 19:36:58 +01:00
James Almer
62f944d594 avfilter/vf_lcevc: add missing pixel formats
Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-27 21:00:53 -03:00
James Almer
1b7483dddd avfilter/vf_lcevc: workaround for unknown initial dimensions
This is not enough as filters down the chain may get wrong dimensions

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-27 21:00:19 -03:00
Anton Khirnov
dba8c62400 lavfi/vf_tiltandshift: stop (ab)using AVFrame.opaque
This filter uses AVFrame.opaque to build a linked list of AVFrames. This
is very wrong, as AVFrame.opaque is intended to store caller's private
data and may not be touched by filters. What's worse, the filter leaks
the opaque values to the outside.

Use an AVFifo instead of a linked list to implement the same logic.
2026-03-27 19:42:08 -03:00
Zhao Zhili
fd9f1e9c52 avfilter/vf_drawtext: fix newline rendered as .notdef glyph
GET_UTF8 advances the pointer past the newline byte before the
newline check, so shape_text_hb receives text that includes the
newline character. Since HarfBuzz does not treat U+000A as
default-ignorable, it gets shaped into a .notdef glyph.

Fixes #21565

Reported-by: scriptituk <info@scriptit.uk>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-03-26 07:24:15 +00:00
Niklas Haas
238df21a4f avfilter/vf_libplacebo: early-free unused resources
Otherwise, this will indefinitely persist the last couple of mapped frames
(including any extra decoded frames) in memory, even though they will never be
used again, causing a gradual memory leak until filter uninit.

Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: nxtedition AB
2026-03-25 17:47:09 +00:00
marcos ashton
9559a6036d libavfilter/vf_v360: fix operator precedence in stereo loop condition
The loop condition in the DEFINE_REMAP macro:

  stereo < 1 + s->out_stereo > STEREO_2D

is parsed by C as:

  (stereo < (1 + s->out_stereo)) > STEREO_2D

Since STEREO_2D is 0 and relational operators return 0 or 1, the
outer comparison against 0 is a no-op for STEREO_2D and STEREO_SBS.
But for STEREO_TB (value 2) the loop runs 3 iterations instead of 2,
producing an out-of-bounds stereo pass.

Add parentheses so the comparison is evaluated first:

  stereo < 1 + (s->out_stereo > STEREO_2D)

This gives 1 iteration for 2D and 2 for any stereo format (SBS or TB),
matching the actual number of stereo views.

Signed-off-by: marcos ashton <marcosashiglesias@gmail.com>
2026-03-25 01:19:08 +00:00
Andreas Rheinhardt
76a5d7c545 avfilter/framepool: Mark init, uninit functions as av_cold
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-24 23:13:00 +00:00
Andreas Rheinhardt
c3486e96dd avfilter/framepool: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-24 23:13:00 +00:00
Andreas Rheinhardt
e1e2c85537 avfilter/framepool: Use av_unreachable() for unreachable code
Instead of av_assert0(0).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-24 23:13:00 +00:00
Andreas Rheinhardt
1c101330d6 avfilter/framepool: Remove impossible branches
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-24 23:13:00 +00:00
Lynne
f40fcf8024
libavfilter/scale_vulkan: do not unnencessarily set s->qf on every frame
The initialization function already does this.

Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:23 +01:00
Lynne
940e407c64
libavfilter/scale_vulkan: use swscale's Vulkan code
This commit enables using swscale's newly added Vulkan code.

Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:17 +01:00
Romain Beauxis
878fb73135 libavfilter/vf_frei0r: use .so suffix for plugins on macOS 2026-03-22 14:27:36 +00:00
stevxiao
a077da895b avfilter/dnn_backend_torch: add CUDA/ROCm device support
Add support for CUDA and ROCm (AMD GPU) devices in the LibTorch DNN
backend.

This works for both NVIDIA CUDA and AMD ROCm, as PyTorch exposes ROCm
through the CUDA-compatible API.

Usage:

./ffmpeg -i input.mp4 -vf scale=224:224,format=rgb24,dnn_processing=dnn_backend=torch:model=sr_model_torch.pt:device=cuda output.mp4

Reviewed-by: Guo Yejun <yejun.guo@intel.com>
Signed-off-by: younengxiao <steven.xiao@amd.com>
2026-03-21 16:25:40 +08:00
marcos ashton
a43ea8bff7 avfilter/af_pan: fix sscanf() return value checks in parse_channel_name
sscanf() returns EOF (-1) on input failure, which is non-zero and
passes a bare truthy check. When this happens, the %n directive is
never processed, so len stays uninitialized. Using that value to
advance the arg pointer causes an out-of-bounds read and crash.

Check for >= 1 instead, matching the fix applied to the other
sscanf() call in init() by commit b5b6391d64.

Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/22451
Signed-off-by: marcos ashton <marcosashiglesias@gmail.com>
2026-03-21 00:44:30 +00:00
stevxiao
7b534c2bdc avfilter/dnn_backend_tf: fix ctx async field access
ctx->options.async does not exist on DnnContext; the correct
field is ctx->async directly on the context struct.

Signed-off-by: younengxiao <steven.xiao@amd.com>
2026-03-20 02:22:06 +00:00