Last active
October 15, 2020 00:28
-
-
Save CharStiles/c90a09ca999257b1e7f56911a3f4ea3c to your computer and use it in GitHub Desktop.
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
# its dependencies are gifsicle and ffmpeg | |
gifify() { | |
if [[ -n "$1" ]]; then # if the input lengt≈h is non-zero | |
randomPlace=0 #lazy, i use it for filename regurdless if its needed or not | |
if [[ $2 != '--random' && $3 != '--random' ]]; then | |
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png | |
else | |
#s=$(ffprobe -i $1 -show_entries format=duration -v quiet -of csv="p=0") | |
s=$(ffprobe -i $1 -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1) | |
seconds=$(echo "$s - 2" | bc) | |
secondsInt=$(echo $seconds | cut -d "." -f 1 | cut -d "," -f 1) | |
echo "in random" | |
echo "this is secondsInt: $secondsInt" | |
#seconds=1 | |
randomPlace=$[RANDOM%$secondsInt] # this random only goes up to 32767 which is 9 hours | |
echo "this is randomplace: $randomPlace" | |
# if you want the gifs to be not 2 seconds long, change the number after the t flag | |
ffmpeg -i $1 -ss $randomPlace -t 2 -r 10 -vcodec png out-static-%05d.png | |
#starting at a random place take two seconds | |
fi | |
if [[ $2 != '--big' ]]; then | |
a=$(ls out-static* | wc -l) | |
for p in $(ls -r out-static*); | |
do | |
out=$(printf "out-static-%05d.png" $a) | |
let "a++" | |
cp $p $out | |
done | |
name=$(echo "$1" | cut -f 1 -d '.') | |
finalName="$name$randomPlace" | |
time convert -verbose +dither -layers OptimizePlus -resize 25% \> out-static*.png GIF:- | gifsicle --colors 256 --delay=5 --loop --optimize=3 --multifile - > $finalName.gif | |
# OptimizePlus | |
else | |
a=$(ls out-static* | wc -l) | |
for p in $(ls -r out-static*); | |
do | |
out=$(printf "out-static-%05d.png" $a) | |
let "a++" | |
cp $p $out | |
done | |
name=$(echo "$1" | cut -f 1 -d '.') | |
finalName="$name$randomPlace" | |
time convert -verbose +dither -layers OptimizePlus -resize 600x600\> out-static*.png GIF:- | gifsicle -- colors 128 --delay=5 --loop --optimize=3 --multifile - > $finalName.gif | |
# time convert -coalesce +dither -duplicate 1,-2-1 -loop 0 -treedepth 5 -colors 128\> out-static*.png $1.gif | |
fi | |
rm out-static*.png | |
else | |
echo "proper usage: gifify <input_movie.mov>. You DO need to include extension. do --big for big" | |
fi | |
} | |
# so for this one you must have nothing else in the directory except audio files | |
randomAudio(){ | |
for p in $(ls); | |
do | |
for i in {0..$1}; #make this many of each video | |
do | |
s=$(ffprobe -i $p -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1) | |
seconds=$(echo "$s - 2" | bc) | |
secondsInt=$(echo $seconds | cut -d "." -f 1 | cut -d "," -f 1) | |
echo "in randomAudio" | |
echo "this is secondsInt: $secondsInt HELLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO" | |
#seconds=1 | |
randomPlace=$[RANDOM%$secondsInt] # this random only goes up to 32767 which is 9 hours | |
echo "this is randomAudio: $randomPlace" | |
#seconds=1 | |
name=$(echo "$1" | cut -f 1 -d '.') | |
finalName="$name$randomPlace" | |
ffmpeg -i $p -ss $randomPlace -t 10 $finalName.WAV | |
done | |
done | |
} | |
bigGifify(){ #use $bigGifify 1 (how many per video in the directory you want) | |
for p in $(ls); | |
do | |
for i in {0..$1}; #make this many of each video | |
do | |
gifify $p --random | |
done | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment