Last active
August 9, 2020 17:50
-
-
Save benjiao/4fb3b631d3fe6238af77c324c64d9a11 to your computer and use it in GitHub Desktop.
A short bash script that slices video into 20 second clips
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 | |
# Usage: ./slice-for-stories.sh Video-to-Slice.mp4 | |
fname=$1 | |
# Get length | |
length=$(ffmpeg -i $fname 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }') | |
let fcount=length/20 | |
echo "${fname} is ${length}s long. About to create ${fcount} files..." | |
# Loop through each file | |
counter=0 | |
while [ $counter -le $fcount ] | |
do | |
newfname="$fname-$counter.mp4" | |
let newstart=counter*20 | |
echo "Creating ${newfname} starting at ${newstart}" | |
ffmpeg -i $fname -ss $newstart -t 20 $newfname | |
## Crop the video as well | |
# ffmpeg -i $fname -filter:v "crop=in_h*9/16:in_h" -ss $newstart -t 20 $newfname | |
((counter++)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment