Created
November 21, 2021 20:14
-
-
Save Ryu1845/2af752c7c782b600a9d1887c45c93689 to your computer and use it in GitHub Desktop.
Download only part of a youtube video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
clip() { | |
YOUTUBE_URL="${1}" | |
START_TIME="${2}" | |
END_TIME="${3}" | |
END_FILENAME="${4}" | |
AUDIO_URL="$(yt-dlp "${YOUTUBE_URL}" -g -f bestaudio)" | |
VIDEO_URL="$(yt-dlp "${YOUTUBE_URL}" -g -f bestvideo)" | |
ffmpeg \ | |
-ss "${START_TIME}" -i "${VIDEO_URL}" -to "${END_TIME}"\ | |
-ss "${START_TIME}" -i "${AUDIO_URL}" -to "${END_TIME}"\ | |
-map 0:0 -map 1:0 -c copy -shortest -y "${END_FILENAME}" | |
} | |
if [ "$#" -ne 4 ]; then | |
echo "Not enough arguments | |
Usage: | |
./clip.sh url 'starting time' 'end time' 'output filename' | |
time in hh:mm:ss" | |
exit 1 | |
fi | |
clip ${@} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment