Commit Graph

12181 Commits

Author SHA1 Message Date
Niklas Haas
2b67137daa avfilter/vf_idet: correctly reset pixdesc on format change 2025-09-21 11:02:41 +00:00
Niklas Haas
5830743363 avfilter/vf_idet: separate DSP parts
To avoid pulling in the entire libavfilter when using the DSP functions
from checkasm.

The rest of the struct is not needed outside vf_idet.c and was moved there.
2025-09-21 11:02:41 +00:00
Niklas Haas
367febc491 avfilter/vf_idet: expose DSP init function internally
For checkasm.
2025-09-21 11:02:41 +00:00
Kacper Michajłow
c373636f55 avfilter/vsrc_gfxcapture: fix string format specifier
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-09-18 03:55:54 +02:00
Timo Rothenpieler
61835e1d8b avfilter/vsrc_gfxcapture: keep cbdata object alive
Depending on the threading backend the stdlib uses, creating a
mutex/condvar can be quite expensive.
So keep this object alive in the ctx, on which we synchronize via the
uninit mutex anyway.
2025-09-18 01:04:59 +00:00
Timo Rothenpieler
c4e537793b avfilter/vsrc_gfxcapture: fix leaking all callback handlers
Fixes #20537
2025-09-18 01:04:59 +00:00
Timo Rothenpieler
1849068c65 avfilter/vsrc_gfxcapture: use free threaded capture frame pool
Apparently, using a normal frame pool in a multithreaded environment
leads to strange resource leaks on shutdown, which vanish when using a
free threaded pool.
2025-09-18 01:04:59 +00:00
Timo Rothenpieler
4879c9f4e2 avfilter/vsrc_gfxcapture: stop capture session before initializing capture thread shutdown
It might have things going on in the background that still need cleaned
up, and this gives it a chance to enqueue them on the dispatch queue.
2025-09-18 01:04:59 +00:00
Timo Rothenpieler
23d9412ff9 avfilter/vsrc_gfxcapture: fix re-using ret variable from outside of lambda scope 2025-09-18 01:04:59 +00:00
Timo Rothenpieler
983fed34f8 avfilter/vsrc_gfxcapture: don't pass pointer to ComPtr
While it does appear to work fine, with all the operator overloads, it
at least has potential for surprises, so pass it by reference instead.
2025-09-18 01:04:59 +00:00
Timo Rothenpieler
00ddb408c5 avfilter/vsrc_ddagrab: support rendering mouse cursor onto array textures 2025-09-17 14:50:41 +00:00
Andreas Rheinhardt
f47b270b41 avfilter/vf_colordetect: Move ff_color_detect_dsp_init() out of .c file
Otherwise checkasm pulls in vf_colordetect.o and then all of
libavfilter.

Reviewed-by: Martin Storsjö <martin@martin.st>
Reviewed-by: Niklas Haas <ffmpeg@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-16 18:23:52 +02:00
Andreas Rheinhardt
fe0a313299 avfilter/vf_colordetect: Avoid sequentially consistent atomics
Reviewed-by: Martin Storsjö <martin@martin.st>
Reviewed-by: Niklas Haas <ffmpeg@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-16 18:23:45 +02:00
Andreas Rheinhardt
a35c91dc14 avfilter/vf_colordetect: Rename header to vf_colordetectdsp.h
It is more in line with our naming conventions.

Reviewed-by: Martin Storsjö <martin@martin.st>
Reviewed-by: Niklas Haas <ffmpeg@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-16 18:22:24 +02:00
Timo Rothenpieler
b8256b82f5 avfilter/vsrc_gfxcapture: remove needless use of atomics 2025-09-16 15:52:11 +00:00
Timo Rothenpieler
61378d6b91 avfilter/vsrc_gfxcapture: fix possible missed wakeup race in capture loop 2025-09-16 15:52:11 +00:00
Drew Dunne
76471fb143 vf_colorspace: Add an option to clamp trc LUT output
Add a new flag to the vf_colorspace filter which provides the user an
option to clamp the linear and delinear transfer characteristics LUT
values to the [0, 1] represented range. This helps constrain the
potential value range when converting between colorspaces.

Certain colors when going through the conversion can result in out of
gamut colors after the rotation. The colorspace filter allows that with
the extended range. The added clamping just keeps the colors within the
[0, 1) range rather than using that extended range. I'm not enough of a
color scientist to say which is correct, but there are certain
situations where we would prefer to keep the colors in gamut.

The example I have is:

A solid color image of 8-bit YUV: Y=157, U=164, V=98.

Specify the input as:

Input range: MPEG
In color matrix: BT470BG
In color primaries: BT470M
In color transfer characteristics: Gamma 28

Output as:
Out color range: JPEG
Out color matrix: BT.709
Out color primaries: BT.709
Out color transfer characteristics: BT.709

During the calculation you get:

