Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # This is a job to be called by cron, that will encode flv and mp4 videos in a set direcctory to preset mp4 and 3gp profiles, then move the source files once completed.
- # since it'll be getting called from cron, if there are a lot of videos to do, it's conceivable that an older cron job might still be running when we attempt to spawn a new one.
- # That's not a good thing, so first off we'll make sure there are no other copies of it running.
- date >> /tmp/date.log
- if [ -f /tmp/autoff.pid ]; then
- # seems like it's already running, but let's double check
- if [ "$(ps -p `cat /tmp/autoff.pid` | wc -l)" -gt 1 ]; then
- # yep it's running.
- echo "$0: seems like there's already an autoff process running... PID: `cat /tmp/autoff.pid`"
- exit 0
- fi
- else
- # nah it's an old autoff.pid from a run that didn't complete
- rm /tmp/autoff.pid
- fi
- # store the current PID in /tmp/autoff.pid
- echo $$ >/tmp/autoff.pid
- # setup the source and destination folders, and where to put the old vids...
- sourcedir=/home/zavids/rawvids/source
- olddir=/home/zavids/rawvids/zcomplete
- donedir=/home/zavids/www/vfiles
- # get the list of videos in the source folder
- vidstodo=`ls $sourcedir/*.mp4 $sourcedir/*.flv -1`
- for vid in `echo $vidstodo`; do
- # get the vid's basename
- basename=${vid%.*}
- basename=${basename##*/}
- echo `date +"%d-%m-%y %T"`": doing video $vid" | tee -a fflog.log
- echo `date +"%d-%m-%y %T"`": -----------------------------------" | tee -a fflog.log
- echo `date +"%d-%m-%y %T"`": Extracting jpeg thumbnail from source video" | tee -a fflog.log
- # create thumbnail
- ffmpeg -v fatal -i $vid -ss 12 -an -vframes 1 $donedir/$basename.jpg
- mogrify -resize 320x240 $donedir/$basename.jpg
- echo `date +"%d-%m-%y %T"`": starting ffmpeg MP4 encode..." | tee -a fflog.log
- ffmpeg -v fatal -threads 0 -i $vid -vcodec libx264 -level 31 -crf 25 -r 25 -vf "scale=iw*min(320/iw\,240/ih):ih*min(240/iw\,240/ih),pad=320:240:(320-iw)/2:(240-ih)/2" -acodec libvo_aacenc -ac 1 -ab 64k $donedir/$basename.temp.mp4
- mp4exit=$?
- MP4Box -nosys -hint -inter 500 -cat $donedir/$basename.temp.mp4 -cat /home/zavids/rawvids/zarchive/outros/outro.mp4 -new $donedir/$basename.mp4
- rm $donedir/$basename.temp.mp4
- echo `date +"%d-%m-%y %T"`": starting ffmpeg 3GP encode..." | tee -a fflog.log
- ffmpeg -v fatal -threads 0 -i $vid -vcodec h263 -s qcif -r 15 -vb 110k -vf "scale=iw*min(176/iw\,144/ih):ih*min(176/iw\,144/ih),pad=176:144:(176-iw)/2:(144-ih)/2" -acodec libopencore_amrnb -ac 1 -ar 8000 -ab 12.2k $donedir/$basename.temp.3gp
- gpexit=$?
- MP4Box -nosys -hint -inter 500 -cat $donedir/$basename.temp.3gp -cat /home/zavids/rawvids/zarchive/outros/outro.3gp -new $donedir/$basename.3gp
- rm $donedir/$basename.temp.3gp
- if [ $gpexit = 0 ]; then
- if [ $mp4exit = 0 ]; then
- echo `date +"%d-%m-%y %T"`": Both encoding processes for $vid completed successfully." | tee -a fflog.log
- if [ $? = 0 ]; then
- echo `date +"%d-%m-%y %T"`": $vid moved to the done dir successfully" | tee -a fflog.log
- fi
- else
- echo `date +"%d-%m-%y %T"`": 3GP for $vid succeeded, but MP4 failed... ffmpeg error code $mp4exit" | tee -a fflog.log
- fi
- else
- if [ $mp4exit = 0 ]; then
- echo `date +"%d-%m-%y %T"`": MP4 for $vid succeeded, but 3GP failed... ffmpeg error code $gpexit" | tee -a fflog.log
- else
- echo `date +"%d-%m-%y %T"`": Both MP4 and 3GP for $vid failed. Exit codes are $mp4exit and $gpexit respectively" | tee -a fflog.log
- fi
- fi
- # encode processes done, I'll move the source file to the done dir now
- mv $vid $olddir
- echo `date +"%d-%m-%y %T"`": -----------------------------------" | tee -a fflog.log
- echo " " | tee -a fflog.log
- echo " " | tee -a fflog.log
- done
- if [ -f /tmp/autoff.pid ]; then
- rm /tmp/autoff.pid
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement