Commit Graph

319 Commits

Author SHA1 Message Date
Nicolas F 4d1269d9db demux_mkv: add A_MLP to mkv_audio_tags
Fixes #5923
2018-06-22 21:17:26 +03:00
wm4 137e34e3e9 demux_mkv: adjust log verbosity levels
With -v -v ("debug" level), which is the default for --log-file, this
would log every damn Matroska EBML element and some other uninteresting
things, which was very noisy.

Adjust the log levels to make them less noisy. Also, change some log
calls to MP_ERR for things which are actually errors.
2018-04-29 02:21:32 +03:00
wm4 4381753207 demux_mkv: fix certain cases of recursive SeekHeads
Some shittily muxed files (by a certain HandBrake+libavformat combo)
contain a SeekHead pointing to a SeekHead at the end of the file, which
in turn points to track headers (also at the end of the file). This
failed because the demuxer didn't bother to actually read the elements
listed by the second SeekHead, so no track headers were read, and
playback broke.

Somehow commit 6fe75c38 broke this for no reason. It adds a "needed"
field, which seems completely pointless and replaced the "parsed" flag
in an incomplete way. In particular, the "needed" field was not set when
a _recursive_ SeekHead was read, so those elements were not read. Just
get rid of the field and use "parsed" instead.
2018-04-15 21:03:49 +03:00
Jan Ekström c33faee6ba demux_mkv: add V_AV1 identifier for AV1
Quickly tested by a person who had FFmpeg linked with libaom.
Seems as simple as the VP9 mappings, where there is no extradata/
initialization data off-band, and just stuff in the packets
themselves.

Do note that the AV1 video format itself at this point is still
not frozen, so what you might produce one day might not be
decodable the following day.
2018-04-08 13:53:29 -07:00
wm4 6f27a165a8 demux_mkv: enable libavcodec parser for eac3
It appears some (or all) mkv files with EAC3 are muxed in a way that
breaks FFmpeg's spdifenc. I suspect it's because either dependent
substream packets are localted in their own packets, or the reverse. Or
possibly this is case where the muxer did not respect packet boundaries
at all. Enabling the EAC3 parser seems to fix this anyway, because why
waste your precious time on retarded Dolby bullshit technology? (Which
idiot came up with this shitty substream garbage?)

Observed with dolby_digital_plus_channel_check_lossless-DWEU.mkv.

Fixes #5578.
2018-03-03 02:38:01 +02:00
wm4 a9f97b26d8 Revert "demux_mkv: remove remaining GPL code"
This reverts commit b7f90be567.

The author agreed to the relicensing now (if that code is affected by
the original copyright at all - that was the only line possibly left of
it).
2018-01-31 03:54:59 +01:00
wm4 6827901230 ta: introduce talloc_dup() and use it in some places
It was actually already implemented as ta_dup_ptrtype(), but that seems
like a clunky name. Also we still use the talloc_ names throughout the
source, and I'd rather use an old name instead of a mixing inconsistent
naming conventions.
2018-01-18 01:42:36 -08:00
wm4 ff506c1e49 demux_mkv: fix x264 hack if video track uses header compression
The x264 hack requires reading the first video packet, which in turn we
handle with a hack in demux_mkv.c to get the packet without having to
add special crap to demux.c. Another useless MKV feature (which they
enabled by default at one point and which caused many demuxers to break
completely, only to disable it again when it was too late) conflicts
with this, because we actually pass a block as packet contents, instead
of after "decompression".

Fix this by calling demux_mkv_decode().
2017-12-30 00:37:58 -07:00
wm4 5e50fe3049 demux_mkv: add hack to pass along x264 version to decoder
This fixes when resuming certain broken h264 files encoded by x264. See
FFmpeg commit 840b41b2a643fc8f0617c0370125a19c02c6b586 about the x264
bug itself.

Normally, the unregistered user data SEI (that contains the x264 version
string) is informational only. But libavcodec uses it to workaround a
x264 bug, which was recently fixed in both libavcodec and x264. The fact
that both encoder and decoder were buggy is the reason that it was not
found earlier, and there are apparently a lot of files around created by
the broken decoder. If libavcodec sees the SEI, this bug can be worked
around by using the old behavior.

