If you want to download audio in opus
format - with best possible quality and without any conversion
In most of the cases best quality audio is oryginally provided by youtube in opus
format.
You can download it in highest possible quality using this command:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0
However opus
format might be inconvenient for many reasons.
For example some media players especially in cars and telephones might not support it.
Probably you just want to have audio in mp3
file.
Below there is a solution on how to (using one command) download audio and convert it to probably most popular mp3
format with lossing as little quality as possible.
If you want to download audio and convert it to mp3 or any other lossy format.
To download audio from a single movie:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-quality 0 --audio-format mp3 https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0
To perform this command you need ffmpeg
installed (audio and video converter which youtube-dl uses for convertion)
It downloads only audio (without video) and converts it to mp3
.
Option --audio-quality 0
is very important there!
Without this option you lose a lot of sound quality during mp3
compression.
--audio-quality 0
tells youtube-dl to save audio file in the best quality (when converting to mp3
).
Without this option mp3
audio-quality is set by default to 5
in 0-9 scale
where 0
is the best quality and 9
the worst quality. So by default quality is worse.
Youtube streams for nonpremium users with variable bitrate up to 160kbps
in opus
format. Opus
format is newer than mp3
and has better compression than mp3
preserving the same quality. So 160kbps
opus = ~256kbps
mp3.
When audio-quality is default (5
in 0-9 scale
) mp3 bitrate is limited to 160kbps
which means that some sound quality is lost during compression. When audio-quality is set to 0
mp3 goes up to 300kbps
preserving almost original quality.
Almost original quality because mp3
is a lossy format so something is lost when converting to it. By using --audio-quality 0
option we just make sure that we loose as little as possible during this conversion. So difference between original opus
audio file and audio file converted to mp3
is so small that it might be hard to spot by ear.
To download audio from all movies from a channel:
Command is the same, but you should put link to the channel instead of link to a single video:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-quality 0 --audio-format mp3 https://www.youtube.com/c/someChannelName1232143/videos
To download audio from a playlist:
You have to add --yes-playlist
option.
You can put a link to a playlist (link with playlist
word):
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format mp3 --audio-quality 0 --yes-playlist https://www.youtube.com/playlist?list=c29tZVZpZGVvVVJMUGFy
Or the link to one of the songs from playlist while playing playlist (link with list
word):
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format mp3 --audio-quality 0 --yes-playlist "https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0&list=c29tZVZpZGVvTGlzdFBhcnRzc29tZVZpZGVvTGlzdFBhcnRz&index=4"
If you want to download audio and convert it to flac or any other lossless format
In this case you don't have to specify --audio-quality
option as it is ignored by youtube-dl during conversion to lossless formats.
To download audio from a single movie:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format flac https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0
To download audio from all movies from a channel:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format flac https://www.youtube.com/c/someChannelName1232143/videos
To download audio from a playlist:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format flac --yes-playlist https://www.youtube.com/playlist?list=c29tZVZpZGVvVVJMUGFy
or
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format flac --yes-playlist "https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0&list=c29tZVZpZGVvTGlzdFBhcnRzc29tZVZpZGVvTGlzdFBhcnRz&index=4"
Command options explanation:
-f "bestaudio/best" <- Choose the best audio format.
As there is only audio format listed only the audio is downloaded.
-c <- (--continue) Force resume of partially downloaded files.
By default, youtube-dl will resume downloads if possible.
As docs state maybe it is default, but I put it to make sure it is set.
-i <- (--ignore-errors) Continue on download errors,
for example to skip unavailable videos in a playlist.
-w <- (--no-overtwrites) Do not overwrite files
(If something was already downloaded
and is present in the directory then continue with the next video)
-o "%(title)s.%(ext)s" <- (--output) Output filename template,
in this case it gives you file named movieTitle.mp3
where movieTitle is the title of the video on youtube.
-v <- (--verbose) Print various debugging information
--extract-audio <- (-x) Convert video files to audio-only files
(requires ffmpeg or avconv and ffprobe or avprobe)
--audio-quality 0 <- Specify ffmpeg/avconv audio quality,
insert a value between 0 (better) and 9 (worse) for VBR or a specific
bitrate like 128K (default 5).
Youtube streams for nonpremium users with variable bitrate up to 160kbps in opus format.
Opus format is newer than mp3 and has better compression than mp3
preserving the same quality. So 160kbps opus = ~ 256kbps mp3.
When audio-quality is default (5 in 0-9 scale) mp3 bitrate
is limited to 160kbps which means that some sound quality is lost during compression.
When audio-quality is set to 0 mp3 goes up to 300kbps preserving original quality.
--audio-format mp3 <- Specify audio format: "best", "aac", "flac", "mp3", "m4a",
"opus", "vorbis", or "wav"; "best" by default; No effect without -x (--extract-audio).
In this case we choose mp3.
Alternatively you could choose for example flac which is loseless codec.
All links that I provided there are fake. I just put some random words encoded by base64 in them. So you have to replace them by your own links to make it work.
Hint:
Youtube-dl gives you opportunity to use your own youtube account to download stuff.
If your account is a premium account you can get
higher 320kbps opus bitrate which is equivalent of ~512kbps mp3.
Using your own account might be possible by setting --username and --pasword
(See Authentication Options in --help)
Note:
All of the above should be relevant for version 2021.12.17
of youtube-dl.
Newer versions might change something, so be aware of that.
171
vorbis@128k is the best audio available for this video. It can be different for others. Rencoding will loose more data, no matter in what or at what birate! Why not make your very own test, compare outputs, in an headphone, in your car, etc. See what suits your needs – Adcock251
"opus@160k" is the best audio quality in this situation. The Opus codec is a decade newer than Vorbis and is more efficient at representing audible sounds. – Banda