1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00
Commit Graph

50 Commits

Author SHA1 Message Date
Niklas Haas
d26ea03f60 lavfi/vf_libplacebo: fix typo in assert
Not caught because av_assert1 was compiled out on my end.
2023-06-13 15:28:32 +02:00
Niklas Haas
c4cdd79435 lavfi/vf_libplacebo: add corner_rounding option
For what use it may be.
2023-05-29 19:11:18 +02:00
Niklas Haas
098b338369 lavfi/vf_libplacebo: require v5.278 for importing
Importing Vulkan device on older versions no longer works due to the
lavu vulkan API changes (specifically, the switch to planar textures by
default). Additionally, importing on versions that don't suppirt
lock/unlock_queue is unsafe with the advent of the threaded vulkan
hwaccel. As a plus, saves us some annoying #ifdef boilerplate.

I will raise the minimum vf_libplacebo version globally on the next
stable release of libplacebo, and remove all of these checks.
2023-05-29 18:56:56 +02:00
Niklas Haas
b41ea8c6c3
avfilter/vf_libplacebo: bump max vk version
For two reasons:
1. We now create a vulkan 1.3 device
2. libplacebo master currently requires a vulkan 1.3 device
2023-05-29 00:41:55 +02:00
Niklas Haas
661db605db
avfilter/vf_libplacebo: forward queue locking primitives
For thread safety.
2023-05-29 00:41:55 +02:00
Niklas Haas
0bce5590c3 lavfi/vf_libplacebo: fix crop expr PTS calculation
mix->timestamps is expressed relative to the source timebase, which is
possibly a different timescale from `base_pts`. We can't mix-and-match
here. The only reason this worked in my previous testing was because I
was testing on a source file which had an exactly matching timebase.

Fix it by always using the exact PTS as tagged on the AVFrame.
2023-05-24 14:39:40 +02:00
Niklas Haas
d815584755 lavif/vf_libplacebo: move code (cosmetic)
To eliminate need for forward declaration
2023-05-23 15:06:18 +02:00
Niklas Haas
ee13414444 lavfi/vf_libplacebo: update settings after adding hooks
Failure to do so led to the update s->hooks never getting correctly
propagated to the render params.
2023-05-23 15:05:21 +02:00
Niklas Haas
877ccaf776 lavfi/vf_libplacebo: don't intrude on pl_ namespace
No reason to use this prefix here.
2023-05-22 10:31:51 +02:00
Niklas Haas
21715ecff1 lavfi/vf_libplacebo: update peak detection options
Upstream peak detection lost one option and gained one option. Update
code and documentation as required.
2023-05-22 10:31:51 +02:00
Niklas Haas
643cf2ec46 lavfi/vf_libplacebo: update for new tone mapping API
This algorithm has once again been refactored, this time leading to a
dropping of the old `tone_mapping_mode` field, to be replaced by a
single tunable hybrid mode with configurable strength.

We can approximately map the old modes onto the new API for backwards
compatibility. Replace deprecated enums by their integer equivalents to
safely preserve this API until the next bump.
2023-05-22 10:31:50 +02:00
Niklas Haas
d637f20f05 lavfi/vf_libplacebo: switch to new gamut mapping API
Upstream deprecated the old ad-hoc, enum/intent-based gamut mapping API
and added a new API based on colorimetrically accurate gamut mapping
functions.

The relevant change for us is the addition of several new modes, as well
as deprecation of the old options. Update the documentation accordingly.
2023-05-22 10:31:50 +02:00
Niklas Haas
f66280182a lavfi/vf_libplacebo: add RGB colorspace sanity
Explicitly forbid using a non-RGB colorspace with RGB pixel format or
vice versa. This mirrors identical logic from vf_scale.
2023-05-22 10:31:23 +02:00
Niklas Haas
c00fd02558 lavfi/libplacebo: properly handle EOF
The current code relied on pl_queue eventually returning EOF back to the
caller, which didn't work in all situations (e.g. single frame input).
Also, the current code assumed that ff_inlink_acknowledge_status only
fired once, which was patently not true, as the above edge cases
demonstrated.

