summaryrefslogtreecommitdiffstats
path: root/demux
Commit message (Collapse)AuthorAgeFilesLines
* player: add track-list/N/image sub-propertyGuido Cella2021-10-145-1/+9
| | | | | | | | | | | | | | | | | | | | | | This exposes whether a video track is detected as an image, which is useful for profile conditions, property expansion and lavfi-complex. The lavf demuxer sets image to true when the existing check detects an image. When the lavf demuxer fails, the mf one guesses if the file is an image by its extension, so sh->image is set to true when the mf demuxer succeds and there's only one file. The mkv demuxer just sets image to true for any attached picture. The timeline demuxer just copies the value of image from source to destination. This sets image to true for attached pictures, standalone images and images added with !new_stream in EDL playlists, but it is imperfect since you could concatenate multiple images in an EDL playlist (which should be done with the mf demuxer anyway). This is good enough anyway since the comment of the modified function already says it is "Imperfect and arbitrary".
* demux_lavf: improve image detectionGuido Cella2021-10-141-9/+9
| | | | | | | | | | | | | | | | | | | | This moves the image check to where the number of frames is available of comparison, which allows not detecting jpg and png videos as images, and detecting 1-frame gifs as images. This works with the mjpeg and png videos in the FATE suite, though unfortunately the bmp video is still detected as an image since it has nb_frames = 0. aliaspix streams are also now considered images. Attached pictures are now treated like standalone images, so audio with attached pictures now has mf-fps as container-fps instead of unavailable, which makes it consistent with external cover art, which was already being assigned mf-fps. Unfortunately images in a codec commonly used for videos are never detected, and detection was inaccurate even using the now private codec_info_nb_frames field in AVStream, and mediainfo gets them wrong too, so I guess it's just a lost cause.
* Revert "player: add track-list/N/image sub-property"Jan Ekström2021-10-025-42/+10
| | | | | | | | Unfortunately, this functionality in large part based on a struct member that was made private in FFmpeg/FFmpeg@7489f632815c98ad58c3db71d1a5239b5dae266c in May. Unfortunately, this was not noticed during review. This reverts commit 0862664ac952d21fef531a8923a58ae575268fc5.
* player: add track-list/N/image sub-propertyGuido Cella2021-10-025-10/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This exposes whether a video track is detected as an image. This is useful for profile conditions, property expansion and lavfi-complex, and is more accurate than any detection even Lua scripts can perform, since they can't differentiate between images and videos without container-fps and audio and with duration 1 (which is the duration set by the mf demuxer with the default --mf-fps=1). The lavf demuxer image check is moved to where the number of frames is available for comparison, and is modified to check the number of frames and duration instead of the video codec. This doesn't misdetect videos in a codec commonly used for images (e.g. mjpeg) as images, and can detect images in a codec commonly used for videos (e.g. 1-frame gifs). pix files are also now detected as images, while before they weren't since the condition was checking if the AVInputFormat name ends with _pipe, and alias_pix doesn't. Both nb_frames and codec_info_nb_frames are checked because nb_frames is 0 for some video codecs (hevc, av1, vc1, mpeg1video, vp9 if forcing --demuxer=lavf), and codec_info_nb_frames is 1 for others (mpeg, mpeg4, wmv3). The duration is checked as well because for some uncommon codecs and containers found in FFMpeg's FATE suite, libavformat returns nb_frames = 0 and codec_info_nb_frames = 1. For some of them it even returns duration = 0, so they are blacklisted in order to never be considered images. The extra codecs that would have to be blacklisted without checking the duration are AV_CODEC_ID_4XM, AV_CODEC_ID_BINKVIDEO, AV_CODEC_ID_DSICINVIDEO, AV_CODEC_ID_ESCAPE130, AV_CODEC_ID_MMVIDEO, AV_CODEC_ID_NUV, AV_CODEC_ID_RL2, AV_CODEC_ID_SMACKVIDEO and AV_CODEC_ID_XAN_WC3, while the containers are film-cpk, ivf and ogg. The lower limit for duration is 10 because that's the duration of 1-frame gifs. Streams with codec_info_nb_frames 0 are not considered images because vp9 and av1 have nb_frames = 0 and codec_info_nb_frames = 0, and we can't rely on just the duration to detect them because they could be livestreams without an initial duration, and actually even if we could for these codecs libavformat returns huge negative durations like -9223372036854775808. Some more images in the FATE suite that are really frames cut from a video in an uncommon codec and container, like cine/bayer_gbrg8.cine, could be detected by allowing codec_info_nb_frames = 0, but then any present and future video codec with nb_frames = 0 and codec_info_nb_frames = 0 would need to be added to the blacklist. Some even have duration > 10, so to detect these images the duration check would have to be removed, and all the previously mentioned extra codecs and containers would have to be added added to the blacklists, which means that images that use them (if they exist anywhere) will never be detected. These FATE images aren't detected as such by mediainfo either anyway, nor can a Lua script reliably detect them as images since they have container-fps and duration > 0 and != 1, and you probably will never see files like them anywhere else. For attached pictures the lavf demuxer always set image to true, which is necessary because they have duration > 10. There is a minor change in behavior for which audio with attached pictures now has mf-fps as container-fps instead of unavailable, but this makes it consistent with external cover art, which was already being assigned mf-fps. When the lavf demuxer fails, the mf one guesses if the file is an image by its extension, so sh->image is set to true when the mf demuxer succeds and there's only one file. Even if you add a video's file type to --mf-type and open it with the mf protocol, only the first frame is used, so setting image to true is still accurate. When converting an image to the extensions listed in demux/demux_mf.c, tga and pam files are currently the only ones detected by the mf demuxer rather than lavf. Actually they are detected with the image2 format, but it is blacklisted; see d0fee0ac33a. The mkv demuxer just sets image to true for any attached picture. The timeline demuxer just copies the value of image from source to destination. This sets image to true for attached pictures, standalone images and images added with !new_stream in EDL playlists, but it is imperfect since you could concatenate multiple images in an EDL playlist (which should be done with the mf demuxer anyway). This is good enough anyway since the comment of the modified function already says it is "Imperfect and arbitrary".
* demux_mkv: enable AVCodec parser timestamp usage for parsed audioDan Oscarsson2021-09-211-0/+4
| | | | | | | | | Without this, cases where the parser cannot return data right away will end up utilizing the following fed packet's timestamps. This will in turn cause an unnecessary offset in the audio stream timestamps. An example of such buffered parser in libavcodec is the EAC3 one.
* demux_playlist: extend maximum line size (again) to 2MAvi Halachmi (:avih)2021-09-061-1/+1
| | | | | | | | | | | | | | | | | | Last time it was extended was de3ecc60 from 8K to 512K two years ago. The issue currently is that youtube EDL files can get very big. Size of about 520K (one line), was observed, at the time of writing: mpv https://youtube.com/watch?v=DBzFQgSMHdQ --ytdl-format=299 ytdl_hook.lua is unaffected by this because EDL lists don't go through the file reader at demux_playlist.c (where each line was limited to 512K before this commit), however, EDL files on disk which are loaded with --playlist=file.edl do. Increase the limit to 2M so that such EDL files can also be loaded from disk. Fixes #9186
* demux: acquire lock before calling update_bytes_readShreesh Adiga2021-07-131-2/+2
| | | | | | | | in->byte_level_seeks field is written and modified inside update_bytes_read at the same time when demux_get_reader_state is executing, which locks the demux thread mutex. This results in a data race, reported by Thread Sanitizer when playing mp3 file of sufficient long length.
* recorder: add support for attachments (fonts)TheAMM2021-07-081-1/+10
| | | | | | Though, only when the output format is matroska, to avoid muxing errors. This is quite useful when the input has ASS subtitles, as they tend to rely on embedded fonts.
* demux, dump-cache: fix demux cache range sortingTheAMM2021-07-081-2/+2
| | | | | | | dump_cache() calls qsort() to order an array of pointers, while the comparator forgets it's receiving pointers to pointers. Since cache-dumping over multiple cache ranges is fairly rare, this seems to have gone unnoticed.
* edl: add a way to add tagsYour Name2021-05-111-1/+16
| | | | | | | | Add new header which shows up as tags/metadata (associated with --display-tags). The way this is added means it doesn't always work, because root->meta (see code) can be NULL for some absurd reason. But it works for the one case I intended to use it (ytdl_hook, see next commit), though only in default configurations.
* build: address AVCodec, AVInputFormat, AVOutputFormat const warningssfan52021-05-011-2/+2
| | | | FFmpeg recently changed these to be const on their side.
* demux_lavf: fix minor memory leaksrland jon2021-04-201-0/+2
|
* demux: undeprecate --cache-secssfan52021-04-081-2/+1
| | | | | It serves a purpose and a rework of the cache won't be coming anytime soon. This partially reverts commit 8427292eb7c4074e1205c3d73c53c9e82569325f.
* demux_mf: improve format string processingAvi Halachmi (:avih)2021-04-051-2/+37
| | | | | | | | | | | | | | | | | | | | | Before this commit, the user could specify a printf format string which wasn't verified, and could result in: - Undefined behavior due to missing or non-matching arguments. - Buffer overflow due to untested result length. The offending code was added at commit 103a9609 (2002, mplayer svn): git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4566 b3059339-0415-0410-9bf9-f77b7e298cf2 It moved around but was not modified meaningfully until now. Now we reject all conversion specifiers at the format except %% and a simple subset of the valid specifiers. Also, we now use snprintf to avoid buffer overflow. The format string is provided by the user as part of mf:// URI. Report and initial patch by Stefan Schiller. Patch reviewed by @jeeb, @sfan5, Stefan Schiller.
* demux: Move demuxer help to new standard mechanismPhilip Langdale2021-03-282-2/+5
| | | | | Previously, demux help was handled as a special case in main.c and this is no longer necessary.
* demuxer/demux_mf: add support for more image codecsPaul B Mahol2021-02-061-0/+2
|
* demux: add function to refresh a track without (de-)selecting itsfan52020-11-272-0/+22
|
* demux_lavf: initialize ReplayGain dataMia Herkt2020-10-231-0/+2
| | | | | | | This was causing undefined behavior when playing streams without RG tags but with RG enabled. Broken in 585f9ff42f3195c. Thanks to uau for bisecting.
* Revert "demux: add a POS"wm42020-10-082-184/+0
| | | | | | This reverts commit 4f18e7927bacd2e887f8cca48a967804ce7adf86. It was a mistake, and barely anyone needs this.
* demux: add a POSwm42020-10-082-0/+184
| | | | | | I regret doing this so much, it's fucking garbage. Fixes: #5100
* command, demux: make drop-buffers reset state even harderwm42020-09-171-2/+9
| | | | Leave nothing left when it's executed.
* Revert "demux_lavf: always give libavformat the filename when probing"wm42020-08-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 41243e7c4f98b410195397b6758f9796acd9de57. This fixes image format detection. FFmpeg has an utter called "image2", which is designed to read patterns in filenames (so you can play something like "%*.jpg" for all jpg files in the current directory). "image2" is not what we want; it's just broken with custom I/O like mpv uses it, and we don't want to "accidentally" interpret filenames as pattern. That's why mpv blacklists it. Unfortunately, "image2" is sometimes the format that FFmpeg's probe API returns as best match. Thus demux_lavf fails to detect the file type, and after some more futile attempts, we end up at demux_mf, which uses detection by file extension. (Not sure why. I guess MPlayer did that, and foudn that sufficient.) If the file extension is wrong (which happens a lot because apparently the world is full of idiots who don't manage to get the most simple things right), the image "loads", but decoding obviously fails. There's no easy way around this. The FFmpeg API has no mechanism to exclude a specific format from probing (like image2, which breaks stuff for us). Out of the 5 probe functions the API provides, none can probe a specific format or include or exclude specific formats. The main problem is that AVInputFormat.read_probe is a private symbol. FFmpeg itself has no problem opening such files. It turns out that it works, because even though image2 by itself uses detection by file extension, it uses private API to further probe the exact format. It explicitly excludes itself to prevent recursion. But fortunately, that also means that it's impossible to get the image2 format if no filename is passed to the prober. (No filename, no file extension.) Apparently we pass it in because it helps in corner cases. Until almost 3 years ago, we passed the filename only when normal probing already failed. Restore this by this revert. It makes incorrectly named files work. The revert also makes the (apparently forgotten) comment above the touched line of code true again. Yes, quite possible that this breaks some mp3s again. You can't win with FFmpeg. Thanks FFmpeg for making us fail at opening simple image files and/or the most widely used file format for audio.
* demux_mf: actually report errorswm42020-08-221-0/+6
| | | | | | Well, whatever. Only results in an error message being printed, because there is no other error reporting mechanism, and the general policy is to keep trying with the rest of the data (i.e. not report EOF).
* demux_mkv: warn against some other aspects of mismatching codec datawm42020-08-161-0/+5
| | | | | | Such files violate the specification. Unfortunately, I could not test whether it really works correctly, since I don't have a sample at hand that is not broken in this regard.
* demux_lavf: workaround reading gif from unseekable streamswm42020-07-091-0/+19
| | | | | | | FFmpeg, being the pile of trash as usual, recently broke this. Add our own trash hack to trashily workaround this shit. Fixes: #7893
* build: change filenames of generated fileswm42020-06-042-2/+2
| | | | Force them into a more consistent naming schema.
* stream_libarchive: remember archive headers from initial openKevin Mitchell2020-04-281-1/+1
| | | | | | | | | | | | | | | | | | The header probing hacks were previously all broken. They only worked the first time the archive file was open. Since subsequent opens (on seek) occured in the middle of the source stream rather than at the beginning, the stream_read_peek calls meant to retrieve the headers were instead returning random bytes in the middle of the file. Perhaps the worst manifestation of this was when seeking within a multi-volume .rar archive with the "legacy" file naming pattern. If the seek required a reopen, the fact that the archive was multi-volume would be forgotten and the file would appear truncated terminating playback. To solve this, only perform the header probling the first time the archive is opened. Save the results and reuse them on subsequent reopens. Put this in a wrapper so this is transparent to demux_libarchive.
* demux_mkv: add png intra supportwm42020-04-161-0/+1
| | | | | | | Evil, non-standard shit. Sample file and script: https://github.com/mpv-player/random-stuff/tree/master/matroska/png
* demux_mkv: concatenate multiple tagswm42020-04-131-2/+8
| | | | | | | | | | | Instead of just picking the last tag that was encountered. The order of the tags still depends on the file order. This is probably wrong, and we should respect TargetTypeValue. But despite staring at the spec, I have no idea what the hell this should do, so fuck that. Fixes: #7604
* demux: don't let --sub-create-cc-track add a track for attached pictureswm42020-04-131-1/+1
| | | | | | | | Unfortunately, attached pictures (from tags etc.) are treated as video tracks. That meant --sub-create-cc-track added a CC track for them as well. Stop doing that. See: #7608
* options: cleanup .min use for OPT_CHANNELSwm42020-04-091-1/+1
| | | | | | | | Replace use of .min==1 with a proper flag. This is a good idea, because it has nothing to do with numeric limits (also see commit 9d32d62b61547 for how this can go wrong). With this, m_option.min/max are strictly used for numeric limits.
* stats: some more performance graphswm42020-04-091-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add an infrastructure for collecting performance-related data, use it in some places. Add rendering of them to stats.lua. There were two main goals: minimal impact on the normal code and normal playback. So all these stats_* function calls either happen only during initialization, or return immediately if no stats collection is going on. That's why it does this lazily adding of stats entries etc. (a first iteration made each stats entry an API thing, instead of just a single stats_ctx, but I thought that was getting too intrusive in the "normal" code, even if everything gets worse inside of stats.c). You could get most of this information from various profilers (including the extremely primitive --dump-stats thing in mpv), but this makes it easier to see the most important information at once (at least in theory), partially because we know best about the context of various things. Not very happy with this. It's all pretty primitive and dumb. At this point I just wanted to get over with it, without necessarily having to revisit it later, but with having my stupid statistics. Somehow the code feels terrible. There are a lot of meh decisions in there that could be better or worse (but mostly could be better), and it just sucks but it's also trivial and uninteresting and does the job. I guess I hate programming. It's so tedious and the result is always shit. Anyway, enjoy.
* demux: average reported download speed some morewm42020-03-211-1/+5
| | | | | | Currently, this reported the number of received bytes per second. Improve this slightly by averaging over 2 seconds (but still updating every second).
* options: fix OPT_BYTE_SIZE upper limitswm42020-03-181-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | As an unfortunate disaster, min/max values use the type double, which causes tons of issues with int64_t types. Anyway, OPT_BYTE_SIZE is often used as maximum for size_t quantities, which can have a size different from (u)int64_t. OPT_BYTE_SIZE still uses in64_t, because in theory, you could use it for file sizes. (demux.c would for example be capable of caching more than 2GB on 32 bit platforms if a file cache is used. Though for some reason the accounting code still uses size_t, so that use case is broken. But still insist that it _could_ be used this way.) There were various inconsistent attempts to set m_option.max to a value such that the size_t/int64_t upper limit is not exceeded. Due to the double max field, this didn't really work correctly. Try to fix this with the M_MAX_MEM_BYTES constant. It's a good approximation, because on 32 bit it should allow 2GB (untested, also would probably exhaust address space in practice but whatever), and something "high enough" in 64 bit. For some reason, clang 11 still warns. But I think this might be a clang bug, or I'm crazy. The result is correct anyway.
* demux_mkv: fix another integer/float conversion warningwm42020-03-181-1/+2
| | | | This code could assign INT64_MAX+1 (as double) to int64_t.
* options: change option macros and all option declarationswm42020-03-187-93/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change all OPT_* macros such that they don't define the entire m_option initializer, and instead expand only to a part of it, which sets certain fields. This requires changing almost every option declaration, because they all use these macros. A declaration now always starts with {"name", ... followed by designated initializers only (possibly wrapped in macros). The OPT_* macros now initialize the .offset and .type fields only, sometimes also .priv and others. I think this change makes the option macros less tricky. The old code had to stuff everything into macro arguments (and attempted to allow setting arbitrary fields by letting the user pass designated initializers in the vararg parts). Some of this was made messy due to C99 and C11 not allowing 0-sized varargs with ',' removal. It's also possible that this change is pointless, other than cosmetic preferences. Not too happy about some things. For example, the OPT_CHOICE() indentation I applied looks a bit ugly. Much of this change was done with regex search&replace, but some places required manual editing. In particular, code in "obscure" areas (which I didn't include in compilation) might be broken now. In wayland_common.c the author of some option declarations confused the flags parameter with the default value (though the default value was also properly set below). I fixed this with this change.
* options: change how option range min/max is handledwm42020-03-132-8/+11
| | | | | | | | | | | | | | | | | Before this commit, option declarations used M_OPT_MIN/M_OPT_MAX (and some other identifiers based on these) to signal whether an option had min/max values. Remove these flags, and make it use a range implicitly on the condition if min<max is true. This requires care in all cases when only M_OPT_MIN or M_OPT_MAX were set (instead of both). Generally, the commit replaces all these instances with using DBL_MAX/DBL_MIN for the "unset" part of the range. This also happens to fix some cases where you could pass over-large values to integer options, which were silently truncated, but now cause an error. This commit has some higher potential for regressions.
* demux: bump --cache-secs default valuewm42020-03-071-1/+1
| | | | | | Change to it 1000 hours, which is "infinite" enough. (Hesitant to use INFINITY, as that is not in the option's range. The option parser rejects it because it causes only problems in API users and so on.)
* demux: mark recently added debug option as deprecatedwm42020-03-071-1/+2
| | | | | It was the intention to remove it again after a release or two; mark it was deprecated so nobody thinks it gets to stay.
* demux: deprecate --cache-secswm42020-03-051-1/+2
| | | | | Because it's confusing and useless. If nobody complains, we'll have one weird cache configuration option less.
* demuxer-lavf: udp_multicast rtsp-transport optionmg2020-03-031-1/+4
|
* demux: another hack to deal with track switching refreshwm42020-02-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The demuxer cache employs a strange method to make track switching instant with caching enabled. Normally this would mean you have to wait until the cache has played out (and you get new packets, including packets from the newly selected track), or you have to perform a slow high level seek (decoding video again etc.). The strange method is that it performs a demuxer-level seek without a high level seek so it looks like a continuous stream to the decoder, and the newly select stream gets packets at the current playback position. This is called a refresh seek. This works only if some weird heuristics work. It needs a packet "unique ID", for which it uses either dts or pts. The value must be strictly monotonic increasing. If this doesn't work, the referesh seek can't be executed, and the user has to wait until the end of the cache. Sometimes there are files that simply do not work. In the present case, there's actually a hack that we can extend. Packets with unset position are likely generated by the parser, and the hack which this commit touches simply attempts to make up a new (hopefully unique) position value, even if the value itself makes no sense. It only ha to be deterministic. It turns out libavcodec sometimes output packets with repeating position values. This commit tries to handle this case too with the same hack. Fixes: #7498
* demux: add a way to block reading after seekswm42020-02-292-0/+7
| | | | | | Preparation for a future commit. The demuxer queues might be read from other threads than the one to issue the seek, and passing SEEK_BLOCK with such a seek will provide a convenient way to synchronize this.
* demux_lavf: don't interpret errors as EOFwm42020-02-281-3/+9
| | | | | | | | | | | | | | | It seems sporadic errors are possible, such as connection timeouts. Before the recent demuxer change, the demuxer thread retried many times even on EOF, so an error was only interpreted as EOF once the decoder queues ran out. Change it to use EOF only. Since this may actually lead to the demuxer thread being "stuck" and retrying forever (depending on libavformat API behavior), I'm also adding a heuristic to prevent this, using a random retry counter. This should not be necessary, but libavformat cannot be trusted. (This retrying forever could be stopped by the user, but obviously