Commit Graph

1549 Commits

Author SHA1 Message Date
Kacper Michajłow
a1424d5fe0 demux/ebml: fix ebml_read_length()
Fixes reading EMBL sizes in some files and makes this function readable
while at it.

Would be good to inline mp_log2(), but should be good enough.

Fixes: #15691
2025-01-27 18:50:59 +01:00
Kacper Michajłow
497310a235 Revert "demux_edl: disallow nested edl to avoid infinite loop"
Apparently there are some scripts that use nested edls instead of
flattening them first, so let's live with this.

This reverts commit de42e11662.
2025-01-04 16:13:07 +01:00
Kacper Michajłow
59d1dc43b9 various: fix typos 2025-01-04 15:59:49 +02:00
Kacper Michajłow
85b8493aad demux_mkv: cast to u32 before shift to fix int overflow 2024-12-28 17:52:37 +01:00
Guido Cella
e696b75f57 options: add --playlist-exts
And add playlist to --directory-filter-types' default.

Fixes
https://github.com/mpv-player/mpv/issues/15096#issuecomment-2466695186,
fixes https://github.com/mpv-player/mpv/discussions/15508
2024-12-28 14:24:00 +01:00
Guido Cella
114bdc24f2 options: add --archive-exts
And add archive to --directory-filter-types' default.

Fixes #15550, fixes #15096.
2024-12-28 14:24:00 +01:00
Guido Cella
2756a780b2 demux_lavf: remove obsolete defines
AV_DISPOSITION_TIMED_THUMBNAILS was added in FFmpeg 3.2 and
AV_DISPOSITION_STILL_IMAGE in FFmpeg 4.1, and we require FFmpeg 6.1.
2024-12-17 20:05:20 +00:00
Guido Cella
7715e2e255 demux_lavf: detect heif/heic as images
Like 565e7d906c did for avif, consider 1-frame HEVC as images, as HEVC
videos have nb_frames 0 or > 1.

Specifically, in the FATE suite:

nb_frames = 0 and are images:
cbf_cr_cb_TUDepth_4_circle.h265 food.hevc hdr10_plus_h265_sample.hevc
hdr_vivid_h265_sample.hevc hevc-monochrome.hevc

nb_frames = 0 and are videos:
mv_nuh_layer_id.bit paired_fields.hevc
paramchange_yuv420p_yuv420p10.hevc pir.hevc

nb_frames > 0:
dv84.mov extradata-reload-multi-stsd.mov multiview.mov
two_first_slice.mp4

As with other video codecs, the hevc images with nb_frames = 0 which are
really frames cut from a video are not detected as images, but you will
only find these files in FATE.
2024-12-17 20:05:12 +00:00
Kacper Michajłow
5897b66454 demux_mkv: limit EBML size to 64 MiB for fuzzing
OSS-Fuzz is limited to 2GiB of process memory, so allocating 512 MiB is
not working well and causing OOMs.
2024-12-12 01:45:19 +01:00
Kacper Michajłow
63e6dfba6e demux_mkv: fix memory leak of codec params
Fixes: 84ee84abb8
2024-12-09 20:46:48 +02:00
Jan Ekström
1b1a8a3e4f demux_lavf: simplify replaygain export
* Early exit if there is no useful data in the AVReplayGain
  structure (FFmpeg does check that gain of at least one thing is
  not INT32_MIN, but leaves the peak unchecked so it can be zero).
* Less depth in the if structure.
2024-12-05 01:21:38 +01:00
Jan Ekström
1f86733bb3 demux_lavf: utilize side data getter for replaygain
This simplifies the code, not requiring a loop.

Moves the getter definition somewhat upwards to allow
for its usage in a function that was defined before it.
2024-12-05 01:21:38 +01:00
Kacper Michajłow
91f1f4ff43 demux_disc: add playlist filename to edition title if available 2024-12-04 14:51:53 +01:00
Kacper Michajłow
de951c383b demux_disc: expose titles as editions
This allows to select DVD/Blu-Ray title easily. Titles are listed as
editions with their duration and number.

I wanted to include Angles also in this selection, but currently Angles
are not that well supported, so let's stick with titles and leave the
rest for the future changes.

We might migrate to lavf demuxer for DVD/Blu-Ray in the future, the mpv
implementation is rotted anyway.

Fixes #14586
2024-12-04 14:51:53 +01:00
Jan Ekström
17e62fcc61 demux/stheader: update lav_codecpar's comment
Was already being utilized by demux_raw, and now also created in
demux_mkv.
2024-12-02 21:03:21 +01:00
Jan Ekström
84ee84abb8 demux_mkv: propagate global stream side data via codecpar
The first AVPacket method has been deprecated in FFmpeg, and only
the HEVC decoder would read this information from there. The native
AV1 decoder as well as the libdav1d wrapper only support the newer
propagation method via codec context's side data. {ad,sd,vd}_lavc
call mp_set_avctx_codec_headers which copies the side data from
codecpar to codec context, so no changes are required on the
receiving end.
2024-12-02 21:03:21 +01:00
Jan Ekström
ba37142ba4 demux_lavf: stop global stream side data injection to AVPacket
This process has been deprecated since avformat 60.15.100 and
since avcodec 60.30.101 AV_PKT_DATA_DOVI_CONF has been read from
AVCodecContext's coded_side_data. Additionally, the HEVC decoder
is the only one which currently reads this side data from packets,
the native AV1 decoder as well as the libdav1d wrapper instead only
support the newer propagation method via codec context's side data.

How this currently is supposed to propagate is:
* demux_lavf copies the codec parameters into sh_stream's lav_codecpar.
* {ad,sd,vd}_lavc call mp_set_avctx_codec_headers that calls
  avcodec_parameters_to_context, which then sets global side data
  to the codec context.

As this logic is already in place, so no additional changes are required
for things to work and the deprecated function call can just be
cleaned up.

Ref: FFmpeg/FFmpeg@5432d2aaca
Ref: FFmpeg/FFmpeg@804be7f9e3
Ref: FFmpeg/FFmpeg@12e5116872
2024-12-02 21:03:21 +01:00
Kacper Michajłow
eb16169b27 demux_playlist: add data:// to self-expanding protocols
Found by OSS-Fuzz.
2024-11-02 01:40:41 +01:00
Kacper Michajłow
de42e11662 demux_edl: disallow nested edl to avoid infinite loop
Found by OSS-Fuzz.
2024-11-02 01:40:41 +01:00
llyyr
c5561b8e09 demux_playlist: fix comparison for current file if it's in current dir
When the file is in the current working directory, stream->path points
the path user passed as arg, so it may or may not include './'.

Strip it from both to make the comparison work

Fixes: c201c4874d
2024-10-24 12:34:58 +02:00
nanahi
dd23bf1555 demux_playlist: use STREAM_READ_FILE_FLAGS_DEFAULT 2024-10-22 03:16:51 +03:00
Kacper Michajłow
c201c4874d demux_playlist: ensure the file is added to autocreated playlist
Even if it doesn't match extensions in filter mode.
2024-10-08 19:57:16 +02:00
Dudemanguy
d54e8c3f40 demux_mkv: drop image probing down to 10000 blocks
It turns out that probing too many blocks is bad. I did not attempt to
go through all the logic but reading that many blocks causes the
demux_reader_state have some pretty funny values which then makes the
playloop think it needs to buffer for cache. It's probably fixable...
but seems hard admittedly so I'll be lazy. Just take out a magnitude off
the probing down to 10000. These seems to be more than sufficient. The
sample in #13975 where we had the opposite issue only needs somewhere
between 1700 and 1750 blocks to be properly detected. Crudely looking
at the demuxer values, 10000 here doesn't appear to alter anything
meaningfully so it does not have the "too many blocks problem".
Hopefully this is a perfect medium? Further improvements to the probe
can always be added later. Or maybe we decide this is all a giant
mistake and delete it. Fixes #14924.
2024-09-26 02:55:35 +00:00
Kacper Michajłow
c9f3fa33a6 demux_mkv: add missing color repr init
Fixes: 66e451f4e6
2024-09-25 19:35:21 +02:00
llyyr
d84a7c5112 stream: don't mark stdin as a filesystem file
Also rename the field to appropriately reflect what it is supposed to be
used for. The only other use of this was to search for ordered chapter
sources, and that makes no sense for mkv files from stdin.

This also fixes autocreate-playlist loading in the current directory
when the input file is stdin.
2024-09-14 16:17:44 +02:00
Kacper Michajłow
b6f0599bfd demux_mkv: fix av_parser_codec leak 2024-08-22 18:13:53 +02:00
Kacper Michajłow
4e50da3ddc demux_playlist: use --directory-filter-types for --autocreate-playlist 2024-08-10 23:27:40 +02:00
Kacper Michajłow
73b58722e7 player/misc: add str_in_list() and use it 2024-08-10 23:27:40 +02:00
Kacper Michajłow
b73445dcf3 demux_playlist: add only media files when opening directory 2024-08-10 23:27:40 +02:00
Kacper Michajłow
44a3a3293f options: add --{video,audio,image}-exts 2024-08-10 23:27:40 +02:00
Kacper Michajłow
4f1e9e34c3 demux_playlist: add --directory-filter-types 2024-08-10 23:27:40 +02:00
Kacper Michajłow
c54ad6933b demux_playlist: add --autocreate-playlist-{video,audio,image}-exts 2024-08-10 23:27:40 +02:00
Kacper Michajłow
bb9b862f0c demux: add --autocreate-playlist 2024-08-10 23:27:40 +02:00
Kacper Michajłow
aa35f2e4bd demux_mf: disable glob for fuzzing 2024-08-04 21:33:36 +02:00
Kacper Michajłow
4764e41cac demux/ebml: bump ebml size limit to 512 MiB
While the code before 571f9b0f23 had a
typo and it was intended to be 100 MB, there are files that exceed this
limit, like 147 MiB. Increase the limit to 512 MiB which should be more
than enough for valid files.

