Guest User

Time-lapse video with mplayer and mencoder

a guest
Jul 2nd, 2010
1,133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2. # Time-lapse capture script
  3. # Author : Samuel El-Borai
  4. # Date : 29 juin 2010
  5. # Tested with : The iSight of my MacBook Pro 5.1, ArchGNULinux kernel 2.6.34.
  6. #       Both camera of my N900, running Maemo PR 1.2
  7. # Need : mplayer , mencoder
  8. # Lisense : BSD
  9.  
  10. if test $# -ne 2; then
  11.     echo 'Need two arguments : time(seconds) and frames(integer)'
  12.     exit 0
  13. fi
  14.  
  15. if test $1 -eq 0; then
  16.     echo 'Time value must be greater than 0'
  17.     exit 0
  18. fi
  19.  
  20.  
  21. if test $2 -eq 0; then
  22.     echo 'Frames value must be greater than 0'
  23.     exit 0
  24. fi
  25.  
  26. #Change nb_frame (1-9) if you have green pictures.
  27. nb_frame=3
  28. t=$1
  29.  
  30. echo $f
  31.  
  32. rep='motion_'$(date '+%y%m%d%H')
  33.  
  34. mkdir $rep
  35. cd $rep
  36.  
  37. for i in `seq 1 $2`;
  38. do
  39.     mplayer -really-quiet tv:// -vo png -frames $nb_frame;
  40.         case ${#i} in
  41.             1) n='0000'$i;;
  42.             2) n='000'$i;;
  43.             3) n='00'$i;;
  44.             4) n='0'$i;;
  45.             5) n=$i;;
  46.             *) echo "More than 99999 frames. Hug ! It's over NINE THOUSAND !!! (This script can't manage more than 99999 frames. Sorry Dude.)"
  47.                 exit 0;;
  48.         esac
  49.  
  50.         echo $n
  51.     mv 0000000$nb_frame.png screen_$n.png
  52.     rm 0*.png
  53.  
  54. # Time to echo remaining (Change time_to_echo to the minimum time you want between each echo)
  55.     time_to_echo=10
  56.     w=0
  57.    
  58.     if test $t -gt $time_to_echo
  59.     then
  60.         while test $(expr $w + $time_to_echo) -lt $t
  61.         do
  62.             sleep $time_to_echo
  63.             w=$(expr $w + $time_to_echo)
  64.             echo $(expr $t - $w)' seconds to wait'
  65.         done
  66.         #echo 'I will sleep '$(expr $t - $w)' seconds. TEST STATEMENT zOLOL RULEZ'
  67.         sleep $(expr $t - $w)
  68.     else
  69.         sleep $t
  70.     fi
  71.     echo 'Frames '$i' / '$2
  72. done
  73.  
  74. mencoder "mf://*.png" -mf fps=12:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vbitrate=7000 -vf scale=640:480 -oac copy -o movie_$rep.avi
  75.  
  76. exit 0
RAW Paste Data