Peter Hinchley

Learning in Public

✪ Extract Audio from YouTube Video

It is easy to download the audio of a YouTube video using youtube-dl. It's also simple to extract only a section of the audio using ffmpeg. For example, on a Mac, the following command will download the audio from E^st's cover of Bitter Sweet Symphony, starting at 45 seconds into the clip, and ending at 5 minutes and 13 seconds:

youtube-dl -f 140 -q -o - | ffmpeg -i - -ss 00:00:45 -to 00:05:13 'E^st - Bitter Sweet Symphony.m4a'

The -f switch specifies the download format (where 140 requests 128K ACC in an M4A container), -q sets "quiet mode", and -o - is used to send the output of youtube-dl to STDOUT. This output is piped into ffmpeg, where -i - reads from STDIN, -ss sets the start-time offset, and -to sets the end-time offset.