How to download 1080p + best audio using youtube-dl?
Asked Answered
S

1

20

I'm trying to download 1920x1080 video with 192kb/s audio but I'm unable to extract both. For example:

        format code  extension  resolution note
    249          webm       audio only DASH audio   51k , opus @ 50k, 600.56KiB
    250          webm       audio only DASH audio   67k , opus @ 70k, 788.31KiB
    251          webm       audio only DASH audio  132k , opus @160k, 1.53MiB
    140          m4a        audio only DASH audio  134k , m4a_dash container, mp4a.40.2@128k, 1.52MiB
    171          webm       audio only DASH audio  135k , vorbis@128k, 1.53MiB
    160          mp4        256x144    144p  110k , avc1.42c00c, 12fps, video only, 1.30MiB
    278          webm       256x144    144p  134k , webm container, vp9, 12fps, video only, 1.18MiB
    133          mp4        426x240    240p  248k , avc1.4d4015, 24fps, video only, 2.91MiB
    242          webm       426x240    240p  254k , vp9, 24fps, video only, 2.30MiB
    243          webm       640x360    360p  475k , vp9, 24fps, video only, 4.17MiB
    134          mp4        640x360    360p  617k , avc1.4d401e, 24fps, video only, 5.00MiB
    244          webm       854x480    480p  861k , vp9, 24fps, video only, 7.31MiB
    135          mp4        854x480    480p 1110k , avc1.4d401e, 24fps, video only, 9.33MiB
    247          webm       1280x720   720p 1691k , vp9, 24fps, video only, 13.90MiB
    136          mp4        1280x720   720p 2220k , avc1.4d401f, 24fps, video only, 17.41MiB
    248          webm       1920x1080  1080p 3044k , vp9, 24fps, video only, 24.43MiB
    137          mp4        1920x1080  1080p 4160k , avc1.640028, 24fps, video only, 31.42MiB
    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)

I'm trying to merge the 1920x1080 video from 137 and 192kb/s audio from 22 (as it's the best available).

-f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' --merge-output-format mp4

But the audio bitrate of output file was 125kb/s. How can I download the required specifications?

EDIT 1: Link for the example video: https://www.youtube.com/watch?v=i-c-K3pNtj4

NOTE: I don't know too much about audio codecs but I want to select the best one so if possible, please provide the facts that can be used to identify the best audio if it outfactors the bitrate.

Sardis answered 1/3, 2018 at 11:34 Comment(3)
To be able to reproduce your problem, can you mention the video URL? From the output, I'm guessing it's a video on YouTube, but there's not much more information. And what makes you think that the audio in 22 is the best available? Just because the bitrate is higher, taht doesn't mean it's best. opus@160k should easily beat m4a@192, although I'd doubt any human can hear the differences, even audiophiles on the best equipment there is.Derina
@phihag I've edited the question. I don't have too much knowledge about audio but I can clearly differ between 128kb/s and 192kb/s audio.Sardis
@phihag I am doing youtube-dl -f 22 --extract-audio and it does not result into the audio it is supposed to(mp4a.40.2@192k), why is that and how can I get it to work as expected? Edit: Answer below says that it is hard-coded.Heavyset
D
16

First of all, a word about audio quality: As described on our sister site, mp3 becomes indistinguishable from lossless CD quality (transparent) at about 192kb/s with a constant bitrate. However, any modern encoder is using a variable bitrate (VBR), putting more quality in some sections than others. With VBR, the cutoff is likely a bit lower. With professional ears and equipment, it may be a little bit higher.

AAC and Vorbis are one generation farther than MP3. This seems to be the most comprehensive quality test - at least the one I could find. AAC and Vorbis have been claimed to be transparent at 128kb/s, although I'd guess 160kb/s is a more realistic threshold. Opus is yet another significant improvement, being reasonably good for music at 64kb/s and probably transparent at 128kb/s.

When youtube-dl lists the format quality for YouTube, the quality it lists is hardcoded. Other websites supported sometimes relay quality information in advance, but for YouTube we'd have to download at least the headers of each file.

I got bad news for your claim to be able to hear the difference between 192kb/s and 128kb/s on this video: All the audio formats offered for this video (namely, 251, 140, 171 and 22) are encoded with 128KB/s VBR. You can check so by downloading them (for 22, you need to split off the audio) and comparing file sizes: They're all 1.6MB = 12.8 Mb (conveniently, the video is 100 seconds long).

In particular, the codecs are opus(251), Vorbis(171), AAC(140 and 22). Of these, Opus definitely offers the highest quality. So why does youtube-dl pick Vorbis with bestaudio? The way I originally designed the youtube-dl format selection, it would have picked the Opus indeed. But there was significant user feedback that some formats may be of worse quality, but supported more broadly.

Even today, lots of applications are unable to handle Opus, or even Vorbis or AAC and their container. A high-quality music player such as VLC will support everything, but out of the box, many laptops will be limited; smartphones more so, and smartwatches or smart headphones even more so. This is why most podcasts will still serve mp3 files - it is a much worse user experience to be unable to play a file at all, than a slight degradation in audio quality and/or file size. In addition, some of these formats are also free, while others are not, bringing further problems on systems configured to use only free software.

If you value audio quality above all, you should pick format 251 here. Store your preferences in a configuration file to make them permanent.

Note that all of this discussion presumes that the original audio source is high-fidelity, if possible lossless. Since the uploader of that video is called MikeTheAnimeRunnerX2, I would not presume expert audio recording skills - although there is credit of the original singer, so he may have gotten a high-quality file in private. If the audio that was uploaded to YouTube was in a lossy format (especially one at the edge of transparency or lower), all the further reencoding by YouTube can do is minimize further artifacts.

Note that to non-experts, worse compression can sometimes sound better, especially when the original source is not that good, noisy, or has been degraded by lossy reencodings. This is because worse compression will remove some inaccuracies and may make the sound more "smooth".

Fortunately, youtube-dl gives you the option to test multiple formats. Just download all candidates (e.g. with youtube-dl -f 251 i-c-K3pNtj4, or -f bestvideo+251 to get a video file) and pick the one you like most.

Derina answered 2/3, 2018 at 10:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.