hpsaturn

Banner Bash (Video sequence generator)

May 24th, 2011
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.57 KB | None | 0 0
  1. #! /bin/bash
  2. #########################################################################
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15. #########################################################################
  16. # AUTHOR:  Antonio Vanegas
  17. # WEBPAGE: http://devel.androidsith.com
  18. # DEMO:    http://www.youtube.com/watch?v=F-FiqQEy_OI
  19. #
  20. # DESCRIPTION:
  21. # Video generator of numeric sequences (decremental, incremental, randomic)
  22. #
  23. # REVISION:
  24. # ------------------------------------------------------------------------
  25. # 20110422 Intial version, functions: Random Control via adb from Android
  26. # 20110524 add functions incremental and decremental. Remove adb control
  27. ##########################################################################
  28. # PACKAGE DEPENDS:
  29. # apt-get install mplayer ffmpeg imagemagick bsdmainutils giflib-tools
  30. ##########################################################################
  31. # CONFIG:
  32. WORKDIR=/tmp
  33. APPDIR=banner
  34. TEMP=$WORKDIR/$APPDIR/tmp
  35. CWIDTH=75                            # Character. Use 132 for frames<100 (best quality)
  36. MODULO=100                           # random%MODULO Example: 100 -> (0-100)
  37. RES="200x200"                        # recommended 600x900 (slow)
  38. COLOR="255 0 10"                     # RGB
  39. OUTPUTDATE=`date +%Y%m%d_%k%M%S`     # string to append file
  40. PLAYVIDEO=1                          # Play video with parameters mplayer -fs -speed x xx.avi
  41. ##########################################################################
  42.  
  43. # Functions
  44. show_help (){
  45.   echo "Banner rev201105 (hpsaturn)"
  46.   echo ""
  47.   echo "SYNOPSYS:"
  48.   echo "banner [command] [options]"
  49.   echo "banner [command] frames speed"
  50.   echo "banner [command] [int] [float]"
  51.   echo "banner [command] [frames]"
  52.   echo ""
  53.   echo "EXAMPLES:"
  54.   echo "banner decremental 20 0.8 (countdown)"
  55.   echo "banner incremental 10"
  56.   echo "banner random 100"
  57.   echo ""
  58.   echo "Speed: Optional, default 1"
  59.   echo "Frames:0-9999"
  60.   echo ""
  61. }
  62. run_video () {  # parameter: speed
  63.   echo "Playing video:"
  64.   mplayer -fs -speed $1 $TEMP/banner_out$OUTPUTDATE.avi 2>/dev/null
  65.   echo "ok"
  66. }
  67. generate_img () { #parameters: input_number, output_name
  68.   printerbanner -w $CWIDTH $1 | text2gif -c $COLOR > $TEMP/$2.gif
  69.   convert -rotate 270 -resize $RES $TEMP/$2.gif $TEMP/out_$2.jpg 2> /dev/null
  70. }
  71. generate_video () {
  72.   echo -n "Loading video.."
  73.   ffmpeg -y -r 1 -i $TEMP/out_%04d.jpg -vcodec copy $TEMP/banner_out$OUTPUTDATE.avi 2>/dev/null
  74.   echo "ok"
  75. }
  76. set_random(){
  77.   echo  "Loading images"
  78.   i=0;
  79.   for (( k=0; k<=$1; k++ ))
  80.   do
  81.     i=`printf '%04d' $i`
  82.     random=$((RANDOM%$MODULO))
  83.     generate_img $random $i
  84.     echo -n -e "\r$i/$1"
  85.     i=`expr $i + 1`
  86.   done
  87. }
  88. set_incremental(){
  89.   echo "Loading images"
  90.   i=0;
  91.   for (( k=0; k<=$1; k++ ))
  92.   do
  93.     i=`printf '%04d' $i`
  94.     generate_img $k $i
  95.     echo -n -e "\r$i/$1"
  96.     i=`expr $i + 1`
  97.   done
  98. }
  99. set_decremental(){
  100.   echo "Loading images"
  101.   i=0;
  102.   for (( k=$1; k>=0; k-- ))
  103.   do
  104.     i=`printf '%04d' $i`
  105.     generate_img $k $i
  106.     echo -n -e "\r$i/$1"
  107.     i=`expr $i + 1`
  108.   done
  109. }
  110. test_dirs(){
  111.   mkdir -p $TEMP
  112. }
  113. clean_temp (){
  114.   echo -n "Cleanning.."
  115.   rm -r $WORKDIR/$APPDIR
  116.   echo "ok"
  117. }
  118. # check parameters
  119. if [ "$1" == "" ] ; then
  120.   show_help
  121.   exit 0
  122. else
  123.   COMMAND=$1
  124. fi
  125. if [ "$2" == "" ] ; then
  126.   show_help
  127.   exit 0
  128. else
  129.   FRAMES=$2
  130. fi
  131. if [ "$3" == "" ] ; then
  132.   SPEED=1
  133. else
  134.   SPEED=$3
  135. fi
  136. ########################################################
  137. ##                        MAIN                        ##
  138. ########################################################
  139. test_dirs
  140. currentdir=`pwd`
  141.  
  142. case "$COMMAND" in
  143.   incremental)
  144.     set_incremental $FRAMES
  145.     ;;
  146.   decremental)
  147.     set_decremental $FRAMES
  148.     ;;
  149.   random)
  150.     set_random $FRAMES
  151.     ;;
  152.   *)
  153.     show_help
  154.     exit 0
  155.     ;;
  156. esac
  157. echo -e "\nok"
  158.  
  159. generate_video
  160. if [ $PLAYVIDEO == 1 ] ; then
  161.  run_video $SPEED
  162. fi
  163. echo "Output video: $currentdir/banner_out$OUTPUTDATE.avi"
  164. mv $TEMP/banner_out$OUTPUTDATE.avi $currentdir/
  165. clean_temp
Advertisement
Add Comment
Please, Sign In to add comment