Input YUV:                             y=157,      u=164,      v-98
Post-yuv2rgb BT.470BG:                 r=0.456055, g=0.684152, b=0.928606
Post-apply gamma28 linear LUT:         r=0.110979, g=0.345494, b=0.812709
Post-color rotation BT.470M to BT.709: r=-0.04161, g=0.384626, b=0.852400
Post-apply Rec.709 delinear LUT:       r=-0.16382, g=0.615932, b=0.923793
Post-rgb2yuv Rec.709 matrix:           y=120,      u=190,      v=25

Where with this change, the delinear LUT output would be clamped to 0,
so the result would be:
r=0.000000, g=0.612390, b=0.918807 and a final output of
y=129, u=185, v=46

As for the long and av_clip64, this was just because lrint returned a
long, so I left it as that and then used av_clip64 to the [0,1) range to
avoid overflow. But re-reading, it looks like av_clip_int16 would
downcast that long to int anyway so the possibility of overflow already
existed there. I've put it back to int just to match the existing
behavior.
2025-09-15 14:39:09 +00:00
Timo Rothenpieler
faba1501d5 avfilter/vsrc_gfxcapture: switch to std::thread
Combining C++ with our w32pthreads does not work out.
The C++ standard lib headers might include pthread.h, which will then
define clashing types with our w32pthread header.

To solve this, switch to using C++ native std::thread.
2025-09-14 21:46:40 +02:00
Timo Rothenpieler
570949822b avfilter/vsrc_gfxcapture: MapWindowPoints can return 0 and still succeed 2025-09-14 20:46:29 +02:00
Timo Rothenpieler
d74d3080ff avfilter/vsrc_gfxcapture: make checkheaders happy 2025-09-14 20:33:24 +02:00
Timo Rothenpieler
36e374efb0 avfilter: add gfxcapture, Windows.Graphics.Capture based window/monitor capture 2025-09-14 11:45:11 +00:00
Niklas Haas
5f39965dd6 avfilter/buffersink: remove unneeded parameter
This is a newly added field, so there's no point to try and keep backwards
compatibility with an older API - newer clients should just use the new
fields.
2025-09-09 14:52:01 +02:00
James Almer
23b759e99e avfilter/buffersink: add missing checks for alphamodes
Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-08 18:38:16 -03:00
Niklas Haas
1f2de0f618 avfilter/vf_libplacebo: ensure linear tex is blittable
Required to clear textures to a background color.
2025-09-08 15:42:01 +02:00
Andreas Rheinhardt
893250a734 avfilter/Makefile: Add dependencies for premultiply_dynamic filter
Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-06 16:06:31 +02:00
Niklas Haas
dfc3256da1 avfilter/af_afade: support multiple inputs
Instead of just 2 files, generalize this filter to support crossfading
arbitrarily many files. This makes the filter essentially operate similar
to the `concat` filter, chaining multiple files one after another.

Aside from just adding more input pads, this requires rewriting the
activate function. Instead of a finite state machine, we keep track of the
currently active input index; and advance it only once the current input is
fully exhausted.

This results in arguably simpler logic overall.
2025-09-04 23:12:34 +00:00
Niklas Haas
81c1004891 avfilter/af_afade: shorten crossfade on too short inputs
This behavior is currently completely broken, leading to an abrupt end of the
first audio stream. I want to generalize this filter to multiple inputs, but
having too short input files will always represent a significant problem.

I considered a few approaches for how to handle this more gracefully, but
most of them come with their own problems; in particular when a short input
is sandwiched between two longer ones; or when there is a sequence of short
inputs. In the end, it's simplest to just shorten the crossfade window.

I also considered (and tested) padding the input with silence, but this also
has its own aesthetic implications and strange edge cases.

See-Also: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20388
2025-09-04 23:12:34 +00:00
Niklas Haas
2e0885a091 avfilter/af_afade: don't leak memory on error
This first frame was never cleaned up if the second input fails.
2025-09-04 23:12:34 +00:00
Niklas Haas
386264ae16 avfilter/af_afade: generalize pass_crossfade() signature
Prerequisite to an upcoming refactor.
2025-09-04 23:12:34 +00:00
Andreas Rheinhardt
2451e06f19 all: Use "" instead of <> to include internal headers
Reviewed-by: Niklas Haas <ffmpeg@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-04 22:20:58 +02:00
Niklas Haas
a700f0f72d avfilter/vf_zscale: simplify and fix alpha handling
There's no reason to use a completely separate graph just to process the
alpha plane in isolation - zimg supports native alpha handling as part of the
main image.

Fixes several issues with this filter when adding or removing alpha planes,
and also adds support for scaling premultiplied alpha (which reduces artefacts
near the image borders).
2025-09-02 17:06:25 +02:00
Niklas Haas
c7adeb75ac avfilter/vf_scale: require straight alpha for alpha blending
Fortunately, we only care if this flag is set - otherwise, this filter is
alpha mode agnostic (since it is purely scaling, etc).

