How to select video quality from youtube-dl?
To download a video, you type the URL after the command like so:
youtube-dl 'http://www.youtube.com/watch?v=P9pzm5b6FFY'
To select the video quality, first use the -F
option to list the available formats, here’s an example,
youtube-dl -F 'http://www.youtube.com/watch?v=P9pzm5b6FFY'
Here’s the output:
[youtube] Setting language
[youtube] P9pzm5b6FFY: Downloading webpage
[youtube] P9pzm5b6FFY: Downloading video info webpage
[youtube] P9pzm5b6FFY: Extracting video information
[info] Available formats for P9pzm5b6FFY:
format code extension resolution note
140 m4a audio only DASH audio , audio@128k (worst)
160 mp4 144p DASH video , video only
133 mp4 240p DASH video , video only
134 mp4 360p DASH video , video only
135 mp4 480p DASH video , video only
136 mp4 720p DASH video , video only
17 3gp 176x144
36 3gp 320x240
5 flv 400x240
43 webm 640x360
18 mp4 640x360
22 mp4 1280x720 (best)
The best quality is 22 so use -f 22
instead of -F
to download the MP4 video with 1280x720 resolution like this:
youtube-dl -f 22 'http://www.youtube.com/watch?v=P9pzm5b6FFY'
Or optionally use the following flags to automatically download the best audio and video tracks that are available as a single file:
youtube-dl -f best 'http://www.youtube.com/watch?v=P9pzm5b6FFY'
If you encounter any error during the muxing process or an issue with the video quality selection, you can use one of the following commands:
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 'http://www.youtube.com/watch?v=P9pzm5b6FFY'
or as Gabriel Staples pointed out here, the following command will typically select the actual best single file video quality resolution instead of video quality bit-rate:
youtube-dl -f best 'http://www.youtube.com/watch?v=P9pzm5b6FFY'
These commands will ensure you download the highest quality mp4 video and m4a audio from the video as a single file or will merge them back into a single mp4 (using ffmpeg
in my case). If ffmpeg
or avconv
is not available, youtube-dl
should fall back to the single file -f best option
instead of the default.
Click here for more detailed information and some different examples.
Also, click to see this related answer by Gabriel Staples.
Source: www.webupd8.org/2014/02/video-downloader-youtube-dl-gets.html
Source: github.com/rg3/youtube-dl
You can download 1080p using youtube-dl
, but you need to do a little extra work. Usually it will only download 720p as its max even if you can see 1080p on youtube.com.
Run with -F
to see available formats:
youtube-dl -F https://www.youtube.com/watch\?v\=-pxRXP3w-sQ
171 webm audio only DASH audio 115k , audio@128k (44100Hz), 2.59MiB (worst)
140 m4a audio only DASH audio 129k , audio@128k (44100Hz), 3.02MiB
141 m4a audio only DASH audio 255k , audio@256k (44100Hz), 5.99MiB
160 mp4 256x144 DASH video 111k , 12fps, video only, 2.56MiB
247 webm 1280x720 DASH video 1807k , 1fps, video only, 23.48MiB
136 mp4 1280x720 DASH video 2236k , 24fps, video only, 27.73MiB
248 webm 1920x1080 DASH video 3993k , 1fps, video only, 42.04MiB
137 mp4 1920x1080 DASH video 4141k , 24fps, video only, 60.28MiB
43 webm 640x360
18 mp4 640x360
22 mp4 1280x720 (best)
notice that youtube-dl
has labeled the last option 1280x720 as the 'best' quality and that's what it will download by default, but that the line starting with 137 is actually higher quality 1920x1080. Youtube has separated the video and audio streams for the lines labeled DASH so we also need to pick the highest quality audio which in this case is the line starting with 141. Then we run youtube-dl
again this time specifying the audio and video:
youtube-dl -f 137+141 https://www.youtube.com/watch\?v\=-pxRXP3w-sQ
and it will download the 1080p video and auto-merge it with the highest-quality audio. It should also auto-deleted the separate downloaded parts. This method is a little extra work, but will get you the best results.
To select specific resolutions, you can specify the size and audio quality so they get selected automatically - so for 480p:
-f 'bestvideo[height<=480]+bestaudio/best[height<=480]'
with bestvideo[height<=720]+bestaudio/best[height<=720]
for 720p etc. This can added to config file at ~/.config/youtube-dl/config
(or even /etc/youtube-dl.conf
) so you don't get oversized downloads:
mkdir ~/.config/youtube-dl
echo "-f 'bestvideo[height<=720]+bestaudio/best[height<=720]'" >> ~/.config/youtube-dl/config
You can use --ignore-config
if you want to disable the configuration file for a particular youtube-dl run.
Please note that fairly often it will have to download a separate video and audio steam and merge them.
For more examples see youtube-dl
's doucmentation.