How to get best quality audio using youtube-dl?
Emily Wong
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?
3 Answers
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.
12Stay 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> 5 Use the command:
youtube-dl -f bestaudio "url"