If you resume a file with mpv (i.e. seeking when the file loads),
libavcodec never sees the first video packet. Consequently it has to
assume the file is not broken, and never applies the workaround,
resulting in garbage being played.

Fix this by always feeding the first video packet to the decoder on
init, and then flushing the codec (to avoid that an unwanted image is
output). Flushing the codec does not remove info such as the x264
version. We also abuse the fact that the first avcodec_send_packet()
always pushes the frame into the decoder (so we don't have to trigger
the decoder by requsting an output frame).
2017-12-28 00:59:22 -07:00
wm4 f6a582e0b2 demux_mkv: maintain a small packet read queue
This is less of a mess than the single-item queue in tmp_block, and also
might help us in the future.
2017-12-28 00:59:22 -07:00
wm4 30686dcec3 demux_mkv: fix off by one error
Caused by the relatively recent change to packet parsing. This time it
was probably triggered by lace type 0, which reduces the byte length of
a 0 sized packet to 3 (timestamp + flag) instead of 4 (lace count for
other lace types). The thing about laces is just my guess why it worked
for other 0 sized packets, though.

Also remove the redundant and now incorrect check below.

Fixes #5271.
2017-12-23 14:07:21 -07:00
wm4 cd6f964b56 demux_mkv: remove unnecessary parsing for vp9
We can finally get rid of this crap.

Depends on a ffmpeg-mpv change. Always worked with Libav (ever since
they fixed it properly).
2017-11-17 14:18:57 +01:00
wm4 618b8a33e5 demux_mkv: fix potential uninitialized variable read 2017-11-10 12:49:53 +01:00
wm4 e598b19dad demux_mkv: allow 0 sized packets
Fixes some obscure sample that uses fixed size laces with 0-sized lace
size. Some broken shit. (Maybe the decoder wouldn't care about these
packets, but the demuxer attempted to resync after these packet reading
errors, even though they were perfectly recoverable. But I don't care
enough about this.)

Sample link: https://samples.ffmpeg.org/Matroska/switzler084d_dl.mkv
2017-11-06 17:12:58 +01:00
wm4 9e1fbffc37 demux_mkv: rewrite packet reading to avoid 1 memcpy()
This directly reads individual mkv sub-packets (block laces) into a
dedicated AVBufferRefs, which can be directly used for creating packets
without a additional copy of the packet data. This also means we switch
parsing of block header fields and lacing metadata to read directly from
the stream, instead of a memory buffer.

This could have been much easier if libavcodec didn't require padding
the packet data with zero bytes. We could just have each packet
reference a slice of the block data. But as it is, the only way to get
padding without a copy is to read the laces into individually allocated
(and padded) memory block, which required a larger rewrite.

This probably makes recovering from broken mkv files slightly worse if
the transport is unseekable. We just read, and then check if we've
overread. But I think that shouldn't be a real concern.

No actual measureable performance change. Potential for some
regressions, as this is quite intrusive, and touches weird obscure shit
like mkv lacing. Still keeping it because I like how it removes some
redundant EBML parsing functions.
2017-11-05 18:13:34 +01:00
Nicolas F e6a68e2330 demux_mkv: add V_SNOW tag to mkv_video_tags
Apparently, and to nobody's surprise, mkv can contain snow. It does
so with the V_SNOW tag. We can now play back snow-inside-mkv in mpv.
2017-11-03 01:03:39 +01:00
wm4 3413fe4dfd demux_mkv: don't probe start time by default
It isn't all that reliable, and improving it would make startup slower
and require more complexity. There isn't even a good reason to do this
(other than semi-broken mkv files), so don't do it. Also see previous
commit.
2017-10-27 18:41:47 +02:00
wm4 dbd22f43be demux: drop redundant SEEK_BACKWARD flag
Seems like most code dealing with this was for setting it in redundant
cases. Now SEEK_BACKWARD is redundant, and SEEK_FORWARD is the odd one
out.

Also fix that SEEK_FORWARD was not correctly unset in try_seek_cache().

