I have installed youtube-dl in my 14.04.

I can download video by following command,

$ youtube-dl [youtube-link]

But I want to know how to select available pixel quality of youtube video(i.e 1080p, 720p, 480p, etc).

In software description they said it's possible(shown in image below), but how to do..


  • 1
    The description above is obsolete. From the man page: "youtube-dl now defaults to downloading the highest available quality as reported by YouTube, which will be 1080p or 720p in some cases." – Jos Jun 21 '14 at 10:08
  • 1
    Note that YouTube has employed some sort of protection that prevents downloading tools from downloading (or even seeing) the 1080p version, but you can still download all other resolutions up to and including 720p. – thomasrutter Oct 1 '14 at 3:19
  • I know I'm a little late to the party, but here's my experience: askubuntu.com/a/1097056/327339. Use the -f best option. – Gabriel Staples Nov 29 '18 at 17:50

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

|improve this answer|||||
  • 5
    Make sure that you do not choose DASH. That will be unplayable! – ps95 Sep 13 '14 at 4:21
  • @prakharsingh95 the DASH audio only can be converted to standard wave or mp3 format using gnac or similar software. – mchid Sep 17 '14 at 12:09
  • 1
    I meant DASH Video. I tried to download 4K, but that's all in DASH format (DASH allows youtube to preserve bandwidth). It's radically different it will mostly be unplayable. – ps95 Sep 24 '14 at 19:41
  • 1
    @prakharsingh95 Yeah if anything you might be able to view the mp4 using VLC as VLC allows you to sync the video with a separate file for audio. I haven't tried it though. Have you tried converting the mp4 file from the DASH download to avi format? I think they are similar. – mchid Sep 25 '14 at 5:05
  • 2
    Yes. Dash is of course playable, but you need to mux the streams with something like avconv. Too slow for 4K. – ps95 Sep 29 '14 at 8:39

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.

|improve this answer|||||
  • 13
    thank you very much, didn't know about 137+141 – whitesiroi May 5 '15 at 14:48
  • 3
    Your example and others present easy choices for the audio - that is, for high quality, choose the one with highest bitrate value. I recently however found myself faced with a choice between DASH audio , opus @160k or DASH audio 126k , audio@128k (44100Hz), 1.79MiB or DASH audio 127k , m4a_dash container, aac @128k (44100Hz), 1.94MiB. I had to choose but am uncertain about quality, or perhaps compatibility. – user643722 Jun 10 '15 at 12:13
  • 1
    The best thing about youtube-dl is that it is multi-platform. This solution doesn't just work on Linux, but also on Mac and Windows. Thank you! – Antony Jun 2 '16 at 23:19
  • 3
    Nowadays this is the default, but only if you have avconv (libav) or ffmpeg installed to do the file conversion. For Windows, you want to set --ffmpeg-location in %APPDATA%\youtube-dl\config.txt to the directory where avconv/ffmpeg is installed. If you've got a low-end system you might want -f bestvideo[fps<=30]+bestaudio in there as well, to avoid 60fps video. – GreenReaper Apr 6 '18 at 22:16

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.

|improve this answer|||||
  • 2
    I had an issue where different segments of the same video had different format codes for the same resolution (e.g. hls-1476 for video 1 of 2 and hls-1665 for video 2 of 2 where both were 540p) so I couldn't just use "-f hls-1476" or "-f hls-1665" or I'd get "ERROR: requested format not available" Your command examples helped me retrieve what I wanted. – ssnobody Jan 22 '17 at 21:37
  • 2
    +1 for ~/.config/youtube-dl/config – Marinos An May 22 '17 at 18:15

Some of the other options to download the best quality videos other than that mentioned here depending on your convenience is given below:

Download best mp4 format available or any other best if no mp4 available

$ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'

Download best format available but not better that 480p

$ youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]'

Download best video only format but no bigger than 50 MB

$ youtube-dl -f 'best[filesize<50M]'

Download best format available via direct link over HTTP/HTTPS protocol

$ youtube-dl -f '(bestvideo+bestaudio/best)[protocol^=http]'


Directly from youtube-dl github page

|improve this answer|||||
  • How to combine ext=mp4 && height<=480 && filesize<50M ? – mrgloom Jun 21 '19 at 12:14
  • I use this youtube-dl -f 'best[ext=mp4]+best[height<=480]+best[filesize<100M]' youtube.com/watch?v=oInZYvMAjyw – ejabu Feb 12 at 0:53

A bash wrapper script that prompts for the format, which includes all available renditions, including audio-only, video-only, and then streams the video/audio with mpv.

Accepts both absolute youtube URLs and video IDs.

#!/ usr/bin/env bash
# Download youtube video with desired quality

# youtube-dl accepts both fully qualified URLs and video id's such as AQcQgfvfF1M


echo "Fetching available formats for $url..."
youtube-dl -F "$url"
read -p "Please enter the desired quality code: " FORMAT

echo "Streaming with quality $FORMAT..."
mpv --cache=1024 $(youtube-dl -f $FORMAT -g "$url")

Sample output:

    yt.sh https://m.youtube.com/watch?v=Dax_tnZRExc
    [youtube] Dax_tnZRExc: Downloading webpage
    [youtube] Dax_tnZRExc: Downloading video info webpage
    [youtube] Dax_tnZRExc: Extracting video information
    [youtube] Dax_tnZRExc: Downloading MPD manifest
    [info] Available formats for Dax_tnZRExc:
    format code  extension  resolution note
    139          m4a        audio only DASH audio   49k , m4a_dash container, mp4a.40.5@ 48k (22050Hz), 308.75KiB
    249          webm       audio only DASH audio   50k , opus @ 50k, 271.91KiB
    250          webm       audio only DASH audio   70k , opus @ 70k, 366.63KiB
    171          webm       audio only DASH audio  118k , vorbis@128k, 652.50KiB
    140          m4a        audio only DASH audio  127k , m4a_dash container, mp4a.40.2@128k (44100Hz), 820.00KiB
    251          webm       audio only DASH audio  130k , opus @160k, 705.84KiB
    160          mp4        256x144    DASH video  109k , avc1.4d400c, 13fps, video only, 703.64KiB
    278          webm       256x144    144p  111k , webm container, vp9, 25fps, video only, 439.72KiB
    242          webm       426x240    240p  243k , vp9, 25fps, video only, 623.95KiB
    133          mp4        426x240    DASH video  252k , avc1.4d4015, 25fps, video only, 1.54MiB
    134          mp4        640x360    DASH video  388k , avc1.4d401e, 25fps, video only, 1.24MiB
    243          webm       640x360    360p  458k , vp9, 25fps, video only, 1.19MiB
    135          mp4        854x480    DASH video  761k , avc1.4d401e, 25fps, video only, 2.40MiB
    244          webm       854x480    480p  893k , vp9, 25fps, video only, 2.00MiB
    136          mp4        1280x720   DASH video 1382k , avc1.4d401f, 25fps, video only, 4.56MiB
    247          webm       1280x720   720p 1754k , vp9, 25fps, video only, 3.94MiB
    137          mp4        1920x1080  DASH video 2350k , avc1.640028, 25fps, video only, 8.48MiB
    248          webm       1920x1080  1080p 2792k , vp9, 25fps, video only, 8.09MiB
    17           3gp        176x144    small , mp4v.20.3, mp4a.40.2@ 24k
    36           3gp        320x180    small , mp4v.20.3, mp4a.40.2
    43           webm       640x360    medium , vp8.0, vorbis@128k
    18           mp4        640x360    medium , avc1.42001E, mp4a.40.2@ 96k
    22           mp4        1280x720   hd720 , avc1.64001F, mp4a.40.2@192k (best)
    Please enter the desired format #

If you want to download the video as opposed to stream it, just remove the mpv --cache=1024 part and the dollar sign with brackets.

|improve this answer|||||

How to get the best video quality available.

This answer here, with the most votes, should be right to give you the best video quality available, but....it's not. bestvideo+bestaudio seems to choose only the best video and best audio of the options that are video only and audio only, then it merges the two together. Note that this also appears to be identical to the default behavior of youtube-dl. However, on the video I was looking at, the best quality was a single, pre-merged file that was already in a format with combined video and audio. The bestvideo+bestaudio option did NOT choose this best quality 720p file because it was looking only for separate video and audio files. Details below.

Solution? Have it grab the best single file which contains both video and audio in one instead, with this:

youtube-dl -f best https://youtu.be/FWGC9SqA3J0

In short: use the -f best option, NOT the -f bestvideo+bestaudio option!


enter image description here

More specifically, see below for the results of running

youtube-dl -F https://youtu.be/FWGC9SqA3J0

in order to see what video 'F'ormats are availabe for download:

gabriel ~ $ youtube-dl -F https://youtu.be/FWGC9SqA3J0
[youtube] FWGC9SqA3J0: Downloading webpage
[youtube] FWGC9SqA3J0: Downloading video info webpage
[youtube] FWGC9SqA3J0: Downloading MPD manifest
[youtube] FWGC9SqA3J0: Downloading MPD manifest
[info] Available formats for FWGC9SqA3J0:
format code  extension  resolution note
139          m4a        audio only DASH audio   50k , m4a_dash container, mp4a.40.5@ 48k (22050Hz), 2.30MiB
249          webm       audio only DASH audio   51k , opus @ 50k, 2.34MiB
250          webm       audio only DASH audio   62k , opus @ 70k, 2.85MiB
171          webm       audio only DASH audio  103k , vorbis@128k, 4.68MiB
251          webm       audio only DASH audio  109k , opus @160k, 5.10MiB
140          m4a        audio only DASH audio  130k , m4a_dash container, mp4a.40.2@128k (44100Hz), 6.13MiB
160          mp4        256x138    DASH video  108k , mp4_dash container, avc1.4d400b, 24fps, video only
134          mp4        640x348    DASH video  142k , mp4_dash container, avc1.4d401e, 24fps, video only, 3.42MiB
133          mp4        426x232    DASH video  242k , mp4_dash container, avc1.4d400c, 24fps, video only
136          mp4        1280x694   DASH video  473k , mp4_dash container, avc1.4d401f, 24fps, video only, 8.01MiB
135          mp4        854x464    DASH video 1155k , mp4_dash container, avc1.4d4014, 24fps, video only
17           3gp        176x144    small , mp4v.20.3, mp4a.40.2@ 24k, 1.63MiB
36           3gp        320x174    small , mp4v.20.3, mp4a.40.2, 2.98MiB
43           webm       640x360    medium , vp8.0, vorbis@128k, 7.44MiB
18           mp4        640x348    medium , avc1.42001E, mp4a.40.2@ 96k, 8.54MiB
22           mp4        1280x694   hd720 , avc1.64001F, mp4a.40.2@192k (best) 

Notice that row 22 says "(best)" to the far right of it. This is the only option which offers hd720 quality, which is the best quality I can get when watching this video in a web browser on YouTube. It is the clearest and has the best definition. When I use either of the commands recommended by the top answer:

youtube-dl -f bestvideo+bestaudio https://youtu.be/FWGC9SqA3J0


youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 https://youtu.be/FWGC9SqA3J0

I end up with a video that is both lower quality/lower resolution, and has a larger file size. I don't understand it exactly, but the -f best option is definitely the only one that truly gives me the best resolution.

Here's some screenshots from a tutorial video I was watching showing electronic circuit diagrams in the video. Notice how the latter one is much higher quality and more legible (click on each image and compare the tiny font in a zoomed-in view):

  1. Using the lower quality -f bestvideo+bestaudio option accepted here as the right answer (OR just using the default option: youtube-dl https://youtu.be/FWGC9SqA3J0):

    • enter image description here
    • Notice how fuzzy the icons are at the top, and how difficult to read are the open window and tiny words within it!
    • This is significantly worse than the quality I get when watching online at YouTube directly in the browser.
    • This option also takes up more memory for some reason: the video is 18.0 MB, and it took longer for my system to download and re-combine (audio + video) than the -f best option below, which only had to do one download and no recombining since it was already one file.
  2. Using the higher quality -f best option which I recommend:

    • enter image description here
    • Notice how much clearer the small icons at the top and small font in the window are!
    • This is the identical resolution to what I get when watching in the highest resolution possible directly in the browser on YouTube.
    • This option also takes up less memory for some reason: the video is 14.8 MB.

Additional Reading:

See man youtube-dl for details.

|improve this answer|||||
  • 1
    odd that I see listings for 1920x1080 options, but the 1280x720 (hd720) option still says "best" – nmz787 Jan 21 '19 at 18:07
  • All your screenshots are showing some electronics stuff. – localhost Jun 16 '19 at 6:36
  • @localhost, that's right. They are all screenshots from the video whos URL you see in all of my code snippets throughout the post: youtu.be/FWGC9SqA3J0. – Gabriel Staples Jun 16 '19 at 8:21
  • @GabrielStaples Aah. Yes, that makes sense. Sorry about that. – localhost Jun 16 '19 at 23:23
  • Is it not weird, that the highest number on the left side does not correspond to the highest amount of pixels in the screen in your code example of available formats? – Ben Sep 24 '19 at 7:21

By default, youtube-dl will pick the best quality.

|improve this answer|||||

I am a disk saver, so I download videos of the format 1280 x 720,
because 4k videos takes more size of my hard disk.
So I add youtube-dl in ~/.bashrc file like given below

Setting a work -

open terminal and type

  • nano ~/.bashrc
    now go to very bottom of the file and add given below command
  • alias yt='youtube-dl -if best'
  • save file by pressing Ctrl o then press Enter
  • exit file by pressing Ctrl x
  • and last run command source ~/.bashrc in terminal

Experiment -

Open terminal and type
yt https://www.youtube.com/watch?v=puPUJlV1-W4
It will start downloading video with the best quality.

Explanation -
Bash allows us to define aliases which act like shortcuts to bash commands
in our case we define alias as -
alias yt='youtube-dl -if best'
where yt is the shortcut command for 'youtube-dl' which gives relief
our fingers to type long command.
You can write anything at the place of yt.
I set a flag -i in youtube-dl -if best
which means

It will Continue on download errors, for example to skip unavailable videos in a playlist

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.