Commit Graph
12613 Commits
Author SHA1 Message Date
Guo Yejun a7e72069f1 avfilter/dnn: fix race when querying queue length
Replace av_usleep polling with a condition variable wait.
2026-08-02 07:59:44 +00:00
Guo Yejun 133923a209 avfilter/dnn: assign correct output layout before use 2026-08-02 12:38:31 +08:00
Dan Dennedy 66a8c37582 scale_d3d11: Fix hw_frame_ctx reference leak
This fixes #20995. The reference is taken twice and assigned to the same pointer (see above in the same function). Only the latter is needed.
2026-07-31 13:29:24 +00:00
younengxiao 0dd50ec535 avfilter/dnn: initialize DNNData at the config_input call sites
vf_dnn_processing.c and vf_dnn_detect.c both declare an uninitialized
DNNData model_input before using it. This commit initialize it.

Signed-off-by: younengxiao <steven.xiao@amd.com>
2026-07-31 13:21:29 +00:00
Michael Niedermayer e38b5d15bd avfilter/af_arnndn: pad the DCT input buffers to the read length
Fixes: out of array access
Fixes: SUcVEyk7r3Gc
Found-by: Kenan Alghythee <kalghy2@uic.edu>
2026-07-31 04:00:18 +00:00
Raja-89 a234fc1130 avfilter/dnn: prevent crash on parameterless LibTorch models
When loading a TorchScript model that does not contain any learnable
parameters (e.g., a purely functional model), the Torch backend would
crash during inference. This occurred because the code attempted to
dereference the first iterator of the model's parameter list
`parameters().begin()` to determine the device, which results in
Undefined Behavior when the parameter list is empty.
This commit fixes the issue by determining the inference device directly
from the user-configured `ctx->device` string instead of probing the
model parameters, allowing parameterless models to execute safely.

Testing:
1. Generate a parameterless model:
cat << 'EOF' > generate_model.py
import torch
class DummyModel(torch.nn.Module):
    def forward(self, x):
        return x
scripted_model = torch.jit.script(DummyModel())
scripted_model.save("dummy_model.pt")
EOF
python3 generate_model.py
2. Run inference (previously crashed, now succeeds):
./ffmpeg -y -i input.mp4 -vf 'format=rgb24,dnn_processing=dnn_backend=torch:model=dummy_model.pt' -frames:v 5 -f null -
Signed-off-by: Raja Rathour <imraja729@gmail.com>
2026-07-29 12:37:03 +00:00
Julius Bairaktaris d43b1efd2e avfilter/vf_amf_common: fix component Init() format with hwaccel input frames
amf_init_filter_config() returned the hardware pixel format (e.g.
AV_PIX_FMT_D3D11) as in_format when the input link carries D3D11VA or
DXVA2 hw frames. av_av_to_amf_format() maps hw formats to
AMF_SURFACE_UNKNOWN, so every AMF filter failed its component Init()
with AMF_INVALID_ARG (VQEnhancer, FRC) or AMF_NOT_SUPPORTED
(Converter, HQScaler). Return the underlying software format instead,
which is already validated against AMF a few lines above. Apply the
same mapping to the default output sw format, which otherwise ends up
as the hw pixel format in hwframes_out->sw_format when the output link
uses a hwaccel format.

Fixes e.g.:
  ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -i in.mp4          -vf frc_amf -c:v hevc_amf out.mp4

Note: with D3D11VA input, the compute-based components (VQEnhancer,
HQScaler, VideoConverter) additionally require decode textures created
with D3D11_BIND_SHADER_RESOURCE, e.g.:
  -init_hw_device d3d11va=dx11:,SHADER=1 -hwaccel_device dx11
FRC and DXVA2 input work with default decode textures.
2026-07-29 08:52:27 +00:00
Kenan Alghythee 06fd4fd0e7 avfilter/vf_xpsnr: avoid a zero block size on small frames
Fixes: division by zero
Fixes: SUcVEyk7r3Gc
Found-by: Kenan Alghythee <kalghy2@uic.edu>
2026-07-29 00:42:47 +00:00
Timo Rothenpieler 80f14b251b Revert "lavfi: do not send premultiplied alpha to filters not ready for it"
This reverts commit f3431169da, which
introduced various regressions and hangs with at least exr, as
reported by fate, and potentially other codecs that are not as
thouroughly tested.
2026-07-27 20:32:34 +02:00
Timo Rothenpieler 7e1f4dc318 Reapply "avfilter/avfiltergraph: always retry format negotiation after auto-filters"
This reverts commit cd9d265344.
2026-07-27 20:13:00 +02:00
Nicolas George ad1f8a09a6 lavfi/vf_format: factor parsing the lists 2026-07-27 10:51:09 +02:00
Nicolas George cf6abefe83 lavfi/vf_format: report error for invalid names 2026-07-27 10:51:09 +02:00
Nicolas George a757b708ae lavfi: cosmetic: rename variable 2026-07-27 10:27:27 +02:00
Nicolas George f3431169da lavfi: do not send premultiplied alpha to filters not ready for it
The arithmetic to process colors in premultiplied alpha is
completely different from the arithmetic for straight alpha.
Running a filter using straight arithmetic on premultiplied
will result in incorrect and sometimes invalid output.
Therefore, premultiplied alpha should only be selected for
filters that either explicitly support it or only use
elementary color arithmetic or none at all.
For other filters, automatic conversion will do its work.
2026-07-27 10:27:27 +02:00
Nicolas George cd9d265344 Revert "avfilter/avfiltergraph: always retry format negotiation after auto-filters"
This reverts commit 978a0821ee.

The stability of the negotiation process has never been studied
with multiple rounds.

It has always been documented to users that scale was the filter
to insert to manage format conversions. A second filter for
a specific type of conversion should never have been added:
the proper fix for the issue that this commit tried to fix is
to give scale the ability to handle premultiplication too.
2026-07-27 10:27:27 +02:00
Raja-89 b52c71e438 avfilter/dnn: fix async teardown race condition in all backends
When the filter graph is torn down early (e.g. at EOF with -frames:v),
the main thread calls dnn_free_model and destroys the request queue
while async inference threads may still be running. When a detached
thread finishes and tries to push its result back to the destroyed
queue, it triggers a segmentation fault.

Add ff_dnn_wait_requests() to dnn_backend_common which blocks
until all allocated request items (ctx->nireq) have been safely
returned to the request_queue. Call it from dnn_free_model in the
torch, tensorflow, openvino, and onnx backends before destroying the queue.
2026-07-25 15:08:07 +00:00
Michael Niedermayer 92cd5c9781 avfilter/vf_lut3d: do not compute size*size before the size is validated
parse_dat(), parse_cube(), and parse_cinespace() multiply an untrusted LUT size
before allocate_3dlut() validates it, which can overflow int.
Use the validated lutsize2 computed by allocate_3dlut() instead.

Fixes: signed integer overflow
2026-07-24 19:09:44 +00:00
Guo Yejun 6095372a70 avfilter/dnn: use batch_size in DnnContext instead of ov_option
batch_size in DnnContext is a common variable for all dnn backends
2026-07-24 14:06:09 +00:00
Andreas Rheinhardt 68c94ed330 av{codec,filter}/x86: Remove unnecessary asm.h inclusions
asm.h is only for inline assembly.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-07-22 14:52:57 +02:00
Andreas Rheinhardt f8c4828c0f avutil/x86/asm: Remove HAVE_[67]REGS, use HAVE_X86_[67]REGS directly
This allows to remove the asm.h inclusion from x86/mathops.h
and therefore from hundreds of files which don't need it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-07-22 14:52:57 +02:00
Michael Niedermayer 5d7112c60e avfilter/vf_hqdn3d: support dynamic frame sizes 2026-07-22 02:50:50 +00:00
Michael Niedermayer f0f634b658 avfilter/vf_hqdn3d: reject unsupported frame parameter changes
Fixes: out of array access
Fixes: 9aj_hqdn3d_dynamic_res.mjpg / 9aj_generate_hqdn3d_dynamic_res_mjpg.py
Fixes: wWDsy2oDvMuR
Found-by: Adrian Junge (vurlo) <adjun37@gmail.com>
2026-07-22 02:50:50 +00:00
StachowiakDawid c182b1c09c Add new mode to mpdecimate video filter 2026-07-20 17:49:47 +00:00
Raja-89 c60ac8f256 avfilter/dnn: implement batching for Torch backend
Add batch processing support to the LibTorch DNN backend, following
the same pattern used by the OpenVINO backend.

