Skip to content

Instantly share code, notes, and snippets.

@banteg
Created April 29, 2019 14:35
Show Gist options
  • Save banteg/5d613ed8eacb174ad200884331568c34 to your computer and use it in GitHub Desktop.
Save banteg/5d613ed8eacb174ad200884331568c34 to your computer and use it in GitHub Desktop.
download fragment of a youtube video without downloading the whole thing
#!/bin/bash
NAME=yt-seek
if [ "$#" -ne 3 ]; then
echo "Usage: $NAME <url> <start> <duration>"
exit 1
fi
URL=$1
START=$2
DURATION=$3
AV=($(youtube-dl -g $URL))
if [ "${#AV[@]}" -ne 2 ]; then
echo "Could not extract streams"
exit 1
fi
AUDIO=${AV[0]}
VIDEO=${AV[1]}
ffmpeg -ss $START -i $VIDEO \
-ss $START -i $AUDIO \
-t $DURATION -c copy out.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment