iwatch and inotify-triggered conversions…

$SO wanted to take $music_site videos and strip/reencode the audio track to mp3.  they already have an SSHFS mount to my file server, so i set up a directory structure where they can deposit mp4 and flv files, and the files will automatically be converted and saved to an output directory.  after conversion, the source files are moved to a processed directory.



iwatch -d -f ./encode.xml


<?xml version="1.0" ?>
<!DOCTYPE config SYSTEM "/etc/iwatch/iwatch.dtd" >
  <guard email="root@localhost" name="IWatch"/>
    <title>test script</title>
    <contactpoint email="root@localhost" name="root"/>
    <path type="single" alert="off" exec="find %f \( -iname '*.mp4' -o -iname '*.flv' \) -execdir /data/convert/encode.sh {} \;" events="close_write">/data/convert/input</path>



echo "[$(date +%H:%M:%S)] encode attempt of $1 starting..." >> /data/convert/encode.log

f=$(basename "${1%.*}")
ffmpeg -i "$1" -acodec libmp3lame -aq 0 "/data/convert/output/$f.mp3"
mv "$1" /data/convert/processed/

echo "[$(date +%H:%M:%S)] encode attempt of $1 complete" >> /data/convert/encode.log