Created
June 4, 2015 12:48
-
-
Save cerisier/da5beb5eeae11b42754b to your computer and use it in GitHub Desktop.
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 | |
cd ~/Desktop | |
spinner() | |
{ | |
local pid=$1 | |
local delay=0.75 | |
local spinstr='|/-\' | |
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do | |
local temp=${spinstr#?} | |
printf " [%c] " "$spinstr" | |
local spinstr=$temp${spinstr%"$temp"} | |
sleep $delay | |
printf "\b\b\b\b\b\b" | |
done | |
printf " \b\b\b\b" | |
} | |
die() { echo "$@" 1>&2 ; exit 1; } | |
echo "Drag the audio file on the window, followed by [ENTER]:" | |
read audio | |
[ -e "$audio" ] || die "Audio file not found at specified location" | |
echo "Drag the sleeve picture on the window, followed by [ENTER]:" | |
read sleeve | |
[ -e "$sleeve" ] || die "Sleeve picture not found at specified location" | |
echo "Type the time at which the audio should start. i.e: 00:01:00 followed by [ENTER]:" | |
read from | |
echo "Type the duration the video should be (in seconds), followed by [ENTER]:" | |
read duration | |
at_exit() { | |
rm /tmp/"$output".* | |
} | |
trap at_exit EXIT | |
output=$(echo $(basename ${audio%.*}) | tr ' ' _) | |
minutes=$(echo $from | cut -d : -f 2 | sed 's/^0*[1-9]+//') | |
seconds=$(echo $from | cut -d : -f 3 | sed 's/^0*[1-9]+//') | |
skip=$(($minutes * 60 + $seconds)) | |
( | |
ffmpeg -loglevel fatal -y -loop 1 \ | |
-i "$sleeve" \ | |
-s 1200x1200 \ | |
-t $duration \ | |
-c:v libx264 -pix_fmt yuv420p \ | |
/tmp/"$output".mov | |
ffmpeg -loglevel fatal -y -ss $skip -i "$audio" -t $duration /tmp/"$output".mp3 | |
ffmpeg -loglevel fatal -y \ | |
-i /tmp/"$output".mov \ | |
-i /tmp/"$output".mp3 \ | |
-map 0:v -map 1:a -codec copy \ | |
-shortest "$output".mov | |
) & | |
echo -n "Generating... This may take a while" | |
spinner $! | |
echo | |
echo "Video was successfully generated" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment