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..
To download a video, you type the URL after the command like so:
To select the video quality, first use the
-F
option to list the available formats, here’s an example,Here’s the output:
The best quality is 22 so use
-f 22
instead of-F
to download the MP4 video with 1280x720 resolution like this:Or optionally use the following flags to automatically download the best audio and video tracks that are available as a single file:
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:
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:
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). Ifffmpeg
oravconv
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: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 runyoutube-dl
again this time specifying the audio and video: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:
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: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.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
Download best format available but not better that 480p
Download best video only format but no bigger than 50 MB
Download best format available via direct link over HTTP/HTTPS protocol
Reference:
Directly from youtube-dl github page
Update: use
yt-dlp
instead ofyoutube-dl
! It's a fork off ofyoutube-dl
and is much better-maintained and works much better!First, ensure you have the latest version of
youtube-dl
installed.How to install the latest version of
youtube-dl
See:
Run these commands:
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 always.
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 ofyoutube-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. Thebestvideo+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:
In short: to get the best quality, you may need to use the
-f best
option, NOT the-f bestvideo+bestaudio
option! Try both to see. It could vary from video to video.Quick reference of various examples of
youtube-dl
in generalI need a quick place to look for common commands. Here are some:
See:
Proof that
-f best
is better than-f bestvideo+bestaudio
in at least some cases:(Note: all circuit schematic images below are actually screenshots from this electrical-engineering-related video tutorial: Video One- Getting started with LTspice).
More specifically, see below for the results of running
in order to see what video 'F'ormats are availabe for download:
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:
OR:
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):
-f bestvideo+bestaudio
option accepted here as the right answer (OR just using the default option:youtube-dl 'https://youtu.be/FWGC9SqA3J0'
):-f best
option below, which only had to do one download and no recombining since it was already one file.-f best
option which I recommend:Additional Reading:
man youtube-dl
for details.A bash wrapper script that prompts for the format, which includes all available renditions, including audio-only, video-only.
Accepts both absolute youtube URLs and video IDs.
Sample output:
Here is an explanation of streams/formats for anyone new to youtube-dl.
Some video sites, such as youtube, offer not only different resolutions of video to download, but have options in youtube-dl called formats to download video and audio separately. For the case of youtube, it will only offer the highest quality video and highest quality audio separately. Here's an example output of using
-F
flag to show all formats available:So there's a lot of different formats, but some are labelled "audio only" or "video only". If I selected to download one of those formats by using the specified format code such as with
-f 137
, I would really get either an audio file or a video file with no audio, which is usually not what you want. If I had ffmpeg installed and specified both video and audio formats with-f 137+140
, then youtube-dl would download video and audio and afterwards combine them together into one video file.If you don't have ffmpeg installed, youtube-dl will by default select the highest quality format that has both audio and video. This maxes out at 720p (and is usually specified by format code 22 so you would download with
-f 22
). If you do have ffmpeg installed, youtube-dl will be able download the real best quality video (1080p or better if available) and best quality audio, and after downloading mux (combine) them together into one video file so this is what I recommend.Summary: install ffmpeg and then you will be able to simply do
youtube-dl [youtube url]
without any flags to get the best quality video and audio automatically in one output video file.By default, youtube-dl will pick the best quality.
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 belowSetting 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'
source ~/.bashrc
in terminalExperiment -
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
youtube-dl
's idea of best is not perfect. Take this example for instance :The following command:
produces far better results than this usage:
There seems to be further bugs as trying to specify the height filters to limit to 1080p doesn't work. It still downloads the 4k variant (which notably is not that marked as best either)