Key changes:
- Add batch_size AVOption (range 1-1000, default 1) to DnnContext
- Accumulate lltasks in the queue, trigger inference when batch_size
  lltasks are ready (matching the OpenVINO batch execution pattern)
- Pre-allocate a single contiguous memory buffer for the entire batch
  in fill_model_input_th() to avoid unnecessary tensor copies
- Split batched output in infer_completion_callback() and dispatch
  each slice to its corresponding task

Tested with:
ffmpeg -f lavfi -i testsrc=duration=5:size=640x480:rate=25 -vf format=rgb24,dnn_processing=dnn_backend=torch:model=dummy_model.pt:batch_size=4 -f null -

Signed-off-by: Raja Rathour <imraja729@gmail.com>
2026-07-18 02:56:18 +00:00
Diego de Souza 07020f5ce8 avfilter/hwupload_cuda: add CUARRAY output and semi-planar 444 format support
Add an output_format option (cuda | cuarray) so the filter can produce
either pitched-linear (AV_PIX_FMT_CUDA, default) or block-linear
(AV_PIX_FMT_CUARRAY) device frames.  This enables host-to-device
upload directly into CUarray surfaces for the CUARRAY transcode
pipeline.

Also extend the accepted input pixel format list with semi-planar 444
formats (NV24, P410, P416) and the planar MSB variants (YUV444P10MSB,
YUV444P12MSB).  Semi-planar 444 formats are rejected with a clear
error when output_format=cuda, as they are only supported by the
CUarray allocation path.

Signed-off-by: Diego de Souza <ddesouza@nvidia.com>
2026-07-14 19:45:02 +00:00
Raja-89 312c830916 avfilter/dnn: auto-initialize nireq for Torch backend
Initialize ctx->nireq with av_cpu_count() / 2 + 1 when
unset, matching the TensorFlow and OpenVINO backends.

Create ctx->nireq THRequestItems in a loop instead of
hardcoding a single request, enabling concurrent async
inference requests for improved throughput.

Signed-off-by: Raja Rathour <imraja729@gmail.com>
2026-07-14 14:26:53 +00:00
Michael Niedermayer a7e38b617b avfilter/vf_swaprect: size the temp row buffer for the widest plane
Fixes: out of array access
Fixes: 7aj_swaprect_odd17_nv12.nut / 7aj_generate_swaprect_odd17_nv12.py
Fixes: VRAXYvKtmKa8
Found-by: Adrian Junge (vurlo) <adjun37@gmail.com>
2026-07-13 18:22:46 +00:00
Michael NiedermayerandFable-5 cff4a69294 avfilter: add latticepal filter
Convert packed 24/32-bit RGB/BGR/RGBA/BGRA input to PAL8 using a per-frame palette
whose colors are placed on a face-centered cubic lattice (realized as the
scaled D3/D4 checkerboard lattice), with a user-supplied density controlling
the number of lattice steps spanning one color axis.

Only lattice points actually used by a frame enter its palette; if a frame
needs more than 256 of them, the filter will itearatively drop palettte
entries and reassign affected pixels until 256 color remain

lookup uses the Conway-Sloane rounding algorithm. Supported dithering
modes: none, ordered 8x8 bayer (swscale), Cluster & Void blue noise and
Floyd-Steinberg error diffusion.

Co-Authored-by: Fable-5
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-07-13 18:16:18 +00:00
Michael Niedermayer f186c50cf5 avfilter/vf_floodfill: remove unneeded variables
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-07-13 17:14:54 +00:00
Michael Niedermayer 24c322fdb2 avfilter/vf_floodfill: size the point stack for the current frame
Fixes: out of array access
Fixes: 8aj_floodfill_dynamic_size.pgm / 8aj_generate_floodfill_dynamic_size_pgm.py
Fixes: 3MleMXjGZvu3
Found-by: Adrian Junge (vurlo) <adjun37@gmail.com>
2026-07-13 17:14:54 +00:00
Michael Niedermayer 0089694c06 avfilter/vf_lut3d: compute size2 after the 3DLUTSIZE directive
Fixes: out of array access
Fixes: lut3d_poc/poc_3dlut2.dat
Fixes: 6p0ahHBxreqG
Found-by: SecBuddyF - Tencent KeenLab
2026-07-13 17:14:48 +00:00
Araz Iusubov fc4b523596 avfilter/vf_vqe_amf: Add AMF Video Quality Enhancer filter 2026-07-13 16:40:41 +00:00
Lynne 90436de5e1 vf_libplacebo: add missing avstring.h include
Otherwise compilation fails due to vulkan.h no longer including it.
2026-07-13 18:57:38 +09:00
Lynne 92f2e6374d configure: remove libshaderc and libglslang support
All of it is now gone.
2026-07-13 18:57:38 +09:00
Lynne 9e9ac0dcd9 vulkan: remove runtime shader compilation support
No longer needed.
2026-07-13 18:57:37 +09:00
Lynne 6219d4fdd1 vf_scale_vulkan: port to compile-time SPIR-V generation
Same functionality as before, but cleaner.
2026-07-13 18:57:37 +09:00
James Almer b662613b63 avfilter/af_aresample: also look for downmix matrix side data
Signed-off-by: James Almer <jamrial@gmail.com>
2026-07-11 19:32:17 -03:00
James Almer 6336cffdce avfilter/af_ashowinfo: support printing downmix matrix side data
Signed-off-by: James Almer <jamrial@gmail.com>
2026-07-11 19:32:17 -03:00
Philip Langdale 8ad6288553 avfilter/vf_libplacebo: add flag to inherit the input's Vulkan device
vf_libplacebo is unique in that it can function as both a Vulkan filter, and a
software filter, depending on how it the filter graph is configured. While this
is very flexible, it create a problem in situations where the filter does not
receive a Vulkan hw frames context up front. When that doesn't happen, it will
initialise its own standalone pl context, and then fail to interoperate with
a context provided via the input link. This then leads to graph failures.

There are two primary scenarios where this existing logic breaks what should
be valid configurations:
* When the global filter hw device is a cuda device and we use something like
  `hwupload=derive_device=vulkan` to pass frames from cuda to vulkan
* In mpv (and probably other media players) which don't set the global filter
  hw device at all. In this case, it's impossible to configure vf_libplacebo
  to use a hw frames ctx, even if it's using Vulkan for everythng else. This
  prevents the use of vf_libplacebo in any fully hardware accelerated pipeline
  in mpv

There are various ways we could imagine addressing it - such as allowing the
filter to discard the initial pl context and recreating it based on the passed
in device, but it's easier to reason about if we add a flag that explicitly
tells the filter that it should inherit the device context from the input link.
This puts the filter into a mode that works like all the other Vulkan filters.

This requires explicit configuration from the user, but the intent is clearer,
and the user can always know when it's necessary as they define the filter
graph.
2026-07-09 13:25:09 +00:00
Zhao Zhili c57660fb18 avfilter/vf_scale_cuda: fix non-scaling format conversion
A format-only conversion leaves the auto use_filters value unresolved.
Regression since 5d0748243f.

Fix issue #23737

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-07-08 12:37:35 +00:00
Michael Niedermayer a73d648f6e avfilter/vf_v360: keep remap source coordinates in bounds
Two runtime paths could compute out-of-range source coordinates for
degenerate projection geometry, causing heap-buffer-overflow reads

Fixes: out of array read
Fixes: assertion failure
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-07-07 17:43:18 +00:00
Michael Niedermayer b3712addc9 avfilter/vf_v360: reject dimensions too small for the projection
Fixes: out of array read
Fixes: assertion failure
Fixes: mQzloVqnivHQ
Found-by: Anthony Hurtado
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-07-07 17:43:18 +00:00
Kacper Michajłow c6498178bb avfilter/vsrc_gfxcapture_winrt: add missing system_error include
Fixes: error: no type named 'system_error' in namespace 'std'
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-06 06:39:19 +00:00
Jamaika1 c74f279559 avfilter/vf_quirc: Changed character specifier
```
vf_quirc.c: In function 'filter_frame':
vf_quirc.c:104:46: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'int64_t' {aka 'long long int'} [-Wformat=]
  104 |            "Found count %d codes in image #%ld\n", codes_count, inl->frame_count_out);
      |                                            ~~^                  ~~~~~~~~~~~~~~~~~~~~
      |                                              |                     |
      |                                              long int              int64_t {aka long long int}
      |                                            %lld
```
2026-07-05 22:31:27 +00:00
Andreas Rheinhardt 97cbffe917 all: Don't discard const through {mem,str,strr}chr
C23 made these generic functions that no longer cast const
away for you, leading to warnings when compiling with C23
and a recent enough toolchain (glibc supports this since 2.43).
This commit fixes all the warnings that can simply be fixed
by adding const, without adding casts.
(the latter excludes parse_forced_key_frames() in ffmpeg_mux_init.c).

Reviewed-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-07-05 09:02:40 +02:00
Vladimir Panteleev e058e8c0c5 vf_photosensitivity: fix metadata when duplicating frames
When the blending factor was calculated to be 0, the hot path skipped
updating variables later emitted in metadata.

Fix the flow to ensure they are populated consistently.

Extend the FATE test suite to check metadata output.
2026-07-05 00:41:30 +00:00
Vladimir Panteleev 722493d3e1 vf_photosensitivity: add blend option
This commit attempts to address feedback from this filter's users, by
introducing a new option which controls the amelioration mechanism.

The "blend" option is a factor which is multiplied by the difference
in badness (between the threshold and the currently accumulated
badness). This difference normally controls how much of the next frame
we can let through without making it exceed the badness threshold.

Setting the option to zero effectively puts the filter into a mode
where it always duplicates the last frame (which did not put
accumulated badness over the threshold) instead of attempting to blend
in new frames.  I have received reports that this mode is preferable
to users for some types of media.
2026-07-05 00:41:30 +00:00
Vladimir Panteleev 734cbb6617 vf_photosensitivity: scale badness threshold with history size
This commit attempts to address feedback from this filter's users, by
improving the filter's behavior at the start of playback or
immediately after seeking.

In these situations, the history buffer is empty, but because we did
not previously track its size, we were calculating the weighted
average as if the corresponding frames had zero badness. This caused
the filter to behave differently and possibly produce false negatives
when the history was not fully populated.

Address this by instead taking into account the history size when
calculating cumulative badness. To accomplish this:

- Add a history_size field to to PhotosensitivityContext, tracking how
  much of the history buffer is populated.

- Change the semantics of PhotosensitivityContext::badness_threshold.
  Previously, it was premultiplied by the maximum history size. This
  is no longer done, so that we can multiply it to the live
  history_size on the fly instead.

- Calculate the badness threshold on a per-frame basis. The result is
  now stored in a badness_threshold local variable.

This commit only changes the filter's behavior for the first
PhotosensitivityContext::nb_frames (configurable as the "frames"
filter option) frames. For successively filtered frames, the behavior
is unchanged.
2026-07-05 00:41:30 +00:00
Michael Niedermayer 4da9812e25 avfilter/vf_quirc: resize the quirc buffers when the input size changes
Fixes: out of array access
Fixes: JbvzNObhorBp
Fixes: 030e140145 (lavfi: add quirc filter)
Found-by: Adrian Junge (vurlo)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-07-05 00:07:59 +00:00
tknaveen 766074133f avfilter/dnn_backend_torch: fix missing ret in async error path
ff_dnn_start_inference_async() return value was not stored in ret,
causing execute_model_th() to return success on async startup failure.
This left vf_dnn_processing stuck in its flush loop waiting on a
task that was never started.
2026-07-03 21:29:36 +08:00