Skip to content

Instantly share code, notes, and snippets.

@niko-dunixi
Last active November 18, 2020 23:12
Show Gist options
  • Save niko-dunixi/21e745d61b01888d079a32419f17cd66 to your computer and use it in GitHub Desktop.
Save niko-dunixi/21e745d61b01888d079a32419f17cd66 to your computer and use it in GitHub Desktop.
Download portion of YouTube video

We can't do this with youtube-dl alone, we can pair this with ffmpeg to acomplish this task though. We use youtube-dl and ffmpeg to resolve the URL of the video, and then tell ffmpeg to download the range itself.

So to take a sound byte from this podcast and use it to create my ringtone:

$ audio_url="$(youtube-dl --audio-format mp3 --get-url https://youtu.be/s8tJ-R28HX8 | grep mime=audio | head -n 1)"
$ ffmpeg -ss 02:00:02.10 -i "${audio_url}" -t 00:00:12 -c:a mp3 paul-ringtone.mp3

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment