summaryrefslogtreecommitdiffstats
path: root/demux/demux_lavf.c
Commit message (Collapse)AuthorAgeFilesLines
* demux_lavf: fix wrong printf parameter type on 64 bit systemswm42015-06-021-1/+1
| | | | | "f.len - 4" is size_t, not int. Fix by using BSTR_P() (and a bstr function to adjust the length).
* demux_lavf: do a better job at guessing the vobsub .sub filenamewm42015-05-281-0/+40
| | | | | | | | | | | Vobsubs come as .idx/.sub pair of files. The .idx file is the one that should be opened, but the name of the .sub file is unknown. We can now make our own guess what the name of that file is. In particular, improve support with URLs (as these can have the file extension in the middle of the filename string if there are HTTP parameters). Note that this works only with newer ffmpeg versions, because the recently added sub_name demuxer option is used for this.
* demux_lavf: drop dead codewm42015-04-251-7/+1
| | | | stream.url can never be NULL, although it probably used to be.
* player: change video-bitrate and audio-bitrate propertieswm42015-04-201-4/+0
| | | | | | | | | | | | | | Remove the old implementation for these properties. It was never very good, often returned very innaccurate values or just 0, and was static even if the source was variable bitrate. Replace it with the implementation of "packet-video-bitrate". Mark the "packet-..." properties as deprecated. (The effective difference is different formatting, and returning the raw value in bits instead of kilobits.) Also extend the documentation a little. It appears at least some decoders (sipr?) need the AVCodecContext.bit_rate field set, so this one is still passed through.
* demuxer_lavf: add an option for disabling hackswm42015-04-171-0/+5
|
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* demux_lavf: use mimetype instead of codec type for embedded fontswm42015-04-051-9/+3
| | | | | | | We handle picking out font attachments by mime type ourselves in a higher level, so we really just want to use the mimetype. Also, Matroska is currently the only code in libavformat which uses the fonts at all, and we can drop use of the codec IDs completely.
* demux_lavf: print seek failures in verbose modewm42015-03-241-6/+12
| | | | | Don't bother with making these visible by default, because often they are bogus and/or useless.
* demux_lavf: assume h264/hevc raw streams have no timestampswm42015-03-201-4/+12
| | | | | There are obscure methods to add timestamps to such streams, but assume they're unused.
* player: better handling of video with no timestampswm42015-03-201-10/+3
| | | | | | | | | | | Trying to handle such video is almost worthless, but it was requested by at least 2 users. If there are no timestamps, enable byte seeking by setting ts_resets_possible. Use the video FPS (wherever it comes from) and the audio samplerate for timing. The latter was already done by making the first packet emit DTS=0; remove this again and do it "properly" in a higher level.
* sub: this isn't needed eitherwm42015-03-031-2/+0
|
* Revert "demux_lavf: workaround for broken libavformat subtitle seeking"wm42015-03-031-23/+4
| | | | | | | This reverts commit c8f49be919ffaf983bde77b63d75f96a593ec7a8. Not needed anymore; fixed in all supported FFmpeg releases. Though I could not test again, because all sample files are gone (oops).
* Remove some FFmpeg/Libav compatibility hackswm42015-03-031-33/+2
| | | | | | All of these are now in the supported FFmpeg and Libav versions. The 3 remaining API checks are for FFmpeg-only things.
* demux_lavf: use this for image formatswm42015-03-021-6/+13
| | | | | | | | | | | | | | | | | | Use the (relatively new) libavformat image format probing functionality, instead of letting demux_mf guess by file extension and MIME type. The libavformat support is weird, though. Traditionally, it uses an absolutely terrible hack to detect images by extension, _and_ (which is the horrible part) will randomly interpret parts of the filename as specifiers for matching by number. So something like '%03d' will be interpreted as placeholder for a frame number. The worst part is that such character sequences can be perfectly valid and common in http URLs. This is known as "image2" demuxer. The newer support, which probes by examining the file header, is split into several format-specific demuxers with names ending in "_pipe". So we check for such a name suffix. (At this point we're doing fine-grained hacking around ffmpeg weirdness, so a clean solution is impossible anyway until upstream changes.)
* demux_lavf: apply hacks even if format is forcedwm42015-02-201-27/+28
| | | | | | | | | | | | | Some of the hacks were not applied if the file format was forced. Commit 37a0c914 moved them to a table, which is checked with normal probing only. Fixes #1612 (DVD forces mpeg, which in turn has to export native stream IDs specifically). Do some code restructuring on the way. For example, the probescore can simply be set to the correct initial value, instead of checking whether it was set at all.
* demux_lavf: blacklist bintext fileswm42015-02-181-0/+3
| | | | | | Whatever the hell that is. FFmpeg tries to open any files with .bin file extension with this demuxer (unless it finds a better demuxer), and then reads the whole damn file, along with spamming dumb crap.
* player: enable cache and demuxer thread for subtitles toowm42015-02-181-0/+8
| | | | | | | | | Includes some logic for not starting the demuxer thread for fully read subtitles. (Well, the cache will still waste _lots_ of resources, and the cache always has to be created, because we don't know whether it'll be needed _before_ opening the file.) See #1597.
* demux_lavf: reorganize hackswm42015-02-181-67/+70
| | | | | | | | | | | An attempt to make format-specifics more declarative. (In my opinion, all of this should be either provided by libavformat, or should not be needed.) I'm still leaving many checks with matches_avinputformat_name(), because they're so specific. Also useful for the following commit.
* demux_lavf: set interrupt_callbackwm42015-02-181-0/+11
| | | | | | Helps with terminating the stream if e.g. HLS streams are stuck. (For other demuxers, the stream's interrupt callback already takes care of this.)
* demux_lavf: hack against hls showing "100%" positionwm42015-02-171-0/+6
| | | | | | | | | | | | | The HLs protocol consists of a "playlist" main file, which mpv downloads and passes to the HLS demuxer. The HLS demuxer actually requests segment files containing media data on its own. The packets read from the demuxer have a source file position set, but it's not from the main file. This leads to a strange effect: as a last fallback, the player will calculate the approximate playback position from the file position/size ratio, and since the main file is tiny, this will always show 100%. Fix this by resetting the packet file position. This doesn't affect the case when HLS actually reports a duration.
* demux: hack for instant stream switchingwm42015-02-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes the delay when switching audio tracks in mkv or mp4 files. Other formats are not enabled, because it's not clear whether the demuxers fulfill the requirements listed in demux.h. (Many formats definitely do not with libavformat.) Background: The demuxer packet cache buffers a certain amount of packets. This includes only packets from selected streams. We discard packets from other streams for various reasons. This introduces a problem: switching to a different audio track introduces a delay. The delay is as big as the demuxer packet cache buffer, because while the file was read ahead to fill the packet buffer, the process of reading packets also discarded all packets from the previously not selected audio stream. Once the remaining packet buffer has been played, new audio packets are available and you hear audio again. We could probably just not discard packets from unselected streams. But this would require additional memory and CPU resources, and also it's hard to tell when packets from unused streams should be discarded (we don't want to keep them forever; it'd be a memory leak). We could also issue a player hr-seek to the current playback position, which would solve the problem in 1 line of code or so. But this can be rather slow. So what we do in this commit instead is: we just seek back to the position where our current packet buffer starts, and start demuxing from this position again. This way we can get the "past" packets for the newly selected stream. For streams which were already selected the packets are simply discarded until the previous position is reached again. That latter part is the hard part. We really want to skip packets exactly until the position where we left off previously, or we will skip packets or feed packets to the decoder twice. If we assume that the demuxer is deterministic (returns exactly the same packets after a seek to a previous position), then we can try to check whether it's the same packet as the one at the end of the packet buffer. If it is, we know that the packet after it is where we left off last time. Unfortunately, this is not very robust, and maybe it can't be made robust. Currently we use the demux_packet.pos field as unique packet ID - which works fine in some scenarios, but will break in arbitrary ways if the basic requirement to the demuxer (as listed in the demux.h additions) are broken. Thus, this is enabled only for the internal mkv demuxer and the libavformat mp4 demuxer. (libavformat mkv does not work, because the packet positions are not unique. Probably could be fixed upstream, but it's not clear whether it's a bug or a feature.)
* command: export file format as propertywm42015-01-231-3/+1
| | | | | | | | | | | | Repurpose demuxer->filetype for this. It used to be used to print a human readable format description; change it to a symbolic format name and export it as property. Unfortunately, libavformat has its own weird conventions, which are reflected through the new property, e.g. the .mp4 case mentioned in the manpage. Fixes #1504.
* Check some mallocswm42014-12-121-0/+4
| | | | Fixes #1337.
* demux_lavf: set PTS of first packet for formats with no timestampswm42014-11-251-0/+9
| | | | Makes time display work for some raw audio formats (*.shn).
* player: always use demux_chapterwm42014-11-021-5/+1
| | | | | | | | | Instead of defining a separate data structure in the core. For some odd reason, demux_chapter exported the chapter time in nano-seconds. Change that to the usual timestamps (rename the field to make any code relying on this to fail compilation), and also remove the unused chapter end time.
* demux_lavf, stream_lavf: drop local buffers on time-seekswm42014-10-301-2/+5
| | | | | There was chance that some data was left in various local buffers after time-seeks. Probably doesn't actually matter.
* demux_lavf: mark as seekable if protocol supports seeking by timewm42014-10-301-0/+2
| | | | | | | | | | | | Basically, this will mark the demuxer as seekable with rtmp* and mmsh protocols. These protocols have network-level time seeking, and whether you can seek on the byte level does not matter. Until now, seeking was typically only enabled because of the cache, and a (nonsensical) warning was shown accordingly. It still could happen that the server doesn't actually support thse requests (or simply rejects them), so this is somewhat imperfect.
* player: add stream selection by ffmpeg indexwm42014-10-211-0/+1
| | | | | | | | | Apparently using the stream index is the best way to refer to the same streams across multiple FFmpeg-using programs, even if the stream index itself is rarely meaningful in any way. For Matroska, there are some possible problems, depending how FFmpeg actually adds streams. Normally they seem to match though.
* demux_lavf: set stream network options if applicablewm42014-10-141-2/+3
| | | | | | | | | | | Normally, we pass libavformat demuxers a wrapped mpv stream. But in some cases, such as HLS and RTSP, we let libavformat open the stream itself. In these cases, set typical network properties like useragent according to the mpv options. (We still don't set it for the cases where libavformat opens other streams on its own, e.g. when opening the companion .sub file for .idx files - not sure if we maybe should always set these options.)
* demux_lavf: let libavformat open HLS streams directlywm42014-10-141-1/+2
| | | | | | | | Fixes opening some streams. This means the HLS playlist will be opened twice, but that's not much of a problem, considering it's pretty small, and HLS will make many other http accesses anyway.
* demux_lavf: blacklist jpeg fileswm42014-10-061-0/+1
| | | | | | | We handle them under demux_mf.c for stupid reasons; mostly so that an image is shown for a second instead of just flashing it. CC: @mpv-player/stable
* demux_lavf: bluray: don't skip stream data when flushingwm42014-09-291-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This code meant to flush demuxer internal buffers by doing a byte seek to the current position. In theory this shouldn't drop any stream data. However, if the stream positions mismatch, then avio_seek() (called by av_seek_frame()) stops being a no-op, and might for example read some data to skip to the seek target. (This can happen if the distance is less than SHORT_SEEK_THRESHOLD.) The positions get out of sync because we drop data at one point (which is what we _want_ to do). Strictly speaking, the AVIOContext flushing is done incorrectly, becuase pb->pos points to the start of the buffer, not the current position. So we have to increment pb->pos by the buffered amount. Since there are other weird reasons why the positions might go out of sync (such as stream_dvd.c dropping buffers itself), and they don't necessarily need to be in sync in the first place unless AVIOContext has nothing buffered internally, just use the sledgehammer approach and correct the position manually. Also run av_seek_frame() after this. Currently, it shouldn't read anything, but who knows how that might change with future libavformat development. This whole change didn't have any observable effect for me, but I'm hoping it fixes a reported problem.
* demux_disc: bluray: potentially fix some aspects of seekingwm42014-09-291-1/+1
| | | | | | | | | | | | | When flushing the AVIOContext, make sure it can't seek back to discarded data. buf_ptr is just the current read position, while buf_end - buffer is the actual buffer size. Since mpegts.c is littered with seek calls, it might be that the ability to seek could read Mark the stream (which the demuxer uses) as not seekable. The cache can enable seeking again (this behavior is sometimes useful for other things). I think this should have had no bad influence in theory, since seeking BD/DVD first does the "real" seek, then flushes libavformat and reads new packets.
* audio: remove WAVEFORMATEX from internal demuxer APIwm42014-09-251-1/+1
| | | | | Same as with the previous commit. A bit more involved due to how the code is written.
* demux: gracefully handle packet allocation failureswm42014-09-161-3/+9
| | | | Now the packet allocation functions can fail.
* player: show HLS bitrate as fallback for track titleswm42014-09-011-0/+2
| | | | | | HLS streams as demuxed by libavformat have no track title metadata. So show the HLS bitrate if no title is set. Could be useless or annoying, so it's a bit controversial, I guess.
* player: simplistic HLS bitrate selectionwm42014-09-011-7/+17
| | | | | | --hls-bitrate=min/max lets you select the min or max bitrate. That's it. Something more sophisticated might be possible, but is probably not even worth the effort.
* demux_lavf: print a warning if av_read_frame() returns an errorwm42014-08-301-1/+6
| | | | Because why not.
* Move compat/ and bstr/ directory contents somewhere elsewm42014-08-291-2/+1
| | | | | | | | | bstr.c doesn't really deserve its own directory, and compat had just a few files, most of which may as well be in osdep. There isn't really any justification for these extra directories, so get rid of them. The compat/libav.h was empty - just delete it. We changed our approach to API compatibility, and will likely not need it anymore.
* demux_lavf: don't reject av:// if cache is enabledwm42014-08-271-1/+1
| | | | | Enabling the cache doesn't make much in this situation, but there's also no reason not to reject it.
* demux: always use AVPacketwm42014-08-251-18/+5
| | | | | | | | | | | | | | | | | | | | | This is a simplification, because it lets us use the AVPacket functions, instead of handling the details manually. It also allows the libavcodec rawvideo decoder to use reference counting, so it doesn't have to memcpy() the full image data. The change in av_common.c enables this. This change is somewhat risky, because we rely on the following AVPacket implementation details and assumptions: - av_packet_ref() doesn't access the input padding, and just copies the data. By the API, AVPacket is always padded, and we violate this. The lavc implementation would have to go out of its way to make this a real problem, though. - We hope that the way we make the AVPacket refcountable in av_common.c is actually supported API-usage. It's hard to tell whether it is. Of course we still use our own "old" demux_packet struct, just so that libav* API usage is somewhat isolated.
* demux_lavf: fix crash with unknown streamswm42014-08-231-1/+1
| | | | Could happen with DVD .vob files.
* demux_lavf: support new metadata update APIwm42014-08-141-3/+23
| | | | | This Libav-invented API is of course completely different from the FFmpeg-one. (The fun part is that I approved of both.)
* Improve setting AVOptionswm42014-08-021-14/+5
| | | | | | | | Use OPT_KEYVALUELIST() for all places where AVOptions are directly set from mpv command line options. This allows escaping values, better diagnostics (also no more "pal"), and somehow reduces code size. Remove the old crappy option parser (av_opts.c).
* demux_lavf: don't consider EAGAIN as EOF conditionwm42014-07-301-2/+3
| | | | | | | | | | This happens apparently randomly with rtmp:// and after seeks. This eventually leads to audio decoding returning an EOF status, which basically disables audio sync. This will lead to audio desync, even if audio decoding later "recovers" when the demuxer actually returns audio packets. Hack-fix this by special-casing EAGAIN.
* stream: hack-fix rtmp-level seekingwm42014-07-301-4/+7
| | | | | | | | | | | | | This didn't work, because the timebase was wrong. According to the ffmpeg doxygen, if the stream index is -1 (which is what we used), the timebase is AV_TIME_BASE. But this didn't work, and it really expected the stream's timebase. Quite "surprising", since this feature (avio_seek_time) is used by rtmp only. Fixing this properly is too hard, so hack-fix our way around it. STREAM_CTRL_SEEK_TO_TIME is also used by DVD/BD, so a new STREAM_CTRL_AVSEEK is added. We simply pass-through the request verbatim.
* demux: fix timestamp type for seek callswm42014-07-211-1/+1
| | | | | mpv/mplayer2/MPlayer use double for timestamps, but the demuxer API used float.
* demux_lavf: reverse rotation direction with new APIwm42014-07-171-1/+1
| | | | | | | The old FFmpeg API and the new Libav API disagree about mp4 display rotation direction. Well, whatever, fix it trial-and-error-style. CC: @mpv-player/stable: add
* demux: add a demuxer threadwm42014-07-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a thread to the demuxer which reads packets asynchronously. It will do so until a configurable minimum packet queue size is reached. (See options.rst additions.) For now, the thread is disabled by default. There are some corner cases that have to be fixed, such as fixing cache behavior with webradios. Note that most interaction with the demuxer is still blocking, so if e.g. network dies, the player will still freeze. But this change will make it possible to remove most causes for freezing. Most of the new code in demux.c actually consists of weird caches to compensate for thread-safety issues (with the previously single-threaded design), or to avoid blocking by having to wait on the demuxer thread. Most of the changes in the player are due to the fact that we must not access the source stream directly. the demuxer thread already accesses it, and the stream stuff is not thread-safe. For timeline stuff (like ordered chapters), we enable the thread for the current segment only. We also clear its packet queue on seek, so that the remaining (unconsumed) readahead buffer doesn't waste memory. Keep in mind that insane subtitles (such as ASS typesetting muxed into mkv files) will practically disable the readahead, because the total queue size is considered when checking whether the minimum queue size was reached.
* demux_lavf: don't let metadata update mess up ogm playbackwm42014-07-141-1/+4
| | | | | | For OGG audio files, we usually merge the per-stream metadata back to the file-global metadata. Don't do that for OGM, because with OGM most metadata is actually per-stream.
* build: include <strings.h> for strcasecmp()wm42014-07-101-2/+1
| | | | | | | It happens to work without strings.h on glibc or with _GNU_SOURCE, but the POSIX standard requires including <strings.h>. Hopefully fixes OSX build.
* demux: minor simplificationwm42014-07-061-2/+2
| | | | Oops, should have been part of commit 37085788.
* demux: minor simplification to internal APIwm42014-07-051-1/+1
| | | | Also some other unrelated minor changes.
* dvd: flush buffers properly on seekwm42014-07-051-3/+4
| | | | | | | | | | | Suggested by tholin on github issue #882. This is not entirely clean, but the fields we're accessing might be considered internal to libavformat. On the other hand, existence of the fields is guaranteed by the ABI, and nothing in the libavformat doxygen suggestes they're not allowed to be accessed. CC: @mpv-player/stable
* dvd, bluray, cdda: add demux_disc co