Skip to content

Instantly share code, notes, and snippets.

@faroncoder
Last active December 31, 2015 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faroncoder/7972194 to your computer and use it in GitHub Desktop.
Save faroncoder/7972194 to your computer and use it in GitHub Desktop.
Bash to fire off ffmpeg encoder to initiate encoding. Built for icrontab and inotify purpose. Will encode any media file the same directory where this script resides in.
#!/bin/bash
if [ ! -d bye ]
then
mkdir bye
fi
if [ ! -d lib ]
then
mkdir lib
fi
file=$(find ./ -type f ! -name "ffmpeg*" | sort | head -1)
ffile="out.mp4"
ffcomp=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
ffbye="bye/"
fflib="lib/"
if [ "$(ls -A)" ]; then
## ACTION IF MEDIA FILE IS PRESENTED IN DIRECTORY
#2 PASSES ENCOIDNG ## TRIM TO 640X360 | PRESENT MEDIUM | X264 | AAC ###
ffmpeg -y -i "$file" -c:v libx264 -s 640x360 -preset medium -b:v 555k -pass 1 -an -f mp4 "$ffile" < /dev/null
ffmpeg -i "$ffile" -c:v libx264 -preset medium -b:v 555k -pass 2 -c:a libfdk_aac -b:a 128k "lib/$ffcomp" < /dev/null
mv "$file" "$ffbye"
rm "$ffile"
else
echo "no files to covert"
exit 0
fi
./fireffmpeg.sh
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment