Linux – Quality of wav files using youtube-dl

linuxwavyoutube-dl

I'm trying to download music from YouTube site using youtube-dl with the best quality possible. So I've tried to download as a WAV file with this command:

youtube-dl -ci -f 'bestvideo[ext=mp4]+bestaudio' -x --audio-format wav https://www.youtube.com/watch?v=tDOffPd81YI  

which produced a big WAV file (with this video, 42.3 Mo 48kHz stereo 16bit 1536kbit/s)

But when I compared with an M4A file, downloaded with:

 youtube-dl -ci -f 'bestvideo[ext=mp4]+bestaudio' -x --audio-format m4a https://www.youtube.com/watch?v=tDOffPd81YI

The M4A file is smaller and lower quality (with this video, 12.3 Mo 48kHz stereo 441kbit/s).

Why is the WAV file better quality? And what causes the difference of file size? It is more strange that I have asked the same quality for both (-f 'bestvideo[ext=mp4]+bestaudio')

I tried downloading with bestaudio quality and converting to a M4A file:

 youtube-dl -ci -f "bestaudio" -x --audio-format m4a https://www.youtube.com/watch?v=tDOffPd81YI  

On this file, I found that the first file had a bigger size and a bigger bitrate than the second, but it probably depends on the video you choose.

Does the flag bestaudio[ext=m4a] download the bestaudio stream in M4A format, or does it take the best audio and convert it to M4A?

I'm running on Manjaro Linux.

Best Answer

As far as I know YouTube internally stores videos in MP4 format with AAC audio (.m4a suffix). If you request a .wav file youtube-dl will simply call ffmpeg in order to convert the audio track from m4a to wav. Since wav is a lossless format both files have exactly the same quality, but wav is much bigger than m4a.

I suggest using some command like the following one:

youtube-dl -ci -f "bestaudio[ext=m4a]" https://www.youtube.com/watch?v=tDOffPd81YI

I also suggest checking the list of available formats with the -F option (uppercase F):

youtube-dl -F https://www.youtube.com/watch?v=tDOffPd81YI