|
Home > Wiki > YouTube Articles
All articles are licensed under CC0 1.0 making them public domain.
Ripping a video with the best quality #
Last updated February 2021
youtube-dl seems to pick the best quality based on bitrate, this is a flawed method of selection. Sometimes it will pick a 720p over a 1080p file and is further complicated by new video codecs like h.265 and vp9 which produce better quality video at lower bitrates than older codecs like h.264.
If I want the best quality I download the video and audio separately and then merge them with ffmpeg.
Requirements
Steps
Look at all the available formats YouTube provides for a video. youtube-dl -F https://www.youtube.com/watch?v=rqZYJ-NVQhI
First pick a video format, look for the highest resolution and then look at the bitrate and codec of each of a particular resolution. Your choice will most likely be between h.264 (avc1) and vp9. Here are some tips for picking:
IMPORTANT: vp9 has poor compatibility and requires VLC player to play outside of a browser. If you're looking for compatibility, your best option is to always take the h.264 (avc1) version instead of re-encoding the vp9 file.
vp9 generally creates videos with a ~60% smaller file with similar video quality to h.264 (will be listed at avc1). If the two options are a h.264 video vs a vp9 video and the bitrate/filesize are similar, the vp9 version is most likely the highest quality version.
Don't worry about "audio only", we will manually grab the audio.
Once you've picked the video format take a note of the number in the first column, e.g. 303, and download it with this number: youtube-dl -f 303 "https://www.youtube.com/watch?v=t4Zi892Xn_w" -o chance-video.%(ext)s
Now grab the best audio file: youtube-dl -f best "https://www.youtube.com/watch?v=t4Zi892Xn_w" --extract-audio -o chance-audio.%(ext)s
Merge the video and audio: ffmpeg -i chance-video.mp4 -i chance-audio.m4a -c:v copy -c:a copy change.mp4
NOTE: If you downloaded a vp9 video you'll need to throw the video and audio into a .mkv file and use VLC player to watch it. A normal .mp4 file can't hold a vp9 video.
Make sure you change the filenames if you copy and paste this line.
Watching a video without a browser #
Last updated February 2021
The video player mpv can play YouTube videos without opening the browser.
- Download both
mpv and youtube-dl.
mpv "https://www.youtube.com/watch?v=zxwfDlhJIpw"
Audio Only
Add the --no-video flag to the command.
Custom filename with youtube-dl #
Last updated February 2021
youtube-dl "https://www.youtube.com/watch?v=zxwfDlhJIpw" -o "download.%(ext)s"
Explained
You can give it any name and extension you desire but when unsure of the extension needed for the download you can include create a template to insert info into the name. Template names are encased in %(name)s, e.g. -o "download.%(ext)s"
There are lots of names and the most common are listed below. All names can be found on the youtube-dl man page under "OUTPUT TEMPLATES".
id (string): Video identifier
title (string): Video title
url (string): Video URL
ext (string): Video filename extension
|