Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Title: pancam.sh
- # Purpose: Correct MOD files from Panasonic videocam (aspect ratio and name)
- # Requiremetns: SH shell, mpgtx
- # Author: Maxim Kursin ([email protected])
- ##################
- # VARIABLES #
- ##################
- FileDir=`echo $1`
- ##################
- # FUNCTIONS #
- ##################
- bConvert ()
- {
- # Title: bConvert
- # Purpose: Converts numbers from one base to another
- # Requiremetns: BASH shell
- # Author: hgate73 (linuxquestions.org)
- # Structure:
- # $1 is base of number being converted (-d, -h, -b, -o)
- # $2 is number to convert
- # $3 is base of number to convert to (-d, -h, -b, -o)
- # Example: ./bConvert.sh -d 3 -b will convert the decimal (-d for DECIMAL) number 3 to binary (-b for BINARY). It should result in 11
- # This is to make sure the input value is in upper-case if it is a letter
- number=$( echo "$2" | tr -s '[:lower:]' '[:upper:]' )
- # Error checking
- if [ $# = 0 ]; then echo "You didn't specify any arguments."; exit; fi
- ##################
- # 1. Set IN type #
- ##################
- if [ "$1" = "-b" ]; then #bin/2
- inType='2'
- elif [ "$1" = "-o" ]; then #oct/8
- inType=8
- elif [ "$1" = "-d" ]; then #dec/10
- inType=10
- elif [ "$1" = "-h" ]; then #hex/16
- inType=16
- fi
- ###################
- # 2. Set OUT type #
- ###################
- if [ "$3" = "-b" ]; then #bin/2
- outType='2'
- elif [ "$3" = "-o" ]; then #oct/8
- outType=8
- elif [ "$3" = "-d" ]; then #dec/10
- outType='10'
- elif [ "$3" = "-h" ]; then #hex/16
- outType=16
- fi
- #########################
- # 3. Perform conversion #
- #########################
- result=$(echo "obase=$outType;ibase=$inType;$number" | bc); echo $result
- }
- ##################
- # BODY #
- ##################
- if [ $# -ne 1 ]
- then
- echo "Usage: $0 {base-file-dir-name}"
- exit 1
- fi
- cd $FileDir
- #Check if directory for processed files is exist
- [ ! -d ./edited ] && mkdir ./edited
- for OrigFile in $(ls *.MOD); do
- #Convert filename
- Hex=`echo $OrigFile | awk -F\\. '{ print substr($1,4) }'`
- Dec=$(bConvert -h $Hex -d)
- StrLen="${#Dec}"
- if [ $StrLen = 1 ]
- then
- NewFile=MOD00$Dec.mpg
- elif [ $StrLen = 2 ]
- then
- NewFile=MOD0$Dec.mpg
- else
- NewFile=MOD$Dec.mpg
- fi
- #Set aspect ration
- mpgtx -j -A3 $OrigFile -o edited/$NewFile
- done
Advertisement
Add Comment
Please, Sign In to add comment