question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible for youtube-dl prefer certain formats within a given resolution?

See original GitHub issue

Checklist

  • I’m asking a question
  • I’ve looked through the README and FAQ for similar questions
  • I’ve searched the bugtracker for similar questions including closed ones

Question

Hello!

I would like youtube-dl to always download the highest resolution video available. However, if a particular resolution is available as either a VP9 or an H.264 stream, I want youtube-dl to prefer H.264.

So, I want youtube-dl to select the VP9 stream for this video, because the highest resolution available is not offered in H.264. However, I want youtube-dl to select the H.264 for this and this video, because the highest resolutions available (1080p and 540x480, respectively) are offered in both H.264 and VP9.

The format selector I’m currently using (bestvideo[vcodec!^=av01]+bestaudio[ext=m4a]/best) downloads the 1080p video as H264 as desired, but it downloads the 540x480 video as VP9.

Is there a format selector that will make youtube-dl do what I want? Thank you so much!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Wowfunhappycommented, Feb 3, 2021

Very clever @Roasty-Float, thank you!

The ability to select by height is nifty, I didn’t know you could do that. I do wish I didn’t have to rely on resolution since the formats Youtube offers per resolution could theoretically change some day, but then it has been pretty consistent about this for many years.

Btw, the final selector I went with is:

((bestvideo[height>1080][vcodec!^=av01]/bestvideo[vcodec^=avc1])+bestaudio[ext=m4a])/best

Because I want to make sure Youtube doesn’t ever download av1 streams, which I’ve found does happen otherwise for some videos.

0reactions
Wowfunhappycommented, Aug 16, 2021

Because best means the best quality that’s available as a single file, which on Youtube is (almost?) always 720p. Whereas bestvideo+bestaudio means “the best individual video stream combined with the best individual audio stream”.

You could leave out best altogether if you only download from Youtube, but that would fail on other websites which don’t offer separate audio and video streams.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to select video quality from youtube-dl? - Ask Ubuntu
For most HD videos the top answer is still the way to go, because "best" alone tends to prefer either format code 22...
Read more >
Get youtube-dl video for a particular size, like 480p or 720p
If you want to only download some DASH formats (for example if you are not interested in getting videos with a resolution higher...
Read more >
Youtube-dl Tutorial With Examples For Beginners - OSTechNix
Youtube-dl is also available in the official repositories of some Linux ... Like already said, we can group the format selectors to get...
Read more >
Why i'm failing to download mp4 file using youtube-dl in python
Issue here is that some videos do not have certain formats available. So you might want to first check the formats available with...
Read more >
Ubuntu Manpage: youtube-dl
When given in the global configuration file /etc/youtube-dl.conf: Do not read ... You can get the list of available format codes for particular...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found