In demux_mkv_seek(), make the arbitrary decision that a video stream is
not required for the subtitle prefetch logic to be active. We might want
subtitles with long duration even with audio only playback, or if the
file is used as external subtitle.
2017-10-23 19:05:39 +02:00
wm4 b7f90be567 demux_mkv: remove remaining GPL code
Fuck this thing.
2017-10-10 17:35:47 +02:00
wm4 4e5d7cbf21 demux_mkv: replace deprecated av_copy_packet_side_data()
It's deprecated, and av_packet_copy_props() is nearly equivalent. It's
also more widely supported.
2017-10-03 14:45:18 +02:00
wm4 028faacff5 video: add metadata handling for spherical video
This adds handling of spherical video metadata: retrieving it from
demux_lavf and demux_mkv, passing it through filters, and adjusting it
with vf_format. This does not include support for rendering this type of
video.

We don't expect we need/want to support the other projection types like
cube maps, so we don't include that for now. They can be added later as
needed.

Also raise the maximum sizes of stringified image params, since they
can get really long.
2017-08-21 14:56:07 +02:00
wm4 0e36b77aae demux_mkv: avoid an error message in a corner case
If --demuxer-mkv-probe-start-time=no is used, and a seek is triggered on
start, then cluster_start will be 0, and the packet reading code will
print an error message about not finding valid data. This fixes itself
since it invokes the resync code, but it's still pretty ugly. Avoid this
by always initializing cluster_start.
2017-08-08 15:19:50 +02:00
wm4 ddd068491c Replace remaining avcodec_close() calls
This API isn't deprecated (yet?), but it's still inferior and harder to
use than avcodec_free_context().

Leave the call only in 1 case in af_lavcac3enc.c, where we apparently
seriously close and reopen the encoder for whatever reason.
2017-07-16 12:51:48 +02:00
wm4 b0d13fa023 demux_mkv: fix broken initializer
Who says that the first member is an array or whatever? It depends on
whatever the matroska.py script generates.
2017-06-23 19:47:10 +02:00
Rudolf Polzer 66ec8ff67b demux_mkv: Fix warnings.
- Fix a signed/unsigned comparison involving info.segment_uid.len
  (doesn't actually warn here, but seems fragile). Code was previously
  safe though.
- Match up all printf format strings with the respective value types,
  using the *int*_t printf specifiers where necessary, and fixing
  multiple signed/unsigned differences. Removed some casts that
  otherwise may have truncated values.
- Fix a warning when initializing ebml_info.
2017-06-23 13:25:41 -04:00
Rudolf Polzer cad313beff demux_mkv: Fix "max_cll" warning.
On some platforms, unsigned long and uint64_t aren't the same type,
after all. As this is just a MP_VERBOSE message, risking truncation in
some cases seems OK.
2017-06-22 21:26:54 -04:00
wm4 1890529857 demux: get rid of DEMUXER_CTRL_GET_TIME_LENGTH
Similar purpose as f34e1a0dee.

Somehow this is much more natural too, and needs less code.

This breaks runtime updates to duration. This could easily be fixed, but
no important demuxer does this anyway. Only demux_raw and demux_disc
might (the latter for BD/DVD). For the latter it might actually have
some importance when changing titles at runtime (I guess?), but guess
what, I don't care.
2017-06-20 14:22:10 +02:00
wm4 f34e1a0dee demux: replace custom return codes with CONTROL_ ones
This is more uniform, and potentially gets rid of some past copyrights.

It might be that this subtly changes caching behavior (it seems before
this, it synced to the demuxer if the length was unknown, which is not
what we want.)
2017-06-19 17:56:51 +02:00
Niklas Haas deb9370779 vd: use ST.2086 / HDR10 MaxCLL in addition to mastering metadata
MaxCLL is the more authoritative source for the metadata we are
interested in. The use of mastering metadata is sort of a hack anyway,
since there's no clearly-defined relationship between the mastering peak
brightness and the actual content. (Unlike MaxCLL, which is an explicit
relationship)

Also move the parameter fixing to `fix_image_params`

I don't know if the avutil check is strictly necessary but I've included
it anyway to be on the safe side.
2017-06-18 20:54:44 +02:00
Niklas Haas c335e84230 video: refactor HDR implementation
List of changes:

1. Kill nom_peak, since it's a pointless non-field that stores nothing
   of value and is _always_ derived from ref_white anyway.

2. Kill ref_white/--target-brightness, because the only case it really
   existed for (PQ) actually doesn't need to be this general: According
   to ITU-R BT.2100, PQ *always* assumes a reference monitor with a
   white point of 100 cd/m².

3. Improve documentation and comments surrounding this stuff.
4. Clean up some of the code in general. Move stuff where it belongs.
2017-06-18 20:48:23 +02:00
wm4 b6d0b57e85 Drop/move img_fourcc.h
This file is an leftover from when img_format.h was changed from using
the ancient FourCCs (based on Microsoft multimedia conventions) for
pixel formats to a simple enum. The remaining cases still inherently
used FourCCs for whatever reasons.

Instead of worrying about residual copyrights in this file, just move it
into code we don't want to relicense (the ancient Linux TV code). We
have to fix some other code depending on it. For the most part, we just
replace the MP_FOURCC macro with libavutil's MKTAG (although the macro
definition is exactly the same). In demux_raw, we drop some pre-defined
FourCCs, but it's not like it matters. (Instead of
--demuxer-rawvideo-format use --demuxer-rawvideo-mp-format.)
2017-06-18 15:13:45 +02:00
wm4 eae693fc46 demux_mkv: support FFmpeg A_MS/ACM extensions
Indeed, FFmpeg found a way to maximize the misery around VfW/AVI-style
muxing. It appears it can mux a number of random codecs by using random
format tags. To make this even more stranger, it has a probably custom
GUID for signaling them, although for unknown reasons this is done only
"sometimes" (judging from FFmpeg's riffenc.c).

Whatever, it's not too hard to support it. Also apparently fix the
incorrect interpretation of extended formats - there's absolutely no
reason to assume they're always PCM. Instead, check for the correct
GUIDs. Also while we're at it, move the channel mask handling also to
codec_tag.c, so all WAVEFORMATEXTENSIBLE handling is in one place. (With
the normal wav header handling strangely still in demux_mkv.c.)

The case I was looking at (aac_latm muxing) decodes now. While I'm not
entirely sure about its correctness (libavformat has a weird
special-case for SBR), it certainly doesn't try to play it as PCM,
which is much of an improvement.

The extradata mess in the demux_mkv.c A_MS/ACM code path is unfortunate
and ugly, but has less impact than refactoring all the code to make
this specific case nicer.

Did I mention yet that I hate VfW-style mkv muxing?
2017-06-03 22:49:15 +02:00
wm4 c443aa68d3 demux_mkv: vp9 alpha, second try
The parser is used to split superframes, and the decoder didn't like
when the blockadditional was duplicated on the second split packet.
2017-05-30 22:50:05 +02:00
wm4 3a448ab972 demux_mkv: fix alpha with vp9 + libvpx
The blockadditional side data gets lost because vp9 has to go through
the parser.
2017-05-30 19:26:27 +02:00
wm4 6fe75c38d8 demux_mkv: read headers at the end of the file sorted by position
Try to read header elements stored at the end of the file in the order
of their position. (It would be nicer if mkv simply told us a range of
elements to parse, but it doesn't do that.)

This can potentially reduce seek elements, although I didn't check if
any real files trigger this. The real contribution by this change is
that it does not defer reading the CUE index if we need to seek to the
end of the file anyway. This can actually avoid 2 seeks when opening a
file and --start is used, and the file has other headers elements at the
end of the file (like tags).
2017-05-15 16:40:57 +02:00
wm4 b78d2e6d09 demux_mkv: mention non-LGPL code 2017-04-21 13:34:10 +02:00
wm4 e7e6aa3d64 demux_mkv: change license to LGPL
Most contributors have agreed. This claims it's based on gstreamer code,
but this was LGPL at the time (and still is). Contributors whose code
was removed were not accounted for. There are still some potentially
problematic cases:

06eee1b67 is potentially the most problematic case. Most of these
changes are gone due to mpv not using BITMAPINFOHEADER anymore. Some
of the other changes are rather trivial. If someone contests this and
claims that copyrightable changes are left, the original change can
simply be reverted.

62bfae140 has only 2 lines left: a "char *name;" struct field, and a
line that prints a message. All other code was removed. The parsing code
in particular was made declarative, which replaced reading this element
explicitly (and  other elements, see 1b22101c77). I'm putting the log
message under HAVE_GPL, but I don't think the declaration is
copyrightable, or the mere concept of reading this element. Redoing the
other 2 lines of code would result in the  same program text.

d41e860ba was applied by someone who (potentially) disagreed. The patch
itself is from someone who did agree, though. It's unknown whether the
applier changed the patch. But it seems unlikely, and the change was
mostly rewritten.

50a86fcc3 all demux_mkv changes were reverted (old stdout slave mode)
3a406e94d same
2e40bfa13 the old MPlayer subtitle code was completely removed
316bb1d44 completely removed in 1cf4802c1d
87f93d9d7 same
11bfc6780 relative seeks were removed in 92ba630796
be54f4813 the corresponding demux_mkv code was removed in 5dabaaf093
efd53eed6 all internal vobsub handling is now in FFmpeg
d7f693a20 removed in f3db4b0b93
e8a1b3713 removed in 522ee6b783
cfb890259 removed, see 6b1374b203 for analysis
c80808b5a same
2017-04-21 12:21:33 +02:00
wm4 9c12d54afa demux_mkv: passthrough BlockAdditions for libvpx alpha
Dumb but simple thing. Requires the FFmpeg libvpx decoder wrapper, as
its native decoder doesn't support alpha.
2017-01-31 14:48:10 +01:00
wm4 c178920505 demux_mkv: any reference makes a frame not a keyframe
Fixes seeking with:

https://bugs.chromium.org/p/chromium/issues/detail?id=497889

Haali also ignores the element's contents, and interprets its presence
as the block not being a keyframe. FFmpeg is going to have an equivalent
change.

I don't know yet whether the affected sample is valid - a reference
timestamp of 0 doesn't make too much sense to me.
2017-01-31 12:44:49 +01:00
wm4 99a4be4127 demux_mkv: trust keyframe flags for TrueHD
TrueHD is a fucked up audio codec with extremely small frame sizes. Some
of these frames start with full headers, which are usually marked as
keyframes, and from which decoding can be started (or at least that's
what you'd expect).

So for such tracks we should probably trust the keyframe flags. Doesn't
really improve seek behavior, though.
2016-12-20 14:28:29 +01:00
wm4 3b5777d86a demux_mkv: fix seeking in some broken files
Some files have audio tracks with packets that do not have a keyframe
flag set at all. I don't think there's any audio codec which actually
needs keyframe flags, so always assume an audio packet is a keyframe
(which, in Matroska terminology, means it can start decoding from that
packet).

The file in question had these set:

| + Multiplexing application: Lavf57.56.100 at 313
| + Writing application: Lavf57.56.100 at 329

Garbage produced by garbage...

There are other such files produced by mkvmerge, though. It's not
perfectly sure whether these have been produced by FFmpeg as well
(mkvmerge often trusts the information in the source file, even if it's
wrong - so other samples could have been remuxed from FFmpeg).

Fixes #3920.
2016-12-19 21:29:46 +01:00
wm4 79d99bd264 demux_mkv: distinguish mp2 and mp3
demux_mkv.c has returned mp3 for mp2 since the initial commit. Normally
not a problem.
2016-11-23 15:57:35 +01:00
Niklas Haas c676c31815 demux: expose demuxer colorimetry metadata to player
Implementation-wise, the values from the demuxer/codec header are merged
with the values from the decoder such that the former are used only
where the latter are unknown (0/auto).
2016-11-08 19:16:26 +01:00
Niklas Haas 81ceb7b6a5 demux_mkv: parse colorimetry metadata
Matroska actually has lots of colorimetry metadata that video tracks can
use, including mastering metadata (HDR signal peak) etc.

This commit adds the EBML definitions and parses the most basic fields.
Note that nothing uses these fields yet, this commit is just adding the
necessary parsing and infrastructure.
2016-11-08 19:16:24 +01:00
Uoti Urpala 18681a7dd2 demux_mkv: fix ordered chapter sources with ordered editions
Commit f72a900892 (and others) added support for ordered editions that
recursively refer to other ordered editions. However, this recursion
code incorrectly activated if the source files had ordered chapters
even if the main file only wanted to use them as raw video, resulting
in broken timeline info overall.

Ordered chapters can specify a ChapterSegmentEditionUID value if they
want to use a specific edition from a source file. Otherwise the
source is supposed to be used as a raw video file. The code checked
demuxer->matroska_data.num_ordered_chapters for an opened source file
to see whether it was using a recursive ordered edition, but demux_mkv
could enable a default ordered edition for the file using the normal
playback rules even if the main file had not specified any
ChapterSegmentEditionUID. Thus this incorrectly enabled recursion if a
source file had a default edition using ordered chapters. Check
demuxer->matroska_data.uid.edition instead, and ensure it's never set
if a file is opened without ChapterSegmentEditionUID.

Also fix what seems like a memory leak in demux_mkv.c.

Signed-off-by: wm4 <wm4@nowhere>
2016-10-22 18:45:06 +02:00
wm4 d4d8b3a4fc demux: do not access global options
Don't access MPOpts directly, and always use the new m_config.h
functions for accessing them in a thread-safe way.

The goal is eventually removing the mpv_global.opts field, and the
demuxer/stream-layer specific hack that copies MPOpts to deal with
thread-safety issues.

This moves around a lot of options. For one, we often change the
physical storage location of options to make them more localized,
but these changes are not user-visible (or should not be). For
shared options on the other hand it's better to do messy direct
access, which is worrying as in that somehow renaming an option
or changing its type would break code reading them manually,
without causing a compilation error.
2016-09-06 20:09:56 +02:00
wm4 b9ba9a898a demux: add per-track metadata
...and ignore it. The main purpose is for retrieving per-track
replaygain tags. Other than that per-track tags are not used or accessed
by the playback core yet.

The demuxer infrastructure is still not really good with that whole
synchronization thing (at least in part due to being inherited from
mplayer's single-threaded architecture). A convoluted mechanism is
needed to transport the tags from demuxer thread to user thread. Two
factors contribute to the complexity: tags can change during playback,
and tracks (i.e. struct sh_stream) are not duplicated per thread.

In particular, we update the way replaygain tags are retrieved. We first
try to use per-track tags (common in Matroska) and global tags
(effectively formats like mp3). This part fixes #3405.
2016-08-12 21:39:32 +02:00
wm4 78bcbe289e demux: make refresh seek handling more generic
Remove the explicit whitelisting of formats for refresh seeks. Instead,
check whether the packet position is somewhat reliable during demuxing.
If there are packets without position, or the packet position is not
monotonically increasing, then do not use them for refresh seeks.

This does not make sure of some requirements, such as deterministic
seeks. If that happens, mpv will mess up a bit on stream switching.

Also, add another method that uses DTS to identify packets, and prefer
it to the packet position method. Even if there's a demuxer which
randomizes packet positions, it hardly can do that with DTS. The DTS
method is not always available either, though. Some formats do not have
a DTS, and others are not always strictly monotonic (possibly due to
libavformat codec parsing and timestamp determination issues).
2016-08-06 19:28:41 +02:00
wm4 a30e727266 demux_mkv: support Matroska webvtt
They're different from the Google/WebM subtitle types, and use a new
codec ID.

Fixes #3247.
2016-06-14 16:43:07 +02:00
wm4 035297212a demux_mkv: better resync behavior for broken google-created webms
I've got a broken webm that fails to seek correctly with "--start=0".
The problem is that every index entry points to 1 byte before cluster
start (!!!). demux_mkv tries to resync to the next cluster, but since it
already has read 2 bytes with ebml_read_id(), it doesn't get the first
cluster, but the following one. Actually, it can be any amount of bytes
from 1-4, whatever happens to look valid at this essentially random byte
position.

Improve this by resyncing from the original position, instead of the one
after the EBML element ID has been attempted to be read.

The file shows the following headers:

| + Muxing application: google at 177
| + Writing application: google at 186

Indeed, the file was downloaded with youtube-dl. I can only guess that
Google got it completely wrong.
2016-05-21 16:39:44 +02:00