Last active
June 25, 2020 20:33
-
-
Save hellocatfood/db4ba82541c1000f350ff40e2fbaad23 to your computer and use it in GitHub Desktop.
A script to perform a random cut on a 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 | |
#A script to perform a random cut on a video | |
#By Antonio Roberts | www.hellocatfood.com | |
#Usage: ./movie_cut.sh /path/to/file.mp4 | |
#e.g. ./movie_cut.sh /home/Desktop/videofile.mp4 | |
# change 30 to however many videos you want output | |
filenumber=$(printf "%05d") | |
while [ $filenumber -le 30 ] | |
do | |
# calculate the length of the video | |
length=`expr $(ffprobe -loglevel error -show_streams $1 | grep duration | tail -1 | cut -f 2 -d = | head -1 | cut -d "." -f 1) \* 100` | |
# start position | |
startPos=$(echo "scale=2;$(shuf -i 1-$length -n 1) / 100" | bc | sed -e s/^/0/) | |
# define random duration (up to 0.999 seconds). Change 1. to bigger number for longer videos | |
duration=$(echo "1.$RANDOM") | |
#get path of file | |
path=$( readlink -f "$( dirname "$1" )" ) | |
#get filename minus extension | |
file=$(basename "$1") | |
filename="${file%.*}" | |
#cut the video | |
ffmpeg -i $1 -ss $startPos -t $duration -q:v 0 -y "$path"/"$filename"_"$filenumber"_cut.avi | |
filenumber=`expr $filenumber + 1` | |
filenumber=$(printf "%05d" $filenumber) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment