PDA

View Full Version : How to use yt-dlp to download video (e.g. Youtube) in really best quality



Fli
09-13-2024, 06:21 AM
YT-DLP (https://github.com/yt-dlp/yt-dlp) is among the best cross-platform command line tools to download videos/playlists from thousands of sites, incl. Youtube.

By default it downloads best available quality. Yet the quality is not always the best.

It appears currently in 2024 that it prefers (at least in Youtube case) the widely supported codec like VP9 before better, yet much less supported AV1 codec.

So if your TV supports AV1 or you do not care, because you will play just on a modern computer, then you can add "-S vcodec" parameter to sort and prefer by the best codec. For mode details on sorting, check https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#sorting-formats

Prefer really the best codec (and possibly the quality):

-S vcodec

further limit videos up to HD (excluding FullHD and higher resolutions):

-S vcodec,res:720

further make sure that the video gets more compatible audio codec (AAC) to it if possible:

-S res:720,vcodec,acodec:aac

Download also all available subtitles:

--write-subs --sub-langs all

If you do NOT want less supported codecs like AV1, you may do:

-S res:720
or
--format="bv*[height<=720]+ba/b"

i think that this default approach (of excluding currently less compatible codecs like AV1) may be better to prevent YTD to combine weird video+audio codecs (like AV1 mp4_dash + Opus webm_dash instead of possibly more compatible AV1 mp4_dash + m4a_dash).

On Linux, i can setup an aliases/full commands like this (you would need to replace path to yt-dlp) and to have permanent alias, add the line into a file $HOME/.bashrc and then load into current environment using "source $HOME/.bashrc", then you can just run "ytd videoaddresshere" to download the video:

A) best quality - widely supported codecs
alias {youtube-dl,ytdl,ytd}='echo ">>>>> Unsupported? Try "gallery-dl" <<<<<<" && $HOME/apps/yt-dlp -U;$HOME/apps/yt-dlp --write-subs --sub-langs all --merge-output-format=mp4 --format="bv*[height<=720]+ba/b"'
B) really best quality - less supported codecs
alias {youtube-dl,ytdl,ytd}='echo ">>>>> Unsupported? Try "gallery-dl" <<<<<<" && $HOME/apps/yt-dlp -U;$HOME/apps/yt-dlp --write-subs --sub-langs all --merge-output-format=mp4 -S vcodec,res:720'