Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] odd ba* format selection? #979

Closed
3 tasks done
probablykasper opened this issue Sep 15, 2021 · 4 comments
Closed
3 tasks done

[Question] odd ba* format selection? #979

probablykasper opened this issue Sep 15, 2021 · 4 comments
Labels
question Question

Comments

@probablykasper
Copy link

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

I'm running the following command:

yt-dlp -x -f 'ba*' --format-sort 'abr,codec' 'https://www.youtube.com/watch?v=nzLw6GMQ65I'

As a result, I get a 2.9MB .m4a file. When I pass -F it shows an ABR of 0k (format ID 22).

If I instead use -f 'ba', I get 3.3MB .opus file. Shouldn't ba* have selected this .opus file to begin with, since it's larger?

@probablykasper probablykasper added the question Question label Sep 15, 2021
@pukkandan
Copy link
Member

pukkandan commented Sep 15, 2021

I can see why you would think that. But

  • ba, bestaudio: Select the best quality audio-only format. Equivalent to best*[vcodec=none]
  • ba*, bestaudio*: Select the best quality format that contains audio. It may also contain video. Equivalent to best*[acodec!=none]

ba* is NOT "select the format that contains the best quality audio"

A format that contains a video stream is always considered better by yt-dlp than a format without it. Since 22 contains both an audio and a video stream, it is considered better than all audio-only streams. Hence why 22 gets selected. Hopefully I explained this clearly


But the more important question is how do you select "the format that contains the best audio"?

In theory, you can achieve this by asking yt-dlp to not consider video streams to be always better than audio-only (which is controlled by the sorting parameter hasvid) by using --format-sort-force. So --format-sort-force -S "abr,acodec" will give you what you want.

BUT, as you have already noticed, yt-dlp shows the abr of format 22 as 0k. This is because we do not know the vbr and abr of this format, but only know the tbr. For simplicity, this tbr is shown in the vbr column when listing formats, with abr set to 0. This means we do not know what is the sound quality of this format and so will sort it with least priority when using the above method. So, this becomes the equivalent of just using -S abr -f ba

tldr; you can't for sure. Just use ba to get the best with the limited information we have

@probablykasper
Copy link
Author

Ah I see, that explains it really well. Thanks!

@probablykasper
Copy link
Author

Looks like the actual flag is --format-sort-force, not -force-format-sort like it mentions in the "Sorting Format" section in the docs

@pukkandan
Copy link
Member

thanks I'll fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question
Projects
None yet
Development

No branches or pull requests

2 participants