Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to watch live HLS WebVTT subtitle streams #3087

Closed
Kagami opened this issue Apr 27, 2016 · 36 comments
Closed

Impossible to watch live HLS WebVTT subtitle streams #3087

Kagami opened this issue Apr 27, 2016 · 36 comments

Comments

@Kagami
Copy link
Contributor

Kagami commented Apr 27, 2016

It seems like libavformat doesn't return intermediate results of WebVTT HLS streams so mpv stucks until entire subtitle stream is downloaded which is inappropriate for live translations.

Consider this test stream. If you try to play it either directly or with --sub-file, mpv hangs. Basically the real life use case is HLS video/audio + HLS subtitles, you can find such streams e.g. at vlive.tv.

Test output:

$ mpv -v https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8
<skip>
[cplayer] Playing: https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8
[cplayer] Running hook: ytdl_hook/on_load
[global] config path: 'youtube-dl' -/-> '/home/kagami/.mpv/youtube-dl'
[global] config path: 'youtube-dl' -/-> '/etc/mpv/youtube-dl'
[ytdl_hook] youtube-dl succeeded! 
[cplayer] Set property string: file-local-options/user-agent='Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/44.0 (Chrome)'
[cplayer] Set property string: stream-open-filename='https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8'
[cplayer] Set property string: file-local-options/force-media-title='prog_index'
[cplayer] Run command: hook-ack, flags=0, args=[on_load]
[ffmpeg] Opening https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8
[ffmpeg] Mime-type: 'audio/x-mpegurl'
[ffmpeg] Stream opened successfully.
[cache] Cache size set to 75032 KiB (75000 KiB backbuffer)
[demux] Trying demuxers for level=normal.
[cache] EOF reached.
[lavf] Found 'hls,applehttp' at score=100 size=2048.
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence0.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence1.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence2.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence3.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence4.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence5.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence6.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence7.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence8.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence9.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence10.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence11.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence12.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence13.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence14.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence15.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence16.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence17.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence18.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence19.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence20.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence21.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence22.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence23.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence24.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence25.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence26.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence27.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence28.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence29.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence30.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence31.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence32.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence33.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence34.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence35.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence36.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence37.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence38.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence39.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence40.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence41.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence42.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence43.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence44.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence45.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence46.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence47.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence48.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence49.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence50.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence51.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence52.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence53.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence54.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence55.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence56.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence57.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence58.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence59.webvtt', offset 0, playlist 0
[ffmpeg/demuxer] webvtt: Dropping 30 duplicated subtitle events
[lavf] avformat_find_stream_info() finished after 0 bytes.
[demux] Detected file format: hls,applehttp (libavformat)
[cache] blocking for STREAM_CTRL 6
[global] config path: 'sub/' -/-> '/home/kagami/.mpv/sub/'
[global] config path: 'sub/' -/-> '/etc/mpv/sub/'
[global] config path: 'audio/' -/-> '/home/kagami/.mpv/audio/'
[global] config path: 'audio/' -/-> '/etc/mpv/audio/'
[cplayer]      Subs  --sid=1 (webvtt)
[cplayer] No video or audio streams selected.
[cache] Terminating cache...
[cache] Cache exiting...
[cplayer] finished playback, no audio or video data played (reason 4)
[cplayer] 
[cplayer] 
[cplayer] Exiting... (Errors when loading file)
[ytdl_hook] Exiting...
[stats] Exiting...
[frame_info] Exiting...

I realize that this is probably ffmpeg's bug but creating issue anyway in case if you know some workaround. My knowledge of ffmpeg is poor so probably there is some option to fix this, etc.

mpv/ffmpeg are latest from git.

@ghost
Copy link

ghost commented Apr 27, 2016

Works just fine for me, except that it's so slow.

@Kagami
Copy link
Contributor Author

Kagami commented Apr 27, 2016

What do you mean by working? I'm trying to say that mpv will wait until entire stream is downloaded and in case of live translations you can't wait, you need to display current video/audio/subtitle chunks right away.

@ghost
Copy link

ghost commented Apr 27, 2016

Your test stream has only subtitles, so that's not necessarily a good test case.

@Kagami
Copy link
Contributor Author

Kagami commented Apr 27, 2016

Yes, sorry. There are lives at vlive.tv which illustatre my issue best. I'm spawning mpv like this mpv http://hls-video-stream.m3u8 --sub-file http://hls-sub-stream.m3u8 and it hangs and I can see in the console log that's because it downloads all subtitle chunks. Though currently there are no such live available. I may try to find better test case if that can help.

@Kagami
Copy link
Contributor Author

Kagami commented Apr 27, 2016

Also, this is a bit arificial example, but works in the exact same way:

mpv any-video.mkv --sub-file https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8

Video will start only when entire sub stream is downloaded.

@ghost
Copy link

ghost commented Apr 27, 2016

Definitely seems to be a ffmpeg issue:

[ffmpeg/demuxer] hls,applehttp: HLS request for url 'https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence59.webvtt', offset 0, playlist 
[ffmpeg/demuxer] webvtt: Dropping 30 duplicated subtitle events
[lavf] avformat_find_stream_info() finished after 0 bytes.
[demux] Detected file format: hls,applehttp (libavformat)

@ghost ghost added the down-upstream:ffmpeg label Apr 27, 2016
@Kagami
Copy link
Contributor Author

Kagami commented Apr 28, 2016

Seems like this (and neighbour commits in hls branch) commit anssih/FFmpeg@7d7fc89 should fix that. A lot of HLS patches were proposed at the ffmpeg's mailing list but some still haven't been merged yet.

@ghost
Copy link

ghost commented Apr 28, 2016

It's unlikely that anything will be done after 2 years of silence...

@Kagami
Copy link
Contributor Author

Kagami commented Apr 28, 2016

Is it possible to reread subtitle file somehow in mpv (maybe with Lua scripting)? It would be extra hacky but it's possible to fetch those subs in separate thread, parse and progressively add to the .vtt file. Any ideas except actually fix ffmpeg?

@ghost
Copy link

ghost commented Apr 28, 2016

You certainly could somehow load the file in Lua (for which you would need some sort of http lib for Lua) and add the subtitles via memory:// or so. But fixing it in ffmpeg is preferable.

@Kagami
Copy link
Contributor Author

Kagami commented Apr 30, 2016

@anssih could you look at this please? I tried to apply your patch anssih/FFmpeg@7d7fc89 to the latest ffmpeg git, it aplied with one merge conflict, but seems like it doesn't produce any effect.

Maybe I'm missing something and need to apply some more patches from your branch? It's just not clear after 3 years which ones are still releveant and which were merged. Any hints will be greatly appreciated. Thanks.

@anssih
Copy link

anssih commented Apr 30, 2016

@Kagami Yep, you are correct in that that commit (plus the two WebVTT MPEG-TS timestamp ones) is supposed to fix this - not sure why it isn't working for you, likely the code has changed too much since them.

When I wrote that I was planning to rewrite it in a cleaner way before getting that merged in, unfortunately I ran out of time... I'm still hoping to get back to that, but can't make any promises on the timeframe.

@Kagami
Copy link
Contributor Author

Kagami commented Apr 30, 2016

Let me try one more time, maybe I did something wrong.

I need these 3 commits:
anssih/FFmpeg@65af023
anssih/FFmpeg@7d7fc89
anssih/FFmpeg@14126c8
Correct?

@anssih
Copy link

anssih commented Apr 30, 2016

@Kagami Yes.

@Kagami
Copy link
Contributor Author

Kagami commented Apr 30, 2016

@anssih I built your hls branch and seems like it works in the same way as stock ffmpeg, it downloads the entire playlist first:

$ ./ffmpeg -v verbose -i http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8
ffmpeg version N-62213-g7843211 Copyright (c) 2000-2014 the FFmpeg developers
  built on Apr 30 2016 15:00:25 with gcc 4.9.3 (Gentoo 4.9.3 p1.4, pie-0.6.4)
  configuration: 
  libavutil      52. 74.100 / 52. 74.100
  libavcodec     55. 57.101 / 55. 57.101
  libavformat    55. 36.101 / 55. 36.101
  libavdevice    55. 11.100 / 55. 11.100
  libavfilter     4.  3.100 /  4.  3.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 18.100 /  0. 18.100
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence0.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence1.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence2.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence3.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence4.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence5.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence6.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence7.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence8.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence9.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence10.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence11.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence12.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence13.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence14.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence15.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence16.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence17.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence18.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence19.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence20.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence21.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence22.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence23.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence24.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence25.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence26.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence27.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence28.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence29.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence30.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence31.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence32.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence33.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence34.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence35.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence36.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence37.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence38.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence39.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence40.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence41.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence42.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence43.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence44.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence45.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence46.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence47.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence48.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence49.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence50.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence51.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence52.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence53.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence54.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence55.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence56.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence57.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence58.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x1f00100] HLS request for url 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/fileSequence59.webvtt', offset 0, playlist 0
Input #0, hls,applehttp, from 'http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8':
  Duration: 00:29:59.00, bitrate: 0 kb/s
  Program 0 
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Subtitle: webvtt
At least one output file must be specified

The same for live stream:

