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

Support for subtitles while streaming #19102

Closed
forthrin opened this issue Feb 2, 2019 · 5 comments
Closed

Support for subtitles while streaming #19102

forthrin opened this issue Feb 2, 2019 · 5 comments

Comments

@forthrin
Copy link

@forthrin forthrin commented Feb 2, 2019

Today you can stream videos like this:

youtube-dl -o - https://www.youtube.com/watch?v=<id> | vlc -

It would be nice to be able to have subtitles when streaming. Something like:

youtube-dl --write-sub-file /tmp/subtitles.srt -o - https://www.youtube.com/watch?v=<id> | vlc --sub-file /tmp/subtitles.srt -
  • I've verified and I assure that I'm running youtube-dl 2019.01.24
  • At least skimmed through the README, most notably the FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones
  • Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser
  • Bug report (encountered problems with youtube-dl)
$ youtube-dl --verbose
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'--verbose']
[debug] Encodings: locale UTF-8, fs utf-8, out utf8, pref UTF-8
[debug] youtube-dl version 2019.01.24
[debug] Python version 2.7.15 (CPython) - Darwin-16.7.0-x86_64-i386-64bit
[debug] exe versions: ffmpeg 4.0.2, ffprobe 4.0.2, rtmpdump 2.4
[debug] Proxy map: {}

@alexvong1995
Copy link
Contributor

@alexvong1995 alexvong1995 commented Feb 6, 2019

After putting the right value for lang and url, the following shell command
should do what you want.

lang=en; url='https://www.youtube.com/watch?v=<id>'; pwd_sv="$PWD"; tmpdir=`mktemp -d`; cd "$tmpdir" && youtube-dl -o sub --write-sub --skip-download --sub-format best --sub-lang "$lang" "$url" && test -f "$tmpdir"/sub.* && youtube-dl -o - "$url" | vlc --play-and-exit --sub-file "$tmpdir"/sub.* -; cd "$pwd_sv"; rm -rf "$tmpdir"

I suspect the vlc subtitle auto-detection is buggy at the moment because I
cannot make it work. I have to pass --sub-file explicitly in the above
command. I can turn the above into a proper shell script if you really need it.

For myself, I use mpv and because it has youtube-dl integration, the command
is as simple as mpv https://www.youtube.com/watch?v=<id>.

@forthrin
Copy link
Author

@forthrin forthrin commented Feb 6, 2019

@alexvong1995: Augh! That's a bit long, and probably slow, since you have to request the video twice.

However, I found out that it's better to watch this way, as eliminating the pipe makes it possible to jump in the video, see the video length, etc.

vlc "$(youtube-dl --get-url 'https://www.youtube.com/watch?v=<id>')"

I'll leave the issue open for someone to suggest a way to get subtitles with this approach, or interest from the developers to add supports for this.

PS! Good to know about mpv!

@alexvong1995
Copy link
Contributor

@alexvong1995 alexvong1995 commented Feb 6, 2019

@forthrin
Copy link
Author

@forthrin forthrin commented Feb 6, 2019

This is much better! This should be useful for several people out there. This snippet would be very suitable for a FAQ or the manual pages.

@forthrin
Copy link
Author

@forthrin forthrin commented Mar 8, 2019

I'll close the issue, as it's probably not feasible to make youtube-dl pass both subtitles and streaming URL on to a video player in a uniform, straight forward way. This can be accomplished using a relatively simple script, as shown above, and in other ways.

@forthrin forthrin closed this Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.