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

Is there an option that yields the best available audio quality among all formats? #9302

Open
4 of 8 tasks
Bl-rp opened this issue Apr 24, 2016 · 44 comments
Open
4 of 8 tasks
Labels

Comments

@Bl-rp
Copy link

Bl-rp commented Apr 24, 2016

  • I've verified and I assure that I'm running youtube-dl 2016.04.24
  • At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones
  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other
  • Single video: https://www.youtube.com/watch?v=J9bjJEjK2dQ

I want to be able to download the best quality audio available. -f bestaudio doesn't always yield the best available audio, as sometimes the best audio only version has worse audio than the best video+audio version. See the example video: -f bestaudio yields 125 kbps m4a, and -x -f best yields 192 kbps m4a. I think I've seen an example of -f best yielding worse quality than -f bestaudio too, but I'm not sure.

Does -f best in fact always yield the best audio?

If not, is there an option that always yields the best audio?

If not, I would like to request such a feature. In fact, the way it's described, it sounds like the default option is intended to yield the best quality audio and video, and that's certainly what I expected. Also, is it guaranteed that either -f best or -f bestaudio yields the best audio? It's conceivable that there could be a video where the best audio-only version has medium quality, the best overall version has medium quality audio and high quality video, and there exists a version with high quality audio and low quality video, and then the answer would be 'no'.

@dstftw
Copy link
Collaborator

dstftw commented Apr 24, 2016

Short: there is no such option.
You completely misinterpret the notions. bestaudio is best audio-only format not best overall audio. best is the best audio+video format not best overall audio. However most of the time bestaudio is indeed best overall audio and your example is rare exception. Thus bestaudio+bestvideo produces best overall audio+video quality that is better than best most of the time. Read FAQ on format selection. Currently there is no notion to denote best overall audio or best overall video.

@dstftw dstftw added the request label Apr 24, 2016
@Bl-rp
Copy link
Author

Bl-rp commented Apr 24, 2016

You completely misinterpret the notions.

I don't, actually.

@nfp0
Copy link

nfp0 commented Aug 6, 2016

@Bl-rp interpreted the meaning of those options perfectly and his request is perfectly valid.

He's requesting an option like "bestavailableaudio" which decides, among all audio-only formats AND video+audio formats, where the best possible audio is. If the audio is an audio-only format, then simply download it, otherwise, if the best audio is contained in a video+audio format, then download the file and extract the audio, as with the -x option.

I also would like to see the feature implemented. While it is true it is not common, it sometimes happens that the audio in the video+audio format is better than any audio-only format.

EDIT: In fact, the default download Youtube-dl does on that video (no format options supplied) is actually one of the worst quality videos. Something is not right in the quality decision.

@yan12125
Copy link
Collaborator

yan12125 commented Aug 7, 2016

In fact, the default download Youtube-dl does on that video (no format options supplied) is actually one of the worst quality videos. Something is not right in the quality decision.

Example?

@nfp0
Copy link

nfp0 commented Aug 7, 2016

Example?

I was refering to the video on the OP by @Bl-rp. This one: https://www.youtube.com/watch?v=J9bjJEjK2dQ
It downloads a 426x240 video when there is a 720p available. It's worth noting that the 426x240 video is reported being the video with the highest file size. Could youtube-dl be using this value as the deciding factor?

@yan12125
Copy link
Collaborator

yan12125 commented Aug 8, 2016

In the current implementation, bitrates have a higher priority than resolutions. There are already lots of debates - some developers (including me) believe resolution should be the first key to determine the quality, while others think bitrates should be the leading criteria. See #6018, #5491 for debates and #8125 for a possible solution.

@nfp0
Copy link

nfp0 commented Aug 8, 2016

Ok I see. And what about sound? What is the criteria for choosing the best audio? Bitrate? Is format taken into account?

@yan12125
Copy link
Collaborator

yan12125 commented Aug 8, 2016

In general bitrate is the first criterion, and filesize is the second. Audio formats are not used unless --prefer-free-formats is specified. See the _sort_format function in youtube_dl/extractor/common.py for all the details.

@kanliot
Copy link

kanliot commented Sep 3, 2016

I came here to request this "feature" --extract-audio on youtube.com seems a bit random, but this is understandable.

M4a usually seems to be the highest bitrate audio on youtube, would a --prefer-m4a switch help at all?

@yan12125
Copy link
Collaborator

yan12125 commented Sep 3, 2016