$ ./ffmpeg -v verbose -i 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlelist_leng.m3u8'
ffmpeg version N-62213-g7843211 Copyright (c) 2000-2014 the FFmpeg developers
  built on Apr 30 2016 15:00:25 with gcc 4.9.3 (Gentoo 4.9.3 p1.4, pie-0.6.4)
  configuration: 
  libavutil      52. 74.100 / 52. 74.100
  libavcodec     55. 57.101 / 55. 57.101
  libavformat    55. 36.101 / 55. 36.101
  libavdevice    55. 11.100 / 55. 11.100
  libavfilter     4.  3.100 /  4.  3.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 18.100 /  0. 18.100
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_381.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_382.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_383.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_384.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_385.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_386.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_387.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_388.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_389.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_390.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_391.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_392.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_393.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_394.webvtt', offset 0, playlist 0
^C[hls,applehttp @ 0x2665100] Failed to open segment of playlist 0
[hls,applehttp @ 0x2665100] HLS request for url 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlechunk_leng_394.webvtt', offset 0, playlist 0
[hls,applehttp @ 0x2665100] Failed to open segment of playlist 0
Input #0, hls,applehttp, from 'http://vlive.hls.edgesuite.net/kr026/400.stream/subtitlelist_leng.m3u8':
  Duration: N/A, bitrate: N/A
  Program 0 
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Subtitle: webvtt
At least one output file must be specified
Received signal 2: terminating.

Maybe I don't understand something?

@ghost
Copy link

ghost commented Apr 30, 2016

That's because as I've earlier pointed out, avformat_find_stream_info() seems to read all subtitles. Why it does that could depend on a number of factors though. It's some of the most terrible code in libavformat.

@Kagami
Copy link
Contributor Author

Kagami commented Apr 30, 2016

Seems like it assumes that sub streams just don't exist because I get same behaviour with subs streamed over HTTP/Pipe.

What if I will write subs to file in separate process (using livestreamer -o) and do sub-add/sub-remove with Lua every second? Sounds terrible, but fixing ffmpeg is too hard for me.

@ghost
Copy link

ghost commented Apr 30, 2016

Standalone subtitle streams (not wrapped in HLS, just text) are always fully downloaded by libavformat on opening.

What if I will write subs to file in separate process (using livestreamer -o) and do sub-add/sub-remove with Lua every second? Sounds terrible, but fixing ffmpeg is too hard for me.

Terrible, but should work. You'll have to mind the timestamp offsets of course.

Kagami added a commit to Kagami/mpv_vlive that referenced this issue Apr 30, 2016
@Kagami
Copy link
Contributor Author

Kagami commented May 1, 2016

@wm4 note that there are plans to export HLS subtitles info in youtube-dl vlive extractor. It will freeze mpv on lives with subtitles... Probably some option needed to disable auto sub-add in ytdl_hook?

@Kagami
Copy link
Contributor Author

Kagami commented Dec 13, 2016

Few patches that probably address this issue: https://ffmpeg.org/pipermail/ffmpeg-devel/2016-November/202451.html
Private ffmpeg branch: https://github.com/coreynicholson/FFmpeg
Seems like @coreynicholson is interested in solving same issue, pinging just in case (sorry if not).

@coreynicholson
Copy link

Didn't realise there was a thread here for this.

@Kagami yep, I'm interested in this too, for the same reason actually, watching vlives. I've sent in those patches to the mailing list but they don't seem to be getting anyway so I've been using the squash_hls_refactor branch from my ffmpeg fork and it's working well enough, haven't noticed any issues. I wouldn't recommend anyone else use that branch though because I'm not merging updates from the official ffmpeg repo to it.

@ghost
Copy link

ghost commented Jan 19, 2017

There were some concerns about code duplication. Anyway, ping the patches if you think you've done everything you could to fix the things that were pointed out.

@coreynicholson
Copy link

I sent new patches with the refactoring work done here: https://patchwork.ffmpeg.org/patch/1995/
Adding tests was the other thing that was mentioned but I don't really know where to start with that so it would likely take more time than I can spare right now.

@Kagami
Copy link
Contributor Author

Kagami commented Jan 19, 2017

@coreynicholson, that's great!
What's the status of your patches? Do they work reliable for common vlive streams? I may help to test them.

Speaking of watching vlives, there are also several issues which prevent watching streams properly:
ytdl-org/youtube-dl#8820
ytdl-org/youtube-dl#9349
They also might be solved in a different way, by creating appropritate plugin for streamlink which seems to be pretty active.

@coreynicholson
Copy link

Ah, just noticed there was a reply to my patches, it seems it breaks some tests (http://ffmpeg.org/pipermail/ffmpeg-devel/2017-January/205150.html), so I need to look at that.

@Kagami
Copy link
Contributor Author

Kagami commented Jan 19, 2017

and it's working well enough, haven't noticed any issues

Ah, missed that, sorry. I will build your branch and test then.

I wouldn't recommend anyone else use that branch though because I'm not merging updates

At least in gentoo that can be solved just by putting patches to /etc/portage/patches. (Of course updates may bring merging conflicts, but you don't need to rebase for every non-related commit.)

@coreynicholson
Copy link

I will build your branch and test then.

Sure, I should mention however, that whilst I haven't any noticed any issues when downloading streams to mkv or mp4 using ffmpeg it doesn't seem to work that well with mpv. Some things I've noticed when building mpv with those patches:

I don't know what could be causing the first issue, but the delay in the second issue may be due to the cache and is probably unavoidable without downloading all the subtitle tracks preemptively. The third issue may be due to not discarding duplicate packets when seeking, not sure if this needs to be done on the mpv side or ffmpeg side.

Having said all that, I used it to watch one of the year end award shows that was 3+ hours long and had subs without any problems.

@ghost
Copy link

ghost commented Jan 20, 2017

Normally enabling a subtitle should start where it does, no matter whether it's an external file or not.

For internal subtitles (which applies to HLS), there's a heuristic to seek the entire demuxer back by 10 seconds, but it's active only if either packet DTS or packet position are strictly monotonically increasing.

Overlapping subtitles could happen because if the packet position is >=0 (i.e. set), it uses that as unique ID to filter out duplicated subtitles that come from playing a range of the file again.

@vins31
Copy link

vins31 commented Aug 7, 2019

Thank you @Kagami for this work.
Looking at the mpv-build project, I see no patch applied to ffmpeg at build time.
However the current version of mpv (0.29.1 using ffmpeg 4.0.2) does handle webVTT in HLS stream (I tested with this stream).

My question is : is there another mpv compilation script that uses your patch or your repo?

@fredvb
Copy link

fredvb commented Aug 7, 2019

I've tried to apply the changes on the current version of ffmpeg but failed at it. I got lost in the HTTP persistent code and probably failed to close or reuse the HTTP object at the right places, thus after a couple of segments being fetched it just hung.

Using the current version of ffmpeg, you could replace completely /libavformat/hls.c with https://github.com/coreynicholson/FFmpeg/blob/56b5e362224a2b403c4a5bccbf01f0df61ba3760/libavformat/hls.c

And also patch libavformat/webvttdec.c manually based on anssih/FFmpeg@65af023

MPV doesn't really require any changes.

Ideally, the changes brought to hls.c should be upgraded to fit in the latest version of it which supports persistent connections.

In any case, this falls into ffmpeg.

Hope this helps. If someone has the courage to upgrade the hls.c file to the latest, that would be greatly appreciated.
As @coreynicholson mentionned, there might be other issues that still exist.

@Akemi
Copy link
Member

Akemi commented Dec 3, 2019

was already brought up upstream.

@Akemi Akemi closed this as completed Dec 3, 2019
@fredvb
Copy link

fredvb commented Dec 3, 2019

Do you know if there is an open ticket for this in ffmpeg?
Latest release of ffmpeg doesn't have this resolved on live hls streams.
I'm only able to make it work with the old code I pointed out above, but I couldn't apply a patch on the latest version of how.c because of how they now reuse the http object.

@Akemi
Copy link
Member

Akemi commented Dec 3, 2019

i am not sure, i remember it being brought up on the mailing list i believe. just open a new one i would say.

@aeeq
Copy link

aeeq commented Apr 7, 2022

This problem has not been solved

@pabloab
Copy link

pabloab commented Aug 10, 2023

@Akemi Where we can see this was brought up upstream? I only find this old closed issue on ffmpeg bug tracker.


$ flatpak run io.mpv.Mpv --no-config --no-video --ytdl-format=best "https://youtu.be/jfKfPfyJRdk"
[ffmpeg] https: HTTP error 403 Forbidden
[ffmpeg/demuxer] hls: Failed to open segment 5580670 of playlist 0
[ffmpeg/demuxer] hls: Segment 5580670 of playlist 0 failed too many times, skipping
[ffmpeg] https: HTTP error 403 Forbidden
[ffmpeg/demuxer] hls: Failed to open segment 5580671 of playlist 0
[ffmpeg/demuxer] hls: Segment 5580671 of playlist 0 failed too many times, skipping
...

Versions:

mpv 0.35.1 Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
FFmpeg library versions:
   libavutil       58.2.100
   libavcodec      60.3.100
   libavformat     60.3.100
   libswscale      7.1.100
   libavfilter     9.3.100
   libswresample   4.10.100
FFmpeg version: n6.0

Have this issue randomly. Using PipeWire (might be realated). Sometimes youtube-dl --rm-cache-dir seems to fix it.

@pabloab
Copy link

pabloab commented Aug 17, 2023

Fixed the above problem with flatpak uninstall --delete-data io.mpv.Mpv && flatpak install io.mpv.Mpv. Not related with IPv4 (--ytdl-raw-options=force-ipv4=). The idea comes from this comment, a permission issue or corruption on the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants