Extract Audio From a YouTube Video


The following steps can be used to extract the audio from a YouTube video and convert it to a stereo MP3.

Notes:

Method 1:

  1. Using youtube-dl, download the audio track in wav (uncompressed) format:

    $ youtube-dl --extract-audio --audio-format wav -o [OUTPUT].wav '[URL]'

    Here [OUTPUT].wav is the name of the file that youtube-dl should save the audio to and [URL] is the URL of the video whose audio youtube-dl should extract.

  2. After youtube-dl finishes downloading the audio track, convert the wav file to an MP3 using ffmpeg:

    $ ffmpeg -i [OUTPUT].wav -acodec mp3 -ab 256k -ac 2 [OUTPUT].mp3

    Here the option -acodec mp3 tells ffmpeg to convert the wav audio to an mp3 (other audio formats are also available), the option -ab 256k tells ffmpeg that the mp3 should be a 256k (high quality , lower numbers can be used for lower quality) mp3, and the option -ac 2 tells ffmpeg that the mp3 should be in stereo.

Method 2:

Tell youtube-dl to download the audio track and covert it to an mp3:

$ youtube-dl --extract-audio --audio-format mp3 --audio-quality 0 -o [OUTPUT].mp3 '[URL]'

Here [OUTPUT].mp3 is the name of the file that youtube-dl should save the audio to and [URL] is the URL of the video whose audio youtube-dl should extract.


Valid XHTML and CSS  //  Licensed under a Creative Commons Attribution 2.5 License