downloading from youtube for fun and archival
this page will guide you through using yt-dlp for downloading videos from not only youtube, but like 30 thousand other sites that it supports. this guide will assume zero prior knowledge on concepts like windows environment variables, using the terminal, ffmpeg, etc. (the *nix instructions will assume basic familiarity with your package manager and the terminal). I made this because a group I’m in recently guided someone through using yt-dlp, and it was slightly disorganized. this should serve as a good introductory guide that you can link to whoever needs to hear it
I don’t want to use yt-dlp
you can use cobalt if you want to download without getting programs yourself. cobalt’s pretty damn user friendly and quick
obtaining yt-dlp
windows
by far the easiest method to “get and go” yt-dlp, as well as receive automatic updates, is to use a windows package manager. when I used windows, I was very in love with scoop, and as such I recommend using it
installing scoop is as simple as two lines in a powershell window, both of which are featured on the scoop website. opening powershell can be done from the start menu by searching “powershell”. I don’t want to rewrite the links were in the event any change, but the github should also give you help
after scoop is installed, you should be able to open a command prompt window and run scoop
. you can open command prompt by start menu -> searching cmd
, or windows key + r -> cmd
to install yt-dlp from here, run scoop install yt-dlp
. in the event youtube breaks something and you feel like yt-dlp needs an update, you can type scoop update yt-dlp
*nix
yt-dlp should be available from your package repositories. if yt-dlp is, for some reason, not packaged for your system, you can install python’s pip
for your system (name may differ from distribution to distribution), then install yt-dlp with pip install yt-dlp
obtaining ffmpeg
ffmpeg is an incredibly powerful command line tool for converting videos from one format to another. it also does much more, but for our purposes, only that part is relevant
windows
if you used scoop for installing yt-dlp, you should be able to install ffmpeg via scoop install ffmpeg
*nix
ffmpeg should be packaged for your system. if it’s not, you’ll have to either get the binaries from someone else or compile it yourself. that is outside the scope of this page
running and configuration
if you wanted, you could start doing yt-dlp video-link-here
and start downloading videos right now. however, there’s a few configuration options I think you should set first
configuration
on windows, the recommended configuration file path is %APPDATA%/yt-dlp/config
. open explorer and type %APPDATA%
in the titlebar to go to the appdata folder. make the directory yt-dlp
then, inside the directory, make the file config
. on *nix, the recommended configuration file path is ${XDG_CONFIG_HOME}/yt-dlp/config
. by default, unless you have changed XDG_CONFIG_HOME
to be something else, this should be ~/.config/yt-dlp/config
. go ahead and make the file at that path if it isn’t there already
in the configuration file, put the following:
-o "%(title).128B [%(id)s].%(ext)s"
--merge-output-format mkv
--yes-playlist
--add-chapters
the first line is a good output filename template; the second line merges videos into the mkv
container; the third line by default downloads playlists if you specify a playlist link; and the forth line adds “chapters” to the output video based on metadata on the site
notes on file formats
video files, along with some audio files, are secretly two formats in one. there is a “container” format, which is most likely what you’re familiar with when you think about a video file. this is the mp4, the webm, the mkv, etc. containers are not what actually make up the video itself, but rather contain metadata that helps serve the video. the second format is the “codec” of the file, which is what actually comprises the video itself. codecs are decoded to pixels by your processor and are what actually put images on your screen. some common codecs are h264/x264 (the most common “supported everywhere” one), h265/x265, vp8 (default for webm container videos), vp9, av1, etc.
youtube currently stores videos in a few formats:
- webm container, vp9 vcodec, no audio, served via DASH
- mp4 container, h264 vcodec, no audio, served via DASH
- mp4 container, h264 vcodec, aac acodec, served directly
- webm container, no video, opus acodec, served via DASH
- m4a container, no video, aac acodec, served via DASH
when using your browser, you’re probably being served a webm DASH video with a webm DASH audio that are combined together on the fly. this probably has some benefits for google, I don’t exactly know, but the point is that all these formats exist
by default, yt-dlp tries to get the best quality possible from a video. this results in it usually downloading the webm vp9 video and the webm opus audio, then combining them together via ffmpeg, preserving the original codecs of both. notice how we set the output format that it merges to to mkv
. this is due to the fact that mkv
is a very good “general” container, in that it supports a wide range of audio and video codecs, in fact all the ones that youtube serves. the mp4 container is unable to use the vp9 codec, and the webm container is unable to use the h264 codec. this can get pretty frustrating, as some places might not support certain video containers and/or codecs (notably, vp9, the highest quality format youtube serves, isn’t really widespread across the board as it’s new)
anyway, mkv is a container format that is almost never conventionally “supported” outside of video players like VLC, MPV, etc. that sounds like a horrible thing to merge to, but it saves headaches if you’re only using the videos for your own purposes. if you want to learn about transcoding the video, switching containers, or downloading other formats from yt-dlp, read on!
changing formats
let’s say you only want the audio from a youtube video. to download only audio, you can run yt-dlp -f ba video-link
. the -f ba
means “download the format that is the best audio”. this is usually going to result in a webm file with an opus audio codec. now, webm isn’t exactly meant to be an audio-only format, so a lot of sites and programs are going to be really confused if you supply this to them. here is where ffmpeg comes to the rescue!
to change the container of this audio, you can run ffmpeg -i input_file.webm -c:a copy output_file.opus
. you should replace input_file
with the file you want to transcode (for windows and some *nix terminal emulators, you’re able to drag the file into the terminal window and it’ll fill it in), and replace output_file
with the output path to the video (if you’re not too familiar with directories in the terminal, you can just drag the same file into the window, then change a character in the title so that it doesn’t overwrite the input file
opus containers are generally more recognized as audio across the board. some services, notably discord, won’t “embed” this audio. you can trick these services by simply changing the file extension to ogg
since the containers are similar enough
for videos, the recommended “supported” container to put them in is mp4 with an h264 codec. in ffmpeg, this looks like ffmpeg -i input_file output_file.mp4
(ffmpeg automatically assumes h264 codec, so no need to specify it)
PLEASE NOTE! every time you change formats without using -c copy, you naturally lose quality as you’re converting to a lossy format (the only exceptions to this are when using inherently lossless formats, like flac, or with niche codec stuff you’ll never need). please keep this in mind if video quality is important!