Solve both issues by keeping track of the acknowledged link status and
forwarding it (instead of trying to probe the pl_queue again) in the
event that we run out of queued input frames, as well as (in CFR mode)
when we pass the indicated status PTS.
2023-05-22 10:31:13 +02:00
Kacper Michajłow
1aeefc4c06 lavfi/vf_libplacebo: allow linking to shared library with dllimport
Address of dll imported variables can't be used for constant
initialization in C language modes.
2023-05-21 13:15:28 +02:00
Niklas Haas
30c71ef98e lavfi/vf_libplacebo: add frame_mixer option
Fairly straightforward. We just need to modify the scaler handling code
slightly to support looking at a different list of filter presets.
2023-05-14 11:21:43 +02:00
Niklas Haas
02f3b9312a lavfi/vf_libplacebo: allow fps conversion
This exposes libplacebo's frame mixing functionality to vf_libplacebo,
by allowing users to specify a desired target fps to output at. Incoming
frames will be smoothly resampled (in a manner determined by the
`frame_mixer` option, to be added in the next commit).

To generate a consistently timed output stream, we directly use the
desired framerate as the timebase, and simply output frames in
sequential order (tracked by the number of frames output so far).
2023-05-14 11:21:43 +02:00
Niklas Haas
83b1f3f54e lavfi/vf_libplacebo: switch to activate()
To present compatibility with the current behavior, we keep track of a
FIFO of exact frame timestamps that we want to output to the user. In
practice, this is essentially equivalent to the current filter_frame()
code, but this design allows us to scale to more complicated use cases
in the future - for example, insertion of intermediate frames
(deinterlacing, frame doubling, conversion to fixed fps, ...)
2023-05-14 11:21:43 +02:00
Niklas Haas
9e802a47cc lavfi/vf_libplacebo: switch to pl_queue-based design
This does not leverage any immediate benefits, but refactors and
prepares the codebase for upcoming changes, which will include the
ability to do deinterlacing and resampling (frame mixing).
2023-05-14 11:21:43 +02:00
Niklas Haas
2d5e137207 lavfi/vf_libplacebo: split and refactor logic
This commit contains no functional change. The goal is merely to
separate the highly intertwined `filter_frame` and `process_frames`
functions into their separate concerns, specifically to separate frame
uploading (which is now done directly in `filter_frame`) from emitting a
frame (which is now done by a dedicated function `output_frame`).

The overall idea here is to be able to ultimately call `output_frame`
multiple times, to e.g. emit several output frames for a single input
frame.
2023-05-14 11:21:43 +02:00
Niklas Haas
482d81378f lavfi/vf_libplacebo: update render params on demand
Only update this struct when it's expected to change, and cache it
otherwise. Partially motivated by a desire to make `process_frames`
smaller.
2023-05-14 11:15:49 +02:00
Niklas Haas
c65e481330 lavfi/vf_libplacebo: allow operation without avhwdevice
Recent versions of libplacebo have required Vulkan versions incompatible
with lavu Vulkan hwcontexts. While this is expected to change
eventually, breaking vf_libplacebo every time there is such a transition
period is obviously undesired behavior, as the following sea of bug
reports shows.

This commit adds a fallback path for init_vulkan failures which simply
creates an internal device if there was no user-supplied Vulkan hwaccel.
Useful when no interop with lavu vulkan hwframes is needed or desired,
and makes using this filter easier inside certain applications.

Fixes: https://github.com/haasn/libplacebo/issues/170
Fixes: https://github.com/mpv-player/mpv/issues/9589#issuecomment-1535432185
Fixes: https://github.com/mpv-player/mpv/issues/11363
Fixes: https://github.com/mpv-player/mpv/issues/11685#issuecomment-1546627082
Closes: https://code.videolan.org/videolan/libplacebo/-/issues/270
2023-05-13 17:38:20 +02:00
Niklas Haas
b80e43bf07 avfilter/vf_libplacebo: add flexible crop exprs
Motivated by a desire to use vf_libplacebo as a GPU-accelerated
cropping/padding/zooming filter. This commit adds support for setting
the `input/target.crop` fields as dynamic expressions.

Re-use the same generic variables available to other scale and crop type
filters, and also add some more that we can afford as a result of being
able to set these properties dynamically.

It's worth pointing out that `out_t/ot` is currently redundant with
`in_t/t` since it will always contain the same PTS values, but I plan on
changing this in the near future.

I decided to also expose `crop_w/crop_h` and `pos_w/pos_h` as variables
in the expression parser itself, since this enables the fairly common
use case of determining dimensions first and then placing the image
appropriately, such as is done in the default behavior (which centers
the cropped/placed region by default).
2023-05-03 23:40:20 +02:00
Niklas Haas
4b11a07550 avfilter/vf_libplacebo: add fillcolor option
In some circumstances, libplacebo will clear the background as a result
of cropping/padding. Currently, this uses the hard-coded default fill
color of black. This option makes this behavior configurable.
2023-05-03 23:40:20 +02:00
Niklas Haas
e3143703e9 avfilter/vf_libplacebo: strip ICC profiles on CSP change
Not doing so is an obvious oversight - the ICC profile is tied to the
original colorspace, so if we change it, we should definitely strip this
information.

We should probably also have an extra option to control whether the ICC
profile should be stripped, ignored, or applied, but for now this fixes
an existing bug.
2023-04-26 15:36:10 +02:00
Anton Khirnov
632c349931 lavfi: add a flag for filters able to work with hw_device_ctx
This way the caller can set it just on the filters that can make use of
it.
2023-03-24 10:16:51 +01:00
Niklas Haas
1231003c3c avfilter/vf_libplacebo: remove deprecated field
This has not been functional since a year ago, including in our current
minimum dependency of libplacebo (v4.192.0). It also causes build errors
against libplacebo v6, so it needs to be removed from the code. We can
keep the option around for now, but it should also be removed soon.

Signed-off-by: Niklas Haas <git@haasn.dev>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-03-13 11:30:58 -03:00
Niklas Haas
11eca6018c avfilter/vf_libplacebo: wrap deprecated opts in FF_API define
Signed-off-by: Niklas Haas <git@haasn.dev>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-03-13 11:30:58 -03:00
Niklas Haas
eabc304d12 avfilter/vf_libplacebo: add SMPTE ST2094 tone-mappers
libplacebo gained these exciting new functions upstream.
2023-02-17 18:35:39 +01:00
Niklas Haas
62dfa54688 avfilter/vf_libplacebo: fix format query
We need to construct the output format list separatedly from the input
format list, because we need to adhere to two extra requirements:

1. Big-endian output formats are always unsupported (runtime error)
2. Combining 'vulkan' with an explicit out_format that is not supported
   by the vulkan frame allocation code is illegal and will crash (abort)

As a free side benefit, this rewrite fixes a possible memory leak in the
`fail` path that was present in the old code.

Signed-off-by: Niklas Haas <git@haasn.dev>
2023-02-07 15:11:49 +01:00
Niklas Haas
9bfdd8524e avfilter/vf_libplacebo: suppress cast warning
This warning was introduced when ee65039 removed the cast.
2023-01-30 20:34:55 +01:00
Timo Rothenpieler
ee650398ec avfilter/vf_libplacebo: ensure filter hwdevice is a vulkan one
Before this, the filter blindly casts to AVVulkanDeviceContext and
passes invalid values to libplacebo if it's not.
2022-12-04 15:22:13 +01:00
Niklas Haas
48c385fb4c avfilter/vf_libplacebo: support more output formats
Rather than hard-coding AV_PIX_FMT_VULKAN, expand this to the full list
of formats supported by <libplacebo/utils/libav.h>. We re-use the
existing `format` option to allow selecting specific software formats in
addition to specific vulkan hwframe formats.

Some minor changes are necessary to account for the fact that
`ff_vk_filter_config_output` is now only called optionally, the fact
that the output format must now be parsed before `query_format` gets
called, and the fact that we need to call a different function to
retrieve data from the `pl_frame` in the non-hwaccel case.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-11-28 16:05:36 +01:00
Niklas Haas
46a4cc460e avfilter/vf_libplacebo: fix normalize_sar calculation
This previous expression multiplied a constant (outlink->h) that was
guaranteed to be 0 at this point, thus making it always a no-op.

Fix the calculation, and also properly reset the SAR to 1:1 as is now
necessary (the failure to do so previously hid this bug's existence).
2022-11-19 14:15:47 +01:00
Niklas Haas
05d390890a avfilter/vf_libplacebo: default to normalize_sar=0
As a result of a typo in the source code, this option was completely
non-functional. In order to fix it, without breaking the current default
behavior, explicitly change this default to 0.

This behavior is also consistent with how other scale filters behave by
default, so it's probably best to enshrine it anyways.
2022-11-19 14:15:19 +01:00
Niklas Haas
12b4ab5d4d avfilter/vf_libplacebo: fix output format selection
After commit c0b93, it's possible that `ff_vk_filter_config_input` never
gets called, leading to `s->vkctx.input_format` being left unset. This
broke the format auto-selection logic in `libplacebo_config_output`,
resulting in a default to yuv420p, instead of defaulting to the input
format as intended.

Fixes: c0b93c4f8b
2022-11-18 16:14:23 +01:00
Niklas Haas
d1b14b4f0b avfilter/vf_libplacebo: suppress warning on older libplacebo
Move the declaration before the code.
2022-11-18 16:11:01 +01:00
Niklas Haas
c0b93c4f8b avfilter/vf_libplacebo: support all supported pixfmts
This is done only to the inputs, not the outputs, because we always
output vulkan hwframes.

Doing so also requires keeping track of backing textures for non-hwdec
formats, but is otherwise a mostly straightforward change to the format
query function. Special care needs to be taken to avoid crashing on
older libplacebo due to AV_PIX_FMT_RGBF32LE et al.
2022-11-15 16:47:55 +01:00
Niklas Haas
be13812a23 avfilter/vf_libplacebo: init vulkan device in query_format
Instead of doing it ad-hoc in `filter_frame`. This is not a huge change
on its own, but paves the way for adding support for more formats in the
future, in particular formats other than AV_PIX_FMT_VULKAN.
2022-11-15 16:47:55 +01:00
Michael Niedermayer
0a3e121798 avfilter/vf_libplacebo: Match AV_OPT_TYPE_FLOAT to dbl
Reviewed-by: "mypopy@gmail.com" <mypopy@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-05-06 15:57:45 +02:00
Andreas Rheinhardt
2b2380c098 avfilter: Constify non-const filters
This makes the filters match their declaration in
libavfilter/allfilters.c; the earlier discrepancy was btw UB.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-01 21:29:01 +02:00
Niklas Haas
e301a24fa1 avfilter/vf_libplacebo: update for new tone mapping API
Upstream gained a new tone-mapping API, which we never switched to. We
don't need a version bump for this because it was included as part of
the v4.192 release we currently already depend on.

Some of the old options can be moderately approximated with the new API,
but specifically "desaturation_base" and "max_boost" cannot. Remove
these entirely, rather than deprecating them. They have actually been
non-functional for a while as a result of the upstream deprecation.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-03-31 11:55:53 +02:00
Niklas Haas
ecf09764dc lavfi/vf_libplacebo: fix side data stripping logic
This was accidentally comparing s->colorspace against out->colorspace,
which is wrong - the intent was to compare in->colorspace against
out->colorspace.

We also forgot to strip mastering metadata. Finally, the order is sort
of wrong - we should strip this side data *before* process_frames,
because otherwise it may end up being seen and used by libplacebo.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-01-10 09:11:02 +01:00
Niklas Haas
db28bb8fb4 lavfi/libplacebo: support dovi metadata application
libplacebo supports automatic dolby vision application, but it requires
us to switch to a new API. Also add some logic to strip the dolby vision
metadata from the output frames in any case where we end up changing the
colorimetry.

The libplacebo dependency bump is justified because neither 184 nor 192
are part of any stable libplacebo release, so users have to build from
git anyways for this filter to exist.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-01-05 03:13:12 +01:00
Niklas Haas
e9ba40c5c9 lavfi/vf_libplacebo: update deprecated option name
This was renamed upstream quite a while ago (v3.112.0). Rename the
option name as well for consistency (and expand the description just
slightly).

Signed-off-by: Niklas Haas <git@haasn.dev>
2021-12-15 23:38:29 +01:00
Niklas Haas
5317a6366f vf_libplacebo: switch to newer libplacebo helpers
Support for mapping/unmapping hardware frames has been added into
libplacebo itself, so we can scrap this code in favor of using the new
functions. This has the additional benefit of being forwards-compatible
as support for more complicated frame-related state management is added
to libplacebo (e.g. mapping dolby vision metadata).

It's worth pointing out that, technically, this would also allow
`vf_libplacebo` to accept, practically unmodified, other frame types
(e.g. vaapi or drm), or even software input formats. (Although we still
need a vulkan *device* to be available)

To keep things simple, though, retain the current restriction to vulkan
frames. It's possible we could rethink this in a future commit, but for
now I don't want to introduce any more potentially breaking changes.
2021-12-15 23:38:21 +01:00
Lynne
f6dd30df24
lavfi/vulkan: split off lavfi-specific code into vulkan_filter.c
The issue is that libavfilter depends on libavcodec, and when doing a
static build, if libavcodec also includes "libavfilter/vulkan.c", then
during link-time, compiling programs will fail as there would be multiple
definitions of the same symbols in both libavfilter and libavcodec's
object files.
Linkers are, however, more permitting if both files that include
a common file that's used as a template are one-to-one identical.
Hence, to make both files the same in the future, export all avfilter
specific functions to a separate file.
There is some work in progress to make templated files like this be
compiled only once, so this is not a long-term solution.

This also removes a macro that could be used to toggle SPIRV compilation
capability on #include-time, as this could cause the files to be different.
2021-11-19 16:47:26 +01:00
Lynne
d1133e8c44
lavu/vulkan: move common Vulkan code from libavfilter to libavutil 2021-11-19 13:44:45 +01:00
Niklas Haas
a943f527a1 lavfi/vf_libplacebo: pick log level dynamically
In particular, allows users to go all the way up to PL_LOG_TRACE if
desired. (While also avoiding some potentially unnecessary callbacks for
filtered messages, including e.g. the CPU cost of printing out shader
sources)

Response to runtime log level changes by updating it once per
filter_frame(), which should hopefully be often enough.
2021-11-12 22:00:14 +01:00
Niklas Haas
51e03409d7 lavfi: add a libplacebo filter
This filter conceptually maps the libplacebo `pl_renderer` API into
libavfilter, which is a high-level image rendering API designed to work
with an RGB pipeline internally. As such, there's no way to avoid e.g.
chroma interpolation with this filter, although new versions of
libplacebo support outputting back to subsampled YCbCr after processing
is done.

That being said, `pl_renderer` supports automatic integration of the
majority of libplacebo's shaders, ranging from debanding to tone
mapping, and also supports loading custom mpv-style user shaders, making
this API a natural candidate for getting a lot of functionality out of
relatively little code.

In the future, I may approach this problem either by rewriting this
filter to also support a non-renderer codepath, or by upgrading
libplacebo's renderer to support a full YCbCr pipeline.

This unfortunately requires a very new version of libplacebo (unreleased
at time of writing) for timeline semaphore support. But the amount of
boilerplate needed to hack in backwards compatibility would have been
very unreasonable.
2021-11-12 14:45:36 +01:00