Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #########################################################################
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #########################################################################
- # AUTHOR: Antonio Vanegas
- # WEBPAGE: http://devel.androidsith.com
- # DEMO: http://www.youtube.com/watch?v=F-FiqQEy_OI
- #
- # DESCRIPTION:
- # Video generator of numeric sequences (decremental, incremental, randomic)
- #
- # REVISION:
- # ------------------------------------------------------------------------
- # 20110422 Intial version, functions: Random Control via adb from Android
- # 20110524 add functions incremental and decremental. Remove adb control
- ##########################################################################
- # PACKAGE DEPENDS:
- # apt-get install mplayer ffmpeg imagemagick bsdmainutils giflib-tools
- ##########################################################################
- # CONFIG:
- WORKDIR=/tmp
- APPDIR=banner
- TEMP=$WORKDIR/$APPDIR/tmp
- CWIDTH=75 # Character. Use 132 for frames<100 (best quality)
- MODULO=100 # random%MODULO Example: 100 -> (0-100)
- RES="200x200" # recommended 600x900 (slow)
- COLOR="255 0 10" # RGB
- OUTPUTDATE=`date +%Y%m%d_%k%M%S` # string to append file
- PLAYVIDEO=1 # Play video with parameters mplayer -fs -speed x xx.avi
- ##########################################################################
- # Functions
- show_help (){
- echo "Banner rev201105 (hpsaturn)"
- echo ""
- echo "SYNOPSYS:"
- echo "banner [command] [options]"
- echo "banner [command] frames speed"
- echo "banner [command] [int] [float]"
- echo "banner [command] [frames]"
- echo ""
- echo "EXAMPLES:"
- echo "banner decremental 20 0.8 (countdown)"
- echo "banner incremental 10"
- echo "banner random 100"
- echo ""
- echo "Speed: Optional, default 1"
- echo "Frames:0-9999"
- echo ""
- }
- run_video () { # parameter: speed
- echo "Playing video:"
- mplayer -fs -speed $1 $TEMP/banner_out$OUTPUTDATE.avi 2>/dev/null
- echo "ok"
- }
- generate_img () { #parameters: input_number, output_name
- printerbanner -w $CWIDTH $1 | text2gif -c $COLOR > $TEMP/$2.gif
- convert -rotate 270 -resize $RES $TEMP/$2.gif $TEMP/out_$2.jpg 2> /dev/null
- }
- generate_video () {
- echo -n "Loading video.."
- ffmpeg -y -r 1 -i $TEMP/out_%04d.jpg -vcodec copy $TEMP/banner_out$OUTPUTDATE.avi 2>/dev/null
- echo "ok"
- }
- set_random(){
- echo "Loading images"
- i=0;
- for (( k=0; k<=$1; k++ ))
- do
- i=`printf '%04d' $i`
- random=$((RANDOM%$MODULO))
- generate_img $random $i
- echo -n -e "\r$i/$1"
- i=`expr $i + 1`
- done
- }
- set_incremental(){
- echo "Loading images"
- i=0;
- for (( k=0; k<=$1; k++ ))
- do
- i=`printf '%04d' $i`
- generate_img $k $i
- echo -n -e "\r$i/$1"
- i=`expr $i + 1`
- done
- }
- set_decremental(){
- echo "Loading images"
- i=0;
- for (( k=$1; k>=0; k-- ))
- do
- i=`printf '%04d' $i`
- generate_img $k $i
- echo -n -e "\r$i/$1"
- i=`expr $i + 1`
- done
- }
- test_dirs(){
- mkdir -p $TEMP
- }
- clean_temp (){
- echo -n "Cleanning.."
- rm -r $WORKDIR/$APPDIR
- echo "ok"
- }
- # check parameters
- if [ "$1" == "" ] ; then
- show_help
- exit 0
- else
- COMMAND=$1
- fi
- if [ "$2" == "" ] ; then
- show_help
- exit 0
- else
- FRAMES=$2
- fi
- if [ "$3" == "" ] ; then
- SPEED=1
- else
- SPEED=$3
- fi
- ########################################################
- ## MAIN ##
- ########################################################
- test_dirs
- currentdir=`pwd`
- case "$COMMAND" in
- incremental)
- set_incremental $FRAMES
- ;;
- decremental)
- set_decremental $FRAMES
- ;;
- random)
- set_random $FRAMES
- ;;
- *)
- show_help
- exit 0
- ;;
- esac
- echo -e "\nok"
- generate_video
- if [ $PLAYVIDEO == 1 ] ; then
- run_video $SPEED
- fi
- echo "Output video: $currentdir/banner_out$OUTPUTDATE.avi"
- mv $TEMP/banner_out$OUTPUTDATE.avi $currentdir/
- clean_temp
Advertisement
Add Comment
Please, Sign In to add comment