That said, there is an argument to be made that we should prefer premul
alpha when scaling, because scaling in straight alpha will leak garbage
pixels; but I think that would be a too backwards-incompatible change to
be worth thinking about at this time.
2025-09-02 17:06:25 +02:00
Niklas Haas
446a25b70f avfilter: add alpha_mode consistency assertion 2025-09-02 17:06:25 +02:00
Niklas Haas
39631c99d4 avfilter/drawutils: add alpha mode support
This allows drawing colors onto images with premultiplied alpha, by first
premultiplying the specified RGBA values.
2025-09-02 17:06:25 +02:00
Niklas Haas
a90e8f1c1d avfilter: use ff_draw_init_from_link() where possible 2025-09-02 17:06:25 +02:00
Niklas Haas
eddbdc8b7c avfilter/drawutils: add ff_draw_init_from_link()
The overwhelming majority of references to ff_draw_init2() just set the
colorspace properties from a filter link. This wrapper allows us to update
all such referencen automatically.
2025-09-02 17:06:25 +02:00
Niklas Haas
d05484757a avfilter/vf_fade: set correct alpha mode requirement
Fading to black in non-alpha mode works for either straight or premultiplied
alpha, but fading to a color does not.
2025-09-02 17:06:25 +02:00
Niklas Haas
ba8aa0e7b3 avfilter/x86/vf_overlay: simplify function signature
No reason to pass all the variables again, if we're already passing the
context.
2025-09-02 17:06:25 +02:00
Niklas Haas
59bb51a8f2 avfilter/vf_overlay: support premultiplied base layers
Conceptually, these are pretty simple to handle, since they are basically
equivalent to the case of alpha being absent, since the only thing the
destination alpha plane is used for is unpremultiplyng straight alpha.

For planar formats, the total number of cases doesn't change in principle,
since before this patch we have:

- alpha present, overlay straight
- alpha present, overlay premultiplied
- alpha absent, overlay straight
- alpha absent, overlay premultiplied

And now we have:

- main straight, overlay straight
- main straight, overlay premultiplied
- main premultiplied, overlay straight
- main premultiplied, overlay premultiplied

That said, we do gain some cases now that we used to (incorrectly) ignore,
like premultiplied yuva420p10.

Notably, we can skip defining separate functions for the case of main alpha
being absent, since that can be a single cheap branch inside the function
itself, on whether or not to also process the alpha plane. Otherwise, as long
as we treat "alpha absent" as "main premultiplied", the per-plane logic will
skip touching the nonexistent alpha plane.

The only format that actually needs extra cases is packed rgb, but that's only
two additional cases in total.

Also arguably simplifies the assignment logic massively.
2025-09-02 17:06:25 +02:00
Niklas Haas
6d6bbdaab0 avfilter/vf_overlay: rename variables for clarity
`is_straight`, `alpha_mode` etc. are more consistently named to refer to
either the main image, or the overlay.
2025-09-02 17:06:25 +02:00
Niklas Haas
6f3eddbedd avfilter/vf_overlay: configure alpha mode on the link
And use the link-tagged value instead of the hard-coded parameter.
2025-09-02 17:06:25 +02:00
Niklas Haas
1c8ca56a88 avfilter/vf_libplacebo: add an alpha_mode setting
Chooses the desired output alpha mode. Note that this depends on
an upstream version of libplacebo new enough to respect the corresponding
AVFrame field in pl_map_avframe_ex.
2025-09-02 17:06:25 +02:00
Niklas Haas
dc02514f6b avfilter/vf_setparams: add alpha_mode parameter 2025-09-02 17:06:25 +02:00
Niklas Haas
e6ab7fe582 avfilter/vf_scale: set correct alpha mode after format change
While vf_scale cannot directly convert between premultiplied and straight
alpha, the effective tagging can still change as a result of a change in
the pixel format (i.e. adding or removing an alpha channel).
2025-09-02 17:06:25 +02:00
Niklas Haas
a3d518a57c avfilter/vf_extractplanes: require straight alpha input 2025-09-02 17:06:25 +02:00
Niklas Haas
ab1bc440f7 avfilter/vf_alphamerge: configure correct alpha mode 2025-09-02 17:06:25 +02:00
Niklas Haas
2e2ca4e740 avfilter/vf_showinfo: print alpha mode when relevant 2025-09-02 17:06:25 +02:00
Niklas Haas
2b1ef029eb avfilter/vf_format: add alpha_modes parameter 2025-09-02 17:06:25 +02:00
Niklas Haas
de297ae2fc avfilter/buffersrc: add alpha_mode parameter 2025-09-02 17:06:25 +02:00
Niklas Haas
0fbd90d78f avfilter/buffersink: add support for alpha modes 2025-09-02 17:06:25 +02:00