mpv
mpv copied to clipboard
Network stream skip forward a few seconds after connection is re-established
Important Information
Provide following Information:
- mpv version: 0.33.0-67-g8121d958ec
- Windows Version: Windows 10 20H2
- Source of the mpv binary: Scoop
- If known which version of mpv introduced the problem: All versions have the problem
- Possible screenshot or video of visual glitches: N/A
If you're not using git master or the latest release, update. Releases are listed here: https://github.com/mpv-player/mpv/releases
Reproduction steps
- Launch mpv with
--no-config https://www.twitch.tv/videos/897966109. - After the stream started, pause the video.
- Either wait for a few minutes for Twitch server to disconnect from their side due to no activity, or use some tools such as Process Hacker to cut the connection for faster reproduction.
- Resume the video.
Expected behavior
The video should play smoothly without any skip, as if we've never paused at all.
Actual behavior
After a few seconds since resume, the video will skip forward several seconds (around 20 in my case, but depends). If --cache=auto is used, I can see the "sec" value in "Total Cache" stats suddenly jumps to large number. If --cache=no is used, I can see the cache bytes being drained to 0, then suddenly starting to refill. The skip happens after the cache is completely drained.
Log file
Sample files
Any Twitch VOD URL should work.
If i'm not mistaken, twitch VODs have been having a problem for a while where mpv would cut ~15 seconds from the VODs in certain places. (might be due to ad segments). Reproduction: play any VOD and you should notice the skip happening in first 10-20 minutes of the video.
I'm not referring to the ad segments. And not only Twitch has this problem. I just tried a random live stream from Facebook Gaming (https://www.facebook.com/omareloff/videos/272439724317708/) and reproduced the same issue. Here is the relevant part of output:
[ad] Invalid audio PTS: 2.915667 -> 3.918000
[cplayer]
[cplayer] Audio/Video desynchronisation detected! Possible reasons include too slow
[cplayer] hardware, temporary CPU spikes, broken drivers, and broken files. Audio
[cplayer] position will not match to the video (see A-V status field).
[cplayer]
[ffmpeg] tls: read failed: error:14FFF3E7:SSL routines:(UNKNOWN)SSL_internal:unknown failure occurred
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: Packet corrupt (stream = 0, dts = 10575260).
[ffmpeg/demuxer] dash: Packet corrupt (stream = 6, dts = 10575260).
[ffmpeg/demuxer] mov,mp4,m4a,3gp,3g2,mj2: stream 0, offset 0x549c9: partial file
[ffmpeg/video] h264: Invalid NAL unit size (7888 > 6055).
[ffmpeg/video] h264: Error splitting the input into NAL units.
[vd] Error while decoding frame!
[ad] Invalid audio PTS: 13.923333 -> 22.926000
[cplayer] Reset playback due to audio timestamp reset.
[ffmpeg/video] h264: co located POCs unavailable
[cplayer]
[cplayer] Audio/Video desynchronisation detected! Possible reasons include too slow
[cplayer] hardware, temporary CPU spikes, broken drivers, and broken files. Audio
[cplayer] position will not match to the video (see A-V status field).
[cplayer]
[ad] Invalid audio PTS: 23.928333 -> 26.915000
It seems that due to the disconnection, ffmpeg can't continue decoding the video, thus it has to start from new segment, which could be a few seconds later, depending on how small each hls segment is cut.
This problem does not happen in non-hls use cases such as Youtube videos.
tried your link, severe audio stuttering
Video --vid=1 (*) (h264 640x360) (825 kbps)
Video --vid=2 (*) (h264 256x144) (110 kbps)
Video --vid=3 (*) (h264 426x240 60.000fps) (413 kbps)
Video --vid=4 (*) (h264 854x480 60.000fps) (1650 kbps)
Video --vid=5 (*) (h264 1280x720 60.000fps) (3300 kbps)
Video --vid=6 (*) (h264 1920x1080 60.000fps) (5500 kbps)
(+) Video --vid=7 (*) (h264 1920x1080 60.000fps) (15000 kbps)
(+) Audio --aid=1 (*) (aac 2ch 48000Hz) (132 kbps)
AO: [wasapi] 48000Hz stereo 2ch float
VO: [gpu] 1920x1080 yuv420p
AV: 00:00:02 / 00:00:05 (44%) A-V: 0.000 Cache: 3.1s/1MB
Invalid audio PTS: 2.931667 -> 4.915000
Audio/Video desynchronisation detected! Possible reasons include too slow
hardware, temporary CPU spikes, broken drivers, and broken files. Audio
position will not match to the video (see A-V status field).
AV: 00:00:10 / 00:00:15 (72%) A-V: 0.045 ct: 1.939 Dropped: 52 Cache: 3.9s/3M
Invalid video timestamp: 10.967000 -> 10.966000
AV: 00:00:30 / 00:00:40 (75%) A-V: 0.000 ct: 1.984 Dropped: 52 Cache: 10s/10M
Invalid audio PTS: 30.920333 -> 29.918000
AV: 00:00:30 / 00:00:40 (76%) A-V: -0.889 ct: 1.871 Dropped: 52 Cache: 9.9s/9M
Invalid video timestamp: 30.967000 -> 30.966000
AV: 00:00:31 / 00:00:41 (75%) A-V: -0.715 ct: 1.698 Dropped: 52 Cache: 10s/10M
Invalid audio PTS: 30.920667 -> 29.918000
AV: 00:00:32 / 00:00:42 (75%) A-V: -1.437 ct: 1.418 Dropped: 52 Cache: 10s/10M
Invalid audio PTS: 30.920667 -> 29.918000
AV: 00:00:34 / 00:00:44 (76%) A-V: -1.580 ct: 0.558 Dropped: 52 Cache: 10s/11M
Invalid audio PTS: 32.926000 -> 31.923000
AV: 00:00:34 / 00:00:46 (75%) A-V: -2.296 ct: 0.271 Dropped: 52 Cache: 11s/12M
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:35 / 00:00:47 (74%) A-V: -3.012 Dropped: 52 Cache: 12s/12MB
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:36 / 00:00:47 (76%) A-V: -3.728 ct: -0.302 Dropped: 52 Cache: 11s/12M
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:37 / 00:00:49 (75%) A-V: -4.444 ct: -0.589 Dropped: 52 Cache: 12s/13M
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:37 / 00:00:50 (74%) A-V: -5.160 ct: -0.876 Dropped: 52 Cache: 12s/14M
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:38 / 00:00:51 (74%) A-V: -5.876 ct: -1.162 Dropped: 52 Cache: 13s/14M
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:39 / 00:00:52 (74%) A-V: -6.592 ct: -1.449 Dropped: 52 Cache: 13s/14M
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:39 / 00:00:53 (74%) A-V: -7.308 ct: -1.736 Dropped: 52 Cache: 13s/15M
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:40 / 00:00:54 (74%) A-V: -8.024 ct: -2.022 Dropped: 52 Cache: 14s/15M
Invalid audio PTS: 32.925667 -> 31.923000
AV: 00:00:42 / 00:00:56 (75%) A-V: -8.167 ct: -2.882 Dropped: 52 Cache: 14s/15M
Invalid audio PTS: 34.931000 -> 33.929000
AV: 00:00:43 / 00:00:58 (74%) A-V: -8.882 ct: -3.169 Dropped: 52 Cache: 15s/16M
Invalid audio PTS: 34.931667 -> 33.929000
AV: 00:00:44 / 00:00:59 (74%) A-V: -9.598 ct: -3.456 Dropped: 52 Cache: 15s/17M
Invalid audio PTS: 34.931667 -> 33.929000
AV: 00:00:44 / 00:01:00 (74%) A-V:-10.314 ct: -3.742 Dropped: 52 Cache: 15s/17M
Invalid audio PTS: 34.931667 -> 33.929000
AV: 00:00:45 / 00:01:00 (75%) A-V:-11.030 ct: -4.029 Dropped: 52 Cache: 15s/17M
Invalid audio PTS: 34.931667 -> 33.929000
AV: 00:00:47 / 00:01:04 (74%) A-V:-11.180 ct: -4.882 Dropped: 52 Cache: 16s/19M
Invalid audio PTS: 36.915667 -> 35.913000
AV: 00:00:48 / 00:01:05 (74%) A-V:-11.895 ct: -5.169 Dropped: 52 Cache: 17s/19M
Invalid audio PTS: 36.915667 -> 35.913000
AV: 00:00:49 / 00:01:05 (75%) A-V:-12.611 ct: -5.456 Dropped: 52 Cache: 16s/18M
Invalid audio PTS: 36.915667 -> 35.913000
AV: 00:00:49 / 00:01:06 (75%) A-V:-13.328 ct: -5.742 Dropped: 52 Cache: 16s/19M
Invalid audio PTS: 36.915667 -> 35.913000
AV: 00:00:50 / 00:01:08 (74%) A-V:-14.043 ct: -6.029 Dropped: 52 Cache: 18s/20M
Invalid audio PTS: 36.915667 -> 35.913000
AV: 00:00:50 / 00:01:08 (74%) A-V:-14.946 ct: -6.129 Dropped: 52 Cache: 17s/19M
Invalid video timestamp: 50.967000 -> 50.966000
AV: 00:00:51 / 00:01:09 (73%) A-V:-14.758 ct: -6.316 Dropped: 52 Cache: 18s/20M
Invalid audio PTS: 36.915667 -> 35.913000
AV: 00:00:52 / 00:01:10 (74%) A-V:-15.474 ct: -6.603 Dropped: 52 Cache: 18s/21M
Invalid audio PTS: 36.915667 -> 35.913000
AV: 00:00:52 / 00:01:11 (74%) A-V:-16.190 ct: -6.890 Dropped: 52 Cache: 18s/21M
Invalid audio PTS: 36.915667 -> 35.913000
AV: 00:00:53 / 00:01:11 (74%) A-V:-17.113 ct: -6.970 Dropped: 52 Cache: 18s/21M
[ffmpeg/demuxer] dash: Error when loading first fragment, playlist 0
Exiting... (Quit)
I don't know what to say. If you can't get the video play normally, maybe there's something wrong with your OS/hardware/internet provider. And you could try ANY link that does HLS.
Well, here is my hack lua to tackle the problem. I can't change the behavior of the demuxer, but I know every time I do seek mpv will reset and playback states, and create connection if missing, so I just seek at current position when
- the video has network source,
- the video has been paused for a long time (that the server has most likely closed the connection).
local PAUSE_DURATION_TO_SEEK_IN_SEC = 300 -- might need to be different value based on server timeout settings
local lastPauseTimestamp = 0
local function pauseSeek(name, paused)
if not mp.get_property_native("demuxer-via-network") then
return
end
if paused then
lastPauseTimestamp = os.time()
elseif os.time() - lastPauseTimestamp > PAUSE_DURATION_TO_SEEK_IN_SEC then
mp.commandv("seek", 0)
end
end
mp.observe_property("pause", "bool", pauseSeek)
You'd think this issue is caused by this FFmpeg default:
seg_max_retry     Maximum number of times to reload a segment on error, useful when segment skip on network error is not desired. Default value is 0.
But setting demuxer-lavf-o=seg_max_retry=10 doesn't help.
The lua script above doesn't work for me.