Advertisement
Guest User

MFarah_Script

a guest
Jul 30th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # 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.
  4.  
  5.  
  6. # 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.
  7. # That's not a good thing, so first off we'll make sure there are no other copies of it running.
  8. date >> /tmp/date.log
  9. if [ -f /tmp/autoff.pid ]; then
  10. # seems like it's already running, but let's double check
  11. if [ "$(ps -p `cat /tmp/autoff.pid` | wc -l)" -gt 1 ]; then
  12. # yep it's running.
  13. echo "$0: seems like there's already an autoff process running... PID: `cat /tmp/autoff.pid`"
  14. exit 0
  15. fi
  16. else
  17. # nah it's an old autoff.pid from a run that didn't complete
  18. rm /tmp/autoff.pid
  19. fi
  20.  
  21. # store the current PID in /tmp/autoff.pid
  22. echo $$ >/tmp/autoff.pid
  23.  
  24.  
  25. # setup the source and destination folders, and where to put the old vids...
  26. sourcedir=/home/zavids/rawvids/source
  27. olddir=/home/zavids/rawvids/zcomplete
  28. donedir=/home/zavids/www/vfiles
  29.  
  30. # get the list of videos in the source folder
  31. vidstodo=`ls $sourcedir/*.mp4 $sourcedir/*.flv -1`
  32.  
  33.  
  34. for vid in `echo $vidstodo`; do
  35.  
  36. # get the vid's basename
  37. basename=${vid%.*}
  38. basename=${basename##*/}
  39.  
  40. echo `date +"%d-%m-%y %T"`": doing video $vid" | tee -a fflog.log
  41. echo `date +"%d-%m-%y %T"`": -----------------------------------" | tee -a fflog.log
  42. echo `date +"%d-%m-%y %T"`": Extracting jpeg thumbnail from source video" | tee -a fflog.log
  43.  
  44. # create thumbnail
  45. ffmpeg -v fatal -i $vid -ss 12 -an -vframes 1 $donedir/$basename.jpg
  46. mogrify -resize 320x240 $donedir/$basename.jpg
  47.  
  48. echo `date +"%d-%m-%y %T"`": starting ffmpeg MP4 encode..." | tee -a fflog.log
  49.  
  50. 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
  51. mp4exit=$?
  52. MP4Box -nosys -hint -inter 500 -cat $donedir/$basename.temp.mp4 -cat /home/zavids/rawvids/zarchive/outros/outro.mp4 -new $donedir/$basename.mp4
  53. rm $donedir/$basename.temp.mp4
  54.  
  55. echo `date +"%d-%m-%y %T"`": starting ffmpeg 3GP encode..." | tee -a fflog.log
  56.  
  57. 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
  58. gpexit=$?
  59. MP4Box -nosys -hint -inter 500 -cat $donedir/$basename.temp.3gp -cat /home/zavids/rawvids/zarchive/outros/outro.3gp -new $donedir/$basename.3gp
  60. rm $donedir/$basename.temp.3gp
  61.  
  62. if [ $gpexit = 0 ]; then
  63. if [ $mp4exit = 0 ]; then
  64. echo `date +"%d-%m-%y %T"`": Both encoding processes for $vid completed successfully." | tee -a fflog.log
  65. if [ $? = 0 ]; then
  66. echo `date +"%d-%m-%y %T"`": $vid moved to the done dir successfully" | tee -a fflog.log
  67. fi
  68. else
  69. echo `date +"%d-%m-%y %T"`": 3GP for $vid succeeded, but MP4 failed... ffmpeg error code $mp4exit" | tee -a fflog.log
  70. fi
  71. else
  72. if [ $mp4exit = 0 ]; then
  73. echo `date +"%d-%m-%y %T"`": MP4 for $vid succeeded, but 3GP failed... ffmpeg error code $gpexit" | tee -a fflog.log
  74. else
  75. echo `date +"%d-%m-%y %T"`": Both MP4 and 3GP for $vid failed. Exit codes are $mp4exit and $gpexit respectively" | tee -a fflog.log
  76. fi
  77. fi
  78.  
  79. # encode processes done, I'll move the source file to the done dir now
  80. mv $vid $olddir
  81.  
  82. echo `date +"%d-%m-%y %T"`": -----------------------------------" | tee -a fflog.log
  83. echo " " | tee -a fflog.log
  84. echo " " | tee -a fflog.log
  85. done
  86.  
  87.  
  88. if [ -f /tmp/autoff.pid ]; then
  89. rm /tmp/autoff.pid
  90. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement