Open Bl-rp opened 8 years ago
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.
You completely misinterpret the notions.
I don't, actually.
@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.
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?
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?
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.
Ok I see. And what about sound? What is the criteria for choosing the best audio? Bitrate? Is format taken into account?
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.
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?
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.
Quite often .webm is "best" both among audio formats and video+audio.
Statistics is not reliable. A new feature should always work correctly.
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
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
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?
@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.
@yan12125 I mean, the same way youtube-dl compares the streams when choosing best, could be used to compare those results, couldn't it?
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?
@yan12125 but then how does youtube-dl determine bestaudio
?
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.
@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?
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>
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.
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?
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.
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.
@davidedelvento @SoreGums Opus at 160kbps outperforms AAC at 192kbps. ~Larger~ Smaller files don't mean that they are worse quality.
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>
@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.
@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
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
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.
@jjgh pls correct typo ;-)
AV1 > VP9 > VP9
-f bestaudio should work with youtube-dl.
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.
@kanliot
-f bestaudio should work with youtube-dl.
This comment explains that -f bestaudio
doesn't guarantee best quality
https://github.com/rg3/youtube-dl/issues/9302#issuecomment-329712042
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: https://github.com/rg3/youtube-dl/issues/9302#issuecomment-357253894
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.
Cause there is no such exact vcodec
av1
. You must use partial string matching.
Yep, discovered that right after posting 😑
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.
@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.
\
I'm struggling really hard w/ this issue of quality; please email(mine's is public) its name to me. thank you
Same here please, why the fuck censorship?
@knocte
why the fuck censorship?
good Q; youtube-dl is non-profit(?) so it doesn't make sense to censor competition
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...
Mine is visible :)
Mine is visible :)
Did you get my mail?
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'.