Thursday, June 22, 2017

Download a part of YouTube video as mp3

I will be using ffmpeg and youtube-dl installed linux distro (Ubuntu 16.04 LTS)
ffmpeg -ss 00:00:00.0000 -i $(youtube-dl -f 22 --get-url <YOUTUBE_LINK>) -t 00:00:00.0000 -acodec libmp3lame -qscale:a 0 sample.mp3
Fill <YOUTUBE_LINK> with the link to YouTube video.

Find further explanation of above command here,
  • -ss : start of the stream 00:00:00.0000 stands for hour:minute:second.millisecond
  • -i   : provide the input, here we will be using an output from youtube-dl.
  • -t   : length of the stream

Further information about bitrate selection (-qscale:a 0) can be found here.
  • libmp3lame is the audio encoding used for this purpose.
  • sample.mp3 is the output file of above command.