252 Commits

Author SHA1 Message Date
Kacper Michajłow
6739fd490b filters/f_decoder_wrapper: reinit decoder on audio-spdif opt change
Fixes: #17072
2025-12-18 13:07:13 +01:00
nanahi
c82d9317a3 filters/f_swresample: make fudge_pairs const 2025-08-05 03:10:33 +02:00
nanahi
b47c805fa2 various: remove redundant return
void return type functions don't need a final return statement.
2025-04-27 00:10:31 +02:00
Leo Izen
5870c95e89 filters: automatically flip video if displaymatrix indicates so
Currently we check AV_FRAME_DATA_DISPLAYMATRIX for its rotation factor
but not for its flip factor, which could happen with some input files.
This commit adds and autovflip filter, which is applied before the
autorotate filter to flip vertically before rotating. It also changes
the displaymatrix reading code to output to mp_image->params.vflip so
it can be autoinserted as necessary.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-03-31 14:07:47 -04:00
Kacper Michajłow
74d3c2f0e7 mp_image: set repr.alpha and repr.bits when mapping AVFrame
Fixes invalid colors with gpu-next direct mapping of some formats.
2025-03-26 18:39:40 +01:00
Kacper Michajłow
1c49cfdb97 various: use mp_assert macro 2025-03-04 20:07:29 +01:00
Kacper Michajłow
50cda601ba f_decoder_wrapper: don't wait on self thread progress on reinit
Fixes deadlock when reinit is triggered by the thread itself.

Fixes: #15776
2025-03-04 19:32:56 +01:00
Dudemanguy
f2ef360444 f_decoder_wrapper: allow VDCTRL_GET_HWDEC to actually fail
a3823ce0e0 made this request a special
case because of all the threading considerations. Unfortunately, the
implementation made it so that VDCTRL_GET_HWDEC always would return
CONTROL_UNKNOWN when using mp_decoder_wrapper_control. This didn't
matter because VDCTRL_GET_HWDEC in vd_lavc would always succeed, but in
reality it shouldn't. It takes some time before we actually know what
the hwdec is and if you query during that time, you'll could get some
bogus value (e.g. during hwdec auto probing). So fix that by returning
false in vd_lavc if hwdec_notified isn't there yet and adjust the
wrapper control logic to take this into account.
2025-03-04 16:37:23 +00:00
Kacper Michajłow
bc0c148d62 demux_mkv: add support for chroma location
Fixes: #15983
2025-03-03 23:47:52 +01:00
nanahi
66a7338027 f_decoder_wrapper: warn when using video-aspect-override of 0 or -1 2025-02-18 23:05:02 +00:00
nanahi
13f94700d9 f_decoder_wrapper: add --video-aspect-method=ignore
This adds --video-aspect-method=ignore to replace --video-aspect-override=0.
--video-aspect-override=0 and --video-aspect-override=-1 will no longer be
handled specially. For compatibility, 0 is mapped to always use ignore
and -1 is always mapped to always use container.

"no" is now the replacement for --video-aspect-override=-1, which is
internally remapped to -2 to avoid using a deprecated value.
2025-02-18 23:05:02 +00:00
nanahi
4456dc1d1f Revert "m_option: forbid non -1 negative values for video-aspect-override"
This is poorly implemented and will break existing scripts which set
the value directly with double without a string value, like
mp.set_property_native, or if the value is set with add/multiply commands.
Revert this until a better solution is found.

This reverts commit cb91de2a34.
2025-02-18 23:05:02 +00:00
Dudemanguy
cb91de2a34 m_option: forbid non -1 negative values for video-aspect-override
Setting this to M_RANGE(-1, 10) meant that you could pass fractional
negative values without it being an error. This is, of course, nonsense.
-1 is the only special negative value with a meaning. Error out if we
get anything else by doing some additional parsing before we send it off
to parse_double which will then restrict the range to 0, 10 with these
changes. Note that this approach requires defval to be there which is
not the most extensible thing in the world. But there's literally only
two OPT_ASPECT type options out of the hundreds we have so not a big
deal. Ideally, this type should be OPT_CHOICE but with underlying
doubles but that's too much effort to implement cleanly.
2025-02-08 02:01:13 +00:00
Kacper Michajłow
038d66549d demux: reclaim demux_packets to reduce memory allocator pressure
This update introduces a demux_packet_pool, allowing for the reuse of
previously allocated packets when needed.

sizeof(AVPacket) is not a part of the lavc public ABI, which prevents us
to allocate memory in larger blocks. However, we can substantially
decrease the amount of alloc/free operations during playback by reusing
both mpv's demux_packet and AVPacket.

This adjustment addresses the root cause of issue #12076, which,
although resolved upstream, did not fully tackle the persistent problem
of allocating small blocks of aligned memory. This issue largely stems
from the FFmpeg design of the AVPacket API. After this change memory
will no longer be allocated once cache limits is reached.

The demux_packet_pool is shared as a global pool of packets for a given
MPContext.

This change significantly speeds up the demuxer deinitialization,
benefiting file switching scenarios, especially when a large demuxer
cache is used.

See: #12294
See: #12563
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-02-05 05:09:33 +01:00
Dudemanguy
0e03fdf0f7 f_decoder_wrapper: allow changing --ad and --vd at runtime 2025-01-28 15:48:15 +00:00
Kacper Michajłow
59d1dc43b9 various: fix typos 2025-01-04 15:59:49 +02:00
Kacper Michajłow
3c57b395d3 hwdec_vaapi: try format upload lazily
Uploading all available formats has proven to be problematic because
more unusual ones can crash the driver, even when no upload is
necessary. Check the upload only if needed to avoid issues with broken
drivers.

This also might speedup the init process.

Fixes: #14956
Fixes: #15030
2024-10-12 01:36:44 +02:00
Kacper Michajłow
a6c363e8da f_hwtransfer: fix too aggressive preference to use direct upload format
Well, this was thinko on last minute code simplification I made. We need
to check both input and output formats.
2024-10-04 05:10:36 +02:00
Kacper Michajłow
3fd6c31e1f f_hwtransfer: fix upload formats selection
There was mixup between upload formats and device formats. Instead of
filtering the device formats with VO constraints, upload formats were
affected. It was working, because most of the time the upload is using
the same formats. But if there is conversion on the fly needed we were
filtering wrong list of formats. Upload formats are those that can be
used to upload to the given hardware frame, conversion during upload are
allowed if possible. The main fix is in select_format() which were using
device formats as input, instead of ouptut formats and upload formats as
output, instead of input.
2024-10-04 00:10:05 +02:00
Kacper Michajłow
822daeb89f f_hwtransfer: ensure that we convert to full range rgb with scale_vaapi
Limited range rgb is evil and not supported by FFmpeg, this ensures
parity of hardware conversion with software conversion.
2024-10-04 00:06:58 +02:00
Dudemanguy
c0c57be07b f_hwtransfer: filter out unsupported hwuploads from p->fmts
With the previous change, it is possible that the mp_hwdec_ctx contains
a list of known supported hwuploads. Take this into account when adding
to the p->fmts list. We want to be sure to select only something that is
actually possible to use. If the hwdec does not implement
supported_hwupload_formats, then all are assumed to work.
2024-09-16 00:07:36 +00:00
Kacper Michajłow
e41ee0524c f_auto_filters: don't set interlaced-only for userdeint
Not wanted apparently: https://github.com/mpv-player/mpv/pull/14822#discussion_r1758134111
2024-09-15 20:10:09 +02:00
Kacper Michajłow
f6d931301b vf_d3d11vpp: adjust options for userdeint filter
Fixes: #14816
2024-09-08 21:44:51 +02:00
Kacper Michajłow
47cb503bf5 f_hwtransfer: fix best upload format selection
It is possible for a format to be supported by hardware but not by
av_hwframe_transfer for uploading. This breaks the best upload format
selection. We first select the hardware input format and then choose the
best software format that can be uploaded. In some cases, this may
result in a format that is not uploadable at all, leading to an error.
To solve this, we should avoid adding non-uploadable formats to the fmts
table.

For example, for format d3d11/yuv420p, av_hwframe_transfer_get_formats()
returns empty list of formats.
2024-08-27 01:27:48 +02:00
Philip Langdale
4b97c23dac video: hwdec: extend look up of hwdecs to consider device type as well
Now that we have identified the device types associated with each hwdec, we
can take advantage of this to ensure that get the right hwdec is chosen when
decoding frames and there are multiple choices available with different device
types.

This is also plumbed into the filter initialisation logic, although in practice
the decision on the hwdec has already been made at this point - still it's
easier than retaining the ambiguous look up logic and worrying that it might
lead to an inconsistent result.
2024-08-10 14:24:36 -07:00
Kacper Michajłow
995283bd7a filters/f_lavfi: fix null dereference on empty graph 2024-06-27 02:57:22 +02:00
Dudemanguy
6e3d90d72a options: remove some deprecated OPT_REPLACED option mapping
These were all deprecated in mpv 0.37.0 or earlier and are not
considered common enough options to warrant keeping the deprecated
mapping longer. Since demux_cue had only a single option in it, the
entire option substract is removed. This can be readded later if someone
wants to introduce a specific option to it again.
2024-06-25 02:18:58 +00:00
Kacper Michajłow
893ea5e47b player/playloop: fix null dereference if filter_root does not exist
For example when `input-commands=drop-buffers` is added to the config.

Add a check inside mp_filter_reset().

Found by OSS-Fuzz.
2024-06-24 16:20:46 +02:00
Kacper Michajłow
687eb4c875 various: remove no longer needed availability checks
image_writer: remove jpegxl availability check

meson: remove check for lavu vulkan support

image_writer: remove avif availability check

ad_spdif: remove no longer needed definitions

demux_lavf: remove side data extraction compatibility code

demux/packet: remove ITU T.35 availability check

filters/f_lavfi: remove avfilter_filter_pad_count availability check

image_writer: remove PNG cICP support check

mp_image: remove AV_FRAME_DATA_DOVI_METADATA availability check

mp_image: remove AV_FRAME_FLAG_INTERLACED availability check

vd_lavc: remove ctx->pic->duration availability check

sws_utils: remove av_chroma_location_enum_to_pos availability check

vd_lavc: remove AV_CODEC_EXPORT_DATA_FILM_GRAIN availability check

demux_lavf: always use io_close2
2024-06-22 16:12:14 +02:00
Kacper Michajłow
3c5a79300c various: remove av channel layout check 2024-06-22 16:12:14 +02:00
nanahi
bb88e4aeb5 various: fix trailing whitespace 2024-05-07 11:23:08 +02:00
Guido Cella
b086a404b5 command: return lavfi filters in option-info/[av]f/choices
This adds non-mpv filters to option-info/af/choices and
option-info/vf/choices, which allows completing them with set af/vf
<Tab> in console.lua.

Partial fix of #13017. Getting the filter options would required adding
af-list and vf-list properties.
2024-05-05 14:43:57 +02:00
sfan5
c4b6d0da38 f_lavfi: reject filters with too many in/outs
The pad count serves as a minimum even if the filter has
dynamic inputs/outputs, so we should reject them here.

At least on FFmpeg 6.1 this results in no practical change
in the list accepted filters.

fixes: 8bf3fe7e2a
2024-05-04 16:13:03 +02:00
Kacper Michajłow
637bc6994f f_decoder_wrapper: clear decoder info on deinit
It is not longer valid and may cause use-after-free if used after
decoder itself is destroyed.

Fixes: #14051
2024-05-04 11:20:38 +02:00
Shreesh Adiga
d9c5aef98d vf_gpu: vulkan and egl implementations
Abstract out EGL, and allow choosing between EGL and vulkan at runtime.
vf_gpu_egl.c contains GL specific context and creation/destroy code,
vf_gpu_vulkan.c contains Vulkan specific. This allows vf_gpu being
built in systems where EGL is not available and where Vulkan is
available.
2024-04-27 01:08:22 +02:00
Kacper Michajłow
a569c3ce0c player/command: add track-list/N/decoder 2024-04-18 01:20:32 +02:00
nanahi
9bb7d96bf9 various: make filter internal function names more descriptive
Lots of filters have generic internal function names like "process".
On a stack trace, all of the different filters use this name,
which causes confusion of the actual filter being processed.

This renames these internal function names to carry the filter names.
This matches what had already been done for some filters.
2024-04-10 19:00:22 +02:00
sfan5
a392f91170 meson: get rid of 'egl-helpers' feature
This was just redundant because it's always present together with 'egl'.
2024-03-21 18:27:08 +01:00
Kacper Michajłow
391261f757 mp_image: add mp_image_params_static_equal for finer comparision
In case of dynamic HDR metadata is present.
2024-03-09 05:58:52 +00:00
Dudemanguy
414ddbd628 filters/f_lavfi: rename channellayout to ch_layout
To better match upstream naming.
2024-03-08 22:55:37 +00:00
Dudemanguy
9ef614d6a3 swresample: stop using deprecated {in,out}_channel_layout options
These options were deprecated with the addition of the channel layout
API about a couple of years ago*. Unfortunately, we never saw the
deprecation messages so it went unnoticed until they were completely
removed with the recent major version bump. Fix this by setting
in_chlayout and out_chlayout instead if we have AV_CHANNEL_LAYOUT.

Fixes #13662.

*: 8a5896ec1f
2024-03-08 22:55:37 +00:00
Dudemanguy
78447c4b91 filters/f_lavfi: handle removed AV_OPT_TYPE_CHANNEL_LAYOUT
See: 65ddc74988
2024-03-07 22:03:55 +00:00
1nsane000
03bfd797f6 video/filter: add field order support for built in deinterlacers
refqueue gets the field of the frame from mp_image which almost always(if not
always) assumes bottom field order first. By default this behavior should not
change but specifying the field order should bypass this.
2024-03-04 17:41:40 -08:00
1nsane000
5b52d44972 f_auto_filters: pass field parity to lavfi bwdif deinterlacers
Since all of them(software, vulkan, cuda) already have a built in parity
parameter
2024-03-04 17:41:40 -08:00
sfan5
861e9566f6 video: don't define IMGFMT_VULKAN conditionally
We generally try to avoid that due to the #ifdef mess.
The equivalent format is defined in ffmpeg 4.4 while our interop code
requires a higher version, but that doesn't cause any problems.
2024-02-26 17:37:20 +01:00
nanahi
aa100d1512 f_output_chain: prevent double free of child filters
When mp_output_chain_update_filters() fails, talloc_free() is called on
each mp_user_filter. But because the structure doesn't have a talloc
destructor, the args aren't freed, resulting in stale references.

Fix this by calling the destructor of the wrapped filter instead.
2024-02-08 18:16:21 +01:00
Dudemanguy
003fb15cbb player/command: add deinterlace-active property 2024-02-07 14:50:09 +00:00
Dudemanguy
8dbbc2ad82 player: add an auto option to deinterlace
Deinterlacing required that the user set it on/off themselves, but we
actually have handy flags for detecting if a frame is interlaced. So
it's pretty simple to make an auto option using that. Unfortunately,
life is not quite that simple and there are known cases of false
positives from the ffmpeg flags so we can't make auto the default value.
However, it still may have some utility for some people, and the
detection could potentially be improved upon later. Closes #10358.
2024-02-07 14:50:09 +00:00
llyyr
d00a00e180 f_lavfi: use libplacebo utils instead of mp_csp_* 2024-01-22 15:23:13 +00:00
Kacper Michajłow
66e451f4e6 csputils: replace mp_colorspace with pl_color_space 2024-01-22 14:54:55 +00:00