Last active
October 30, 2020 18:22
-
-
Save antoniozh/76b120024629b47835ffbe83894c110e to your computer and use it in GitHub Desktop.
Crops a portion of a youtube video and merges the video and audio parts without downloading the whole video.
This file contains hidden or 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 | |
echo "Usage: ytcrop.sh VIDEO_LINK START_TIME DURATION [filename]" | |
LINKS=$(youtube-dl -g $1) | |
# Parse first link which is video | |
VIDEO_LINK=$(echo $LINKS | tr " " "\n" | head -n1 ) | |
# Parse second link which is audio | |
AUDIO_LINK=$(echo $LINKS | tr " " "\n" | tail -n1 ) | |
# echo Video link: $VIDEO_LINK | |
# echo Audio link: $AUDIO_LINK | |
if [ -n $4 ]; then | |
OUT_PATH="out.mp4" | |
else | |
OUT_PATH=$4 | |
fi | |
ffmpeg -loglevel warning -hide_banner -ss $2 -i "${VIDEO_LINK}" -ss $2 -i "${AUDIO_LINK}" -map 0:v -map 1:a -t $3 -c copy $OUT_PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment