Created
July 29, 2014 11:31
-
-
Save tobalsan/f143d8c93290121a8e69 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 | |
item=$1 | |
# A directory or a file must be provided | |
if [ -z $item ]; then | |
echo "You must specify a file or a folder" | |
exit 0 | |
elif [ ! -d $item ] && [ ! -f $item ]; then | |
echo "The entry you specified is not a folder or a file" | |
exit 0 | |
fi | |
# Processing function definition | |
function process { | |
if [ ! -f $1 ]; then | |
echo "Invalid specified file" | |
exit 0 | |
fi | |
file=$1 | |
# file=${file##*/} <- strip path and keep only filename | |
donefile=${file:0:${#file}-4}".flv" | |
# Wait while any other ffmpeg processes are running | |
while [ -n "$(ps -ef | egrep "ffmpeg" | grep -v grep)" ]; | |
do | |
echo -e "\n[$(date +%b\ %d\ %Y:\ %H:%M:%S)]\nFound another instance of ffmpeg running, pausing 5 minutes..." | |
sleep 300 | |
done | |
# ffmpeg cmd comvert to flv | |
echo "Processing conversion to FLV of $file" | |
/usr/local/bin/ffmpeg -i "$file" -ar 44100 -acodec libmp3lame -ab 160K -vcodec flv -qmin 2 -qmax 4 "$donefile" | |
if [ -f "$donefile" ] && [ -s "$donefile" ]; then | |
rm "$file" | |
fi | |
} | |
# Ok, process item if it's a file | |
if [ -f $item ]; then | |
process $item | |
# Or if it's a directory, loop over each file | |
elif [ -d $item ]; then | |
cd $item | |
for file in ./* ; | |
do | |
if [[ $file = *.mp4 ]] ; then | |
process $file | |
fi | |
done | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment