How to get best quality audio using youtube-dl?

The --audio-quality does not affect the audio quality of the source. It's a post processing option and will re-encode the audio.

Since any kind of (lossy) re-encoding will actually deteriorate the quality of the stream—or at least make it unnecessarily larger in size—I would recommend not to post-process the audio at all.

To get the best audio quality possible you simply need to select a source format of high quality. Actually, youtube-dl will do that by default, but you can explicitly set it with --audio-format best. YouTube (and other providers) store different audio codecs with different bitrates, and youtube-dl will choose the best one from those.

If you have ffmpeg installed on your system, then youtube-dl can extract the audio automatically:

youtube-dl --audio-format best -x <url>

Otherwise, you will get a video file from which you have to extract the audio component.


Stay with Youtube's native music formats to avoid re-encoding:

youtube-dl -f bestaudio[ext=m4a] --embed-thumbnail --add-metadata <Video-URL>

resulting in an m4a file or

youtube-dl -f bestaudio --extract-audio --embed-thumbnail --add-metadata <Video-URL>

The latter can also resul in an ogg file if the highest audio quality format is OPUS rather than AAC.

You can list the available format with

youtube-dl -F <Video-URL>

Use the command:

youtube-dl -f bestaudio "url"