Skip to content

Instantly share code, notes, and snippets.

@bhargavkakadiya
Forked from banteg/yt-seek.sh
Created November 28, 2023 05:05
Show Gist options
  • Save bhargavkakadiya/d512557a0e2dae528706a76b65aa5591 to your computer and use it in GitHub Desktop.
Save bhargavkakadiya/d512557a0e2dae528706a76b65aa5591 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