16
3
I am using youtube-dl
on Linux to download videos from YouTube and extract the audio. This is my way of building a small music collection.
Anyways, I know that there is an option --audio-quality=
with 0 being best and 9 being worst. Is this all I need to do to get the best quality audio?
Also, does anyone know if downloading from soundcloud could get higher quality?
If
ffmpeg
doesn't reencode then why am I selecting the audio format? If I enter that line but withaac
instead, I don't get the same file but with a different extension. I get a different file with slightly different size and bitrate. – Blrp – 2016-03-15T23:02:01.477@Blrp YouTube stores the audio and video bitstreams in different formats (different codecs, different bitrates).
youtube-dl
allows you to choose that format.ffmpeg
really only multiplexes video and audio streams together into a single file. – slhck – 2016-03-16T10:14:21.1201Ok, but that doesn't really answer my question. I'm asking specifically about the video to audio conversion. If there's a command that takes the audio from an MP4 and saves it as an audio file without reencoding, there should only be one possible outcome, right? And yet, the ffmpeg command in your post yields a different result depending on which extension I select for the audio. So is there always one correct audio extension, depending on the video extension, for which I get the audio without reencoding? Or how else do I do it? – Blrp – 2016-03-16T10:46:20.830
1
I see now. First, I clarified my answer—it was a little more complex than needed. Also, maybe this answer is interesting to read. Even if the audio codec bitstream is not touched (i.e., copied), the extension determines how it is wrapped in a format. There is no 1:1 mapping here. Some formats require more space than others. You can use
– slhck – 2016-03-16T11:07:17.057ffmpeg -i in.mp4 -c:a copy -vn out.m4a
and end up with a different file thanffmpeg -i in.mp4 -c:a copy -vn out.mkv
, although both contain the exact same audio data (and therefore have the same audio quality).Thanks! Another question though - are you certain that
– Blrp – 2016-03-16T12:04:38.827youtube-dl
doesn't re-encode? All videos I've tried in 240p, 480p and 1080p get the same quality of 253kbps, which seems kinda weird. Also, other services give 125kbps with what they claim is the best available quality and no re-encoding. For more details see here.1I'm certain it doesn't re-encode. It doesn't have any ability to do so. The reason you're getting the same bitrates is that YouTube has very limited variation in the audio bitrates / codecs they use, in contrast to the video representations. Maybe YouTube is a bit erratic when it assigns video and audio bitrates, and you may see a higher audio bitrate for a lower video quality—in that case, I think
youtube-dl
still selects the highest quality video format. Do you have a specific video example? – slhck – 2016-03-16T15:07:17.970I'll take your word for it, but here are some videos of varying bitrate if you wanna mess around with it.
– Blrp – 2016-03-16T15:36:29.9071Seems fine to me. For example in the second one, when you use
-x
as an option, it'll download the audio-only variant with the highest bitrate (256k, format code 141, check out withyoutube-dl -F <url>
). All other audio components of the other audiovisual representations have lower bitrates. – slhck – 2016-03-16T17:57:46.150Hey, it's me again. I found a video that doesn't yield the best quality with your solution.
– Blrp – 2016-04-20T17:40:42.790youtube-dl --audio-format best -x https://www.youtube.com/watch?v=J9bjJEjK2dQ
yields 125kbps m4a, andyoutube-dl --format best -x https://www.youtube.com/watch?v=J9bjJEjK2dQ
yields 192kbps m4a. I guess it's because the format with highest audio quality isn't audio-only, and--audio-format
ignores formats with video? But if I replace--audio-format
with--format
, maybe the format counted as 'best' has really high video quality but lower audio (1/2)(2/2) quality than some other format, so
--format best
also doesn't seem like a guarantee to have the best format. In fact, maybe it's possible that neither gives the best quality. What if one format has high video quality but medium audio quality, and one has high audio quality but low video quality, so the first is counted as best overall, and the second is not audio-only. – Blrp – 2016-04-20T17:44:23.937I went to the project's support site and apparently there is no option for best sound quality: https://github.com/rg3/youtube-dl/issues/9302
– Blrp – 2016-04-26T04:27:05.310@Blrp Hm, interesting. I didn't assume there would be a case where the best video/audio does not correspond to the best audio option. – slhck – 2016-04-26T17:45:34.977