I want to download YouTube videos as mp3 files in its best quality. The below code helps to download youtube videos as m4a
but not us mp3
youtube-dl -f bestaudio --audio-quality 0 --audio-format mp3 https://www.youtube.com/playlist?list=PLYRruMbyFRcBVdVN8v4FNkIKkXvL-bZn_
can you tell me how to use bestaudio
parameter to download YouTube video as mp3
From
man youtube-dl
:So your command could be:
The
--audio-quality 0
uses the highest encoding quality but can increase your file size unnecessarily. The default is 5 and might be a better choice depending on the source quality.So, if quality and file size matter to you, you should avoid re-encoding and stay with Youtube's native music formats:
resulting in an
m4a
file orprobably resulting in an
ogg
file.You can list the available format with
If you only want the mp3 file:
If you do not want to remove the original file:
I recommend use Pafy (Python), very easy to get audio link, and you can download directly if you want:
It is also worth noting other pieces out of
man youtube-dl
(a online copy can be found here):(For those thinking TL;DR, just read the 4th paragraph, and you can use
youtube-dl -x URL
as it should download the best quality anyway :)Also
youtube-dl -f bestaudio URL
works in my experience! However with both these options most of the time you will need convert to MP3 usingffmpeg
or similar - since you are already editing the file you can also tag it (use the old ID3 version for most device compatibility!).Youtube (probably as it is supposed to be a video playing site) also apparently compresses the audio (see here) down to 120~KBs, which is quite low but for the most part seems OK.
To compare download videos, you can query the downloaded video/audio tracks (you may need to use
avprobe
instead offfprobe
) to see which is best: