Wondering how to download a video from YouTube, with audio and subtitles intact? Here are a couple of methods I’m documenting in case I ever need to use them.
This is just a mental exercise, and I do not know if it works! I neither condone nor suggest you use this for any form of copyright infringement. Please be aware of copyright laws and do not download anything you do not have rights to.
Method 1: On-line tools
There are a multitude of on-line YouTube downloading tools, such as KeepVid.ch. Pretty self-explanatory, just provide a YouTube URL, choose the quality options, and hit download. Two browser tabs open - one playing just the video stream and the other playing audio, both directly from YouTube. For each, right-click and Save As...
For subtitles, SaveSubs.com is one of the many on-line tools to download YouTube subtitles in
Method 2: youtube-dl
Disclaimer: downloading apps from the Internet should generally be considered unsafe!
There is an open-source youtube-dl Python-based command-line downloader. This is the method I prefer.
- On macOS, according to the instructions,
curl -L https://yt-dl.org/downloads/latest/youtube-dl -o youtube-dlwill download the executable.
- On Windows, just download the compiled executable - since I have no idea, I downloaded the full package.
- Plus get the open-soruce transcoding tool FFmpeg as well, and put it in the same folder as youtube-dl.
However, using youtube-dl is rather complex, see the examples!, e.g.
- To download video and audio streams
youtube-dl -ci -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' https://www.youtube.com/watch?v=xxxxxxxxxxx
- Or to download video, audio and English subtitle streams,
youtube-dl -ci -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' --sub-lang en-GB,en-UK,en-US,en --write-sub https://www.youtube.com/watch?v=xxxxxxxxxxx
Youtube-dl can use FFmpeg automatically to merge the streams, that’a a bonus from the previous method! Assuming
ffmpeg is in the same folder as
youtube-dl, then, configure youtube-dl as follows:
youtube-dl -ci -f bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best \ --sub-lang en-GB,en-UK,en-US,en --embed-subs --write-sub --ffmpeg-location . \ https://www.youtube.com/watch?v=xxxxxxxxxxx
On Windows: Make sure it's all one one line - cmd shell doesn’t respect
\ to join the lines.
If the audio, video and subtitles are all separate files, e.g.
english.srt, the open-source FFmpeg tool can merge these streams into a single file, e.g.
ffmpeg -i video.mp4 -i audio.m4a -i english.srt \ -c:v copy -c:a copy -c:s mov_text \ merged.mp4
ffmpeg can handle more streams, e.g. multiple audio tracks with respective subtitles. According to this Stack Overflow answer, it’ll be something like this:
ffmpeg -i video.mp4 -i english.mp3 -i german.mp3 \ -i english.srt -i german.srt \ -map 0:v -map 0:a -map 1:a \ -metadata:s:s:0 language=eng -metadata:s:s:1 language=ger \ -metadata:s:a:0 language=eng -metadata:s:a:1 language=ger \ -c:v copy -c:a copy -c:s mov_text \ merged.mp4
And so much more, e.g. delay subtitles (
ffmpeg -ss -60 -i subtitles.srt -c copy output.srt), convert formats (
ffmpeg -i audio.wav -c:a aac output.mp4), etc.
Again, I honestly haven’t validated any of this. So good luck!
Updated 4 July 2020: Small addition to sepecify multiple English subtitle variations with
--sub-lang en-UK,en-US,en. Use
--list-subs to get a list, and note that the list often starts wtih
Available automatic captions, which is maybe not what you want.
Updated 28 Nov 2020: Wanted to just add
en-GB but ended up re-structing a few sentences. Can’t leave well alone.