mckinley.cc Home Blog Computers

A very brief beginner's guide to youtube-dl

May 15th, 2020

Notice 2022-03-05: As youtube-dl is now effectively unmaintained, all references to youtube-dl in this guide have been replaced with yt-dlp.

yt-dlp is one of my favorite command line tools. It lets you download videos from over 1400 websites. If you want to download a video from somewhere, yt-dlp has you covered. The only problem is that it has a very daunting set of flags and options to use to make the program do different things. For the average user who just wants to download a YouTube video, it seems like a waste of time to read through all that. It absolutely isn't, but if you only plan to use this program once, here is a very basic guide on how to download a video.

Installing yt-dlp

Instructions to download it are here. Windows users should download the standalone Windows binary. Macintosh users can use either Homebrew or PIP. If you are on GNU/Linux, try installing the yt-dlp package from your distro's standard package manager. If there is no yt-dlp package, it's easiest to install it with PIP.

Running yt-dlp

yt-dlp is a command line program. That means you need to use Command Prompt on Windows, or a terminal emulator of your choice on other platforms. Open your terminal, and navigate to the folder where you downloaded yt-dlp.

-f and -F

These are the most important options in yt-dlp. Referring to the documentation, here is the description for these options

-f, --format FORMAT Video format code, see "FORMAT SELECTION" for more details
-F, --list-formats List available formats of each video.

Go ahead and run yt-dlp --list-formats [link] and take a look at the output. You should see a list of available formats. Choose the desired video and audio quality, and run the command again, this time with the format flag and a format like this:

yt-dlp --format ${VIDEO_CODE}+${AUDIO_CODE} ${URL}

yt-dlp --format 299+140 https://www.youtube.com/watch?v=pjzQHf_VlbY

You can also just use bestvideo and bestaudio to automatically use the highest quality video and audio possible. Example:

yt-dlp --format bestvideo+bestaudio https://www.youtube.com/watch?v=pjzQHf_VlbY

Downloading FFmpeg

Downloading videos may not work if you don't have ffmpeg installed. Download it here, or use your preferred package manager. On Windows, there are builds available here. Scroll down the page to the "Release" section and download ffmpeg-release-essentials.zip. (or ffmpeg-release-essentials.7z if you have 7-zip installed) The file you're looking for is ffmpeg-[version number]-essentials_build/bin/ffmpeg.exe when you open the downloaded archive. Copy that file to the same folder yt-dlp.exe is in, and try the command again.

Conclusion

Congratulations, you've just downloaded a video with yt-dlp. There is much more to this program, and I strongly recommend reading the full documentation if you intend to use this tool any more. I hope this short guide did help you, though. Happy downloading!

Update 2021-01-30: Added install instructions for GNU/Linux, added "bestvideo+bestaudio" example, changed video used in examples, update link and instructions for FFmpeg on Windows, change link for documentation to jump to #description

Update 2022-03-05: Replaced mentions of youtube-dl with yt-dlp, improved grammar, improved presentation with CSS disabled or in text mode browsers, fixed presentation when CSS is enabled but the site-wide style sheet is not present, updated Windows FFmpeg download instructions, fixed page <title>.

Update 2022-04-23: Remove style for <tt> tags, moved to /style.css.