From quick look ffmpeg limits to 1<<8 bytes, so we should be good with
our new limit.

In theory this limit could be removed, but it is better to play the
file, possibly with skipped some corrupted block of data, instead OOM.

Fixes: 571f9b0f23
2024-07-15 17:38:22 +02:00
Kacper Michajłow
024c79a53c demux_mf: don't run glob() on urls
Not intended to be run on urls. Fixes stack-overflow in glob() when
unexpected data is passed.

Found by OSS-Fuzz.
2024-07-12 22:38:18 +02:00
Guido Cella
c2fc6503fb demux_mf: support URLs in @listfile and filemask
This allows playing arguments like
mf://https://foo.jpg,https://bar.jpg
and also URLs within @listfiles (files with 1 image per line).

URLs still don't work with globs and printf-formats.
2024-07-12 22:37:34 +02:00
Kacper Michajłow
9158653982 demux_mkv: ignore duplicated BlockAdditions to avoid memory leak
This can happen only on invalid files.

Found by OSS-Fuzz.
2024-07-11 03:48:25 +02:00
Kacper Michajłow
66fdec8a67 demux_edl: don't try to extract dirname from self-expanding protocols
Fixes infinite recursion. Trying to extract dirname from string of
memory://<data> is not really a good idea.

Found by OSS-Fuzz.
2024-07-11 03:48:25 +02:00
Kacper Michajłow
571f9b0f23 demux/ebml: fix ebml size check
There was one zero too many. Change the limit to 128 MiB with more
readable notation.
2024-07-09 20:58:39 +02:00
nanahi
33e414fa5d demux: avoid seeking video streams for refresh seek
940854c86f added this logic, but when the
demuxer contains a selected video stream, it causes a seek for the video
stream. This is unnecessary since the problems that commit fixed are only
relevant for external audio streams. For a demuxer with a video stream
selected, the synchronization is done by the demuxer implementation.
Add a check to prevent this.
2024-07-04 22:23:27 +00:00
nanahi
c461ea6cd1 demux: don't log if track isn't refreshed
Also use demux_internal type for the refresh_track in style of other
internal functions.
2024-07-04 22:23:27 +00:00
Kacper Michajłow
2b1e9a6537 demux_playlist: don't add base path to self-expanding protocols
Adding base path make sense only if it is a real directory or url
location. In case of protocols like memory adding base path to playlist
entry in facts adds the whole playlist to that entry.

For example `mpv $'memory://#EXTM3U\na/b'` produces infinite loop,
expanding playlist, adding more to it.

open_file adds the dirname to support relative playlist enties, however,
the dirname is invalid when the name doesn't represent a path, such as
with memory://..., so avoid taking the dirname with such protocols.

Found by OSS-Fuzz.
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
nanahi
940854c86f demux: allow refresh seek for non-video streams
Since d41f0a54b0, enabling a stream will
no longer perform a refresh seek, to fix issues with switching video
tracks. Additionally, 62e9a0c5f6 also
prevents refresh seek on track switching when it happens right after a
seek.

Unfortunately, when external audio files are loaded, preventing refresh
seeks can cause A-V sync issues. Since external tracks have separate demuxer
instances from the internal tracks, the demuxer instances from both
internal and external tracks are explicitly sought to the same pts when
seeking is performed. When enabling an external audio track for the first
time, the existing logic prevents refresh seek because no packets have ever
been read, so the track ends up not being sought. This means that switching
the track in the middle of playback results in a huge A-V desync.

To make it worse, unlike one demuxer instance with multiple tracks,
tracks from multiple demuxer instances are not synced in any meaningful
way beyond the separate explicit seeking. The only thing which keeps these
tracks synced is the generic A-V sync logic, which is unfit for such large
desync above. This means the audio is at the start position after the track
is switched, behind the video, so the audio is not considered ready, and
audio is continuously filtered sequentially until it is synced to the video.
While this is happening, the audio filtering exhausts all CPU resources.

There is also a case with cache enabled: if a seek causes some new data to
be cached, the demuxer is sought to the end of joined cache range.
If track is switched after this, the existing logic prevents a refresh seek,
so the demuxer is at a wrong position after the track is switched.

Fix this by allowing refresh seek for non-video streams, even when no packets
have been read yet or immediately after a seek.
2024-06-22 18:21:28 +00: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
Kacper Michajłow
c194f2dc32 demux_edl: fix infinite loop on empty EDL files
"file" is implicit key, it is always available, so we have to check if
it is not empty.

Found by OSS-Fuzz.

Fixes: 96ef62161a
2024-06-18 03:11:14 +02:00
Kacper Michajłow
6c908363cd demux_lavf: fix null derefence of stream variable
demux_stream_is_selected() already checks if stream is valid, so move
the image format hack check after that.

Fixes: 4ef7931266
2024-06-15 18:08:16 +02:00
nanahi
3fa09458da demux_lavf: add format hack entry for jpeg metadata frames 2024-06-14 17:16:19 +00:00