would a --prefer-m4a switch help at all?

It may work in some cases but not aforementioned J9bjJEjK2dQ, where almost all audio streams are m4a.

@Bl-rp
Copy link
Author

Bl-rp commented Sep 4, 2016

Quite often .webm is "best" both among audio formats and video+audio.

@yan12125
Copy link
Collaborator

yan12125 commented Sep 4, 2016

Statistics is not reliable. A new feature should always work correctly.

@davidedelvento
Copy link

davidedelvento commented Jan 26, 2017

I think I've seen an example of -f best yielding worse quality than -f bestaudio too, but I'm not sure.

I think that's the case for youtube-dl -F https://www.youtube.com/watch?v=ByhXM9AvnQo where best yields format 22 which is audio+video mp4a.40.2@192k whereas bestaudio yields 251 which is audio-only opus @160k

I'd love to have an option to grab the best possible audio from either the audio-only or audio+video available options, and I don't think it would be hard to implement such logic. The problem is that (as far as I can tell) youtube-dl does not know (cannot know?) how much audio is in the audio+video file. Is that information available?

If not, for the example above, the format 22 has a total bitrate of 192k so it could theoretically have better audio than the 160k audio only one, if the 1280x720 video stream were supercompressed to just 10k (is that even possible? maybe not, but hopefully you get my point: it's a problem to guess the audio bitrate in an audio+video stream whose only total bitrate is known).

So the key question is: can the audio bitrate of a mixed audio+video stream be known? I don't see it in the output of -F

@yan12125
Copy link
Collaborator

yan12125 commented Feb 1, 2017

can the audio bitrate of a mixed audio+video stream be known? I don't see it in the output of -F

They are unknown before downloading if not in the output of -F

@illtellyoulater
Copy link

So what about downloading the best video, then extracting the audio, then downloading the best audio and comparing it with the extracted audio from best video? Could there be an option for this?

@yan12125
Copy link
Collaborator

@jihg: That's already possible to download multiple formats with extracting audio. For example:

youtube-dl -v -f best,bestaudio -x -o "%(title)s-%(format_id)s.%(ext)s" (some video URL)

The last step - comparing - is left to you. It's infeasible to create automatic comparing algorithms as there are quite a few audio codecs.

@illtellyoulater
Copy link

@yan12125 I mean, the same way youtube-dl compares the streams when choosing best, could be used to compare those results, couldn't it?

@yan12125
Copy link
Collaborator

I don't think there will be a simple and satisfying algorithm. For example, if you have opus@153k and mp4a.40.2@125k, is the former unconditionally better?

@illtellyoulater
Copy link

@yan12125 but then how does youtube-dl determine bestaudio ?

@yan12125
Copy link
Collaborator

how does youtube-dl determine bestaudio ?

The current implementation compares all audio-only formats by bitrates.

That said, if you don't care whether the downloaded file is the best, the second best or even the third best, comparing by bitrates is OK. If you are serious about quality, you should download all possible formats and compare them by yourselves.

@illtellyoulater
Copy link

illtellyoulater commented Sep 19, 2017

@yan12125 : given that a bestaudio file is retrieved by comparing just the bitrates/sizes of differently encoded files, then why couldn't youtube-dl go ahead and use the same criteria to compare the audio file downloaded through bestaudio with the audio file extracted from best, even though they are encoded with different codecs?

I agree on what you say that for a perfect result you should be comparing the quality manually, or at least take into account many other factors, but if the comparison criteria above are considered good enough when comparing among bestaudio streams (different codecs), then why it can't be considered good enough when comparing bestaudio with audio extracted with best?

If you don't find such an option reliable, then bestaudio should be considered not reliable as well, and therefore should not exist?

@illtellyoulater
Copy link

illtellyoulater commented Sep 19, 2017

I don't know if it can be of any interest here but with regard to this topic I just found another non-dumb youtube downloader app that similarly to youtube-dl actually analyzes all audio sources (both DASH and muxed) but goes on by picking the best audio based on the highest bitrate among all of them.

<removed>

@yan12125
Copy link
Collaborator

First, comparing bitrates of bestaudio and the audio extracted from best does not bring users much benefits than comparing audio-only formats. Second, it's already possible for users to download all possible formats and compare by themselves, so I don't see this feature a high priority. Pull requests are still welcomed, though.

If you don't find such an option reliable, then bestaudio should be considered not reliable as well, and therefore should not exist?

There are indeed quite a few discussions for best* options and callings for changes. For example, #8125, #6018.

@illtellyoulater
Copy link

illtellyoulater commented Sep 21, 2017

First, comparing bitrates of bestaudio and the audio extracted from best does not bring users much benefits than comparing audio-only formats.

@yan12125 why not? Aren't we simply comparing the bitrates of two plain audio files at that point (provided -x is used on both bestaudio and best)? Yes the two files might be encoded with different codecs, but so could be the bestaudio candidates... so, why not?

@TheNicholasNick
Copy link

TheNicholasNick commented Nov 7, 2017

bestaudio works for me, it is good enough (haven't actually spent enough time downloading all the best formats and comparing tbh)

am curious though if there is a way to download the best audio then convert to an m4a, yeah yeah, i know compressing a compressed files should result in less quality, only need to convert if it is not already a m4a though.

I have a feeling the correct answer to this question is: write a script around youtube-dl since all the information is available and adding this kind of functionality is outside of the scope of youtube-dl.

example video where perhaps the best audio is in 22 (mp4 1280x720)
https://www.youtube.com/watch?v=WPni755-Krg

format code  extension  resolution note
139          m4a        audio only DASH audio   58k , m4a_dash container, mp4a.40.5@ 48k (22050Hz), 61.24MiB
249          webm       audio only DASH audio   71k , opus @ 50k, 73.99MiB
250          webm       audio only DASH audio   88k , opus @ 70k, 99.75MiB
171          webm       audio only DASH audio  106k , vorbis@128k, 117.72MiB
140          m4a        audio only DASH audio  138k , m4a_dash container, mp4a.40.2@128k (44100Hz), 163.54MiB
251          webm       audio only DASH audio  165k , opus @160k, 191.39MiB
160          mp4        256x144    DASH video   92k , avc1.4d400c, 30fps, video only, 62.13MiB
278          webm       256x144    144p  146k , webm container, vp9, 30fps, video only, 106.50MiB
242          webm       426x240    240p  187k , vp9, 30fps, video only, 119.24MiB
133          mp4        426x240    DASH video  202k , avc1.4d4015, 30fps, video only, 133.20MiB
243          webm       640x360    360p  350k , vp9, 30fps, video only, 273.25MiB
134          mp4        640x360    DASH video  454k , avc1.4d401e, 30fps, video only, 280.15MiB
244          webm       854x480    480p  661k , vp9, 30fps, video only, 514.94MiB
135          mp4        854x480    DASH video 1045k , avc1.4d401f, 30fps, video only, 565.84MiB
247          webm       1280x720   720p 1514k , vp9, 30fps, video only, 1.16GiB
136          mp4        1280x720   DASH video 2132k , avc1.4d401f, 30fps, video only, 1.02GiB
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)

Reason I am here is because I want to grab this playlist https://www.youtube.com/watch?v=WPni755-Krg&list=RDQM13Ux3JPdInk and only have m4a files, even though perhaps the webm files could be best quality... snap, having just typed all that up I have remembered that there is an android app that can do a pretty good job - removed, wasn't an ad.
leaving the comment here in case others come by looking for something similar...

edit: not an ad. it would be ideal if I could also get the same filetype (all m4a) out of "youtube-dl -f bestavailableaudio playlist.url" with zero effort rather than a mix of file formats.

@illtellyoulater
Copy link

illtellyoulater commented Nov 7, 2017

This does not add anything valuable to the discussion. It's already a complicated topic deciding what the best audio should be and you're only adding noise and honestly your comment looks more like an advertisement to a paid product than anything else. The app you talk about is misleadingly named "donationware" but what really is is a freemium that will only let you download music after you "donate" $2.

@nickcassol
Copy link

nickcassol commented Jan 12, 2018

@davidedelvento @SoreGums Opus at 160kbps outperforms AAC at 192kbps. Larger Smaller files don't mean that they are worse quality.

@mmshasan
Copy link

I use the following command/options and happy with the result. It downloads the Opus 160kbps and convert it to mp3(VBR)

youtube-dl -x --audio-format mp3 --audio-quality 0 <youtube-url>

@illtellyoulater
Copy link

illtellyoulater commented Jan 18, 2018

@mmshasan that will imply transcoding which means adding additional artifacts = lower quality.
Better download the AAC / MP4 then, which has a good quality and is compatible with every device.
Or if you really want the OPUS stream you could consider giving OGG as output parameter, since OGG is a container (most popular for Vorbis audio, but also for OPUS).
However I think not so many players are able to read an OGG containing an Opus stream.

@ytdl-org ytdl-org deleted a comment from alsteiner Jan 21, 2019
@karolzlot
Copy link

karolzlot commented Jan 28, 2019

@nickcassol mentioned that format may be more important than bitrate

Possibly this will be helpful in determining which video format is best:
https://superuser.com/questions/338725/compare-two-video-files-to-find-out-which-has-best-quality


VP9 outperforms avc1 according to https://motovlog.com/threads/making-1080p60-look-like-4k-by-getting-youtubes-bigger-bit-rate.17619/post-156037

more info: https://www.reddit.com/r/youtubegaming/comments/9mevc1/dear_ytg_devs_what_determines_a_vp9_versus_avc1/


if you want to download best opus+vp9 video:

-f bestvideo[vcodec=vp9]+bestaudio[acodec=opus]/best

if you want to download best opus audio:

-xf bestaudio[acodec=opus]


in future when av1 will become more available it will be even better choice than vp9

https://aomedia.org/av1-features/

if you want to download best opus+av1 video:

-f bestvideo[vcodec=av1]+bestaudio[acodec=opus]/best

@illtellyoulater
Copy link

illtellyoulater commented Feb 15, 2019

Hi @qqgg231,
with regards to video, as you said AV1 > VP9 > AVC1.
I just wanted to add that, depending on the client hw, YouTube is already serving AV1 video streams (it can be forced on in the youtube test page @ https://youtube.com/testtube).
Apparently youtube-dl is already supporting it, but I cannot test it atm.

@karolzlot
Copy link

@jjgh
pls correct typo ;-)

AV1 > VP9 > VP9

@kanliot
Copy link

kanliot commented Feb 16, 2019 via email

@karolzlot
Copy link

karolzlot commented Feb 17, 2019

@kanliot

-f bestaudio should work with youtube-dl.

This comment explains that -f bestaudio doesn't guarantee best quality
#9302 (comment)


Also on new youtube videos, from my personal appraisal, youtube.com is using 128KB/s AAC to encode all other audio formats, as that is the archive format after upload. so that would be number one-forty. Other formats might still sound better, but that format should have less audio artifacts and be closer to the source coded file.

One user did an experiment about it and result was Youtube keeps original file, not reencoded to AAC:

https://www.quora.com/Does-YouTube-keep-the-original-uploaded-video-files

Also please look at this comment: #9302 (comment)

@TheDecryptor
Copy link

Testing with one of the YT launch videos (https://www.youtube.com/watch?v=2nXYbGmF3_Q), the AV1 streams are detected and can download properly (Using the numeric code), but something like bestvideo[vcodec=av1] (or av01) doesn't work currently.

They're also using the MP4 container since it's technically not valid for WebM, and youtube-dl emits a warning about it.

@dstftw
Copy link
Collaborator

dstftw commented Mar 17, 2019

Cause there is no such exact vcodec av1. You must use partial string matching.

@TheDecryptor
Copy link

Yep, discovered that right after posting 😑

@basicmaster
Copy link
Contributor

I'm affected, too, but rather in terms of video than regarding audio. In case someone implements this sometime, here is an example of this issue affecting the video resolution: https://www.bbc.co.uk/programmes/p02k4zqd

While bestvideo returns 704x396 video, only best will lead to 960x540 video.

@zoklev
Copy link

zoklev commented Feb 18, 2021

@jjgh

another non-dumb youtube downloader app that similarly to youtube-dl actually analyzes all audio sources (both DASH and muxed) but goes on by picking the best audio based on the highest bitrate among all of them.

<removed>

I'm struggling really hard w/ this issue of quality; please email(mine's is public) its name to me. thank you

@knocte
Copy link

knocte commented Feb 19, 2021

Same here please, why the fuck censorship?

@zoklev
Copy link

zoklev commented Feb 19, 2021

@knocte

why the fuck censorship?

good Q; youtube-dl is non-profit(?) so it doesn't make sense to censor competition

@illtellyoulater
Copy link

I'm struggling really hard w/ this issue of quality; please email(mine's is public) its name to me. thank you

@zoklev I can't see your email in your profile...

@knocte
Copy link

knocte commented Mar 2, 2021

Mine is visible :)

@illtellyoulater
Copy link

Mine is visible :)

Did you get my mail?

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

No branches or pull requests