m0ps

pancam.sh

May 25th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.34 KB | None | 0 0
  1. #!/bin/sh
  2. # Title:        pancam.sh
  3. # Purpose:      Correct MOD files from Panasonic videocam (aspect ratio and name)
  4. # Requiremetns: SH shell, mpgtx
  5. # Author:       Maxim Kursin ([email protected])
  6.  
  7. ##################
  8. # VARIABLES      #
  9. ##################
  10. FileDir=`echo $1`
  11.  
  12. ##################
  13. # FUNCTIONS      #
  14. ##################
  15. bConvert ()
  16. {
  17. # Title:        bConvert
  18. # Purpose:      Converts numbers from one base to another
  19. # Requiremetns: BASH shell
  20. # Author:       hgate73 (linuxquestions.org)
  21.  
  22. # Structure:
  23. # $1 is base of number being converted (-d, -h, -b, -o)
  24. # $2 is number to convert
  25. # $3 is base of number to convert to  (-d, -h, -b, -o)
  26. # 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
  27.  
  28. # This is to make sure the input value is in upper-case if it is a letter
  29. number=$( echo "$2" | tr -s '[:lower:]' '[:upper:]' )
  30.  
  31. # Error checking
  32. if [ $# = 0 ]; then echo "You didn't specify any arguments."; exit; fi
  33.  
  34. ##################
  35. # 1. Set IN type #
  36. ##################
  37. if [ "$1" = "-b" ]; then    #bin/2
  38.     inType='2'
  39. elif [ "$1" = "-o" ]; then    #oct/8
  40.     inType=8
  41. elif [ "$1" = "-d" ]; then    #dec/10
  42.     inType=10
  43. elif [ "$1" = "-h" ]; then    #hex/16
  44.     inType=16
  45. fi
  46.  
  47. ###################
  48. # 2. Set OUT type #
  49. ###################
  50. if [ "$3" = "-b" ]; then    #bin/2
  51.     outType='2'
  52. elif [ "$3" = "-o" ]; then    #oct/8
  53.     outType=8
  54. elif [ "$3" = "-d" ]; then    #dec/10
  55.     outType='10'
  56. elif [ "$3" = "-h" ]; then    #hex/16
  57.     outType=16
  58. fi
  59.  
  60. #########################
  61. # 3. Perform conversion #
  62. #########################
  63. result=$(echo "obase=$outType;ibase=$inType;$number" | bc); echo $result
  64. }
  65.  
  66. ##################
  67. # BODY           #
  68. ##################
  69. if [ $# -ne 1 ]
  70. then
  71.     echo "Usage: $0 {base-file-dir-name}"
  72.     exit 1
  73. fi
  74.  
  75. cd $FileDir
  76. #Check if directory for processed files is exist
  77. [ ! -d ./edited ] && mkdir ./edited
  78.  
  79. for OrigFile in $(ls *.MOD); do
  80. #Convert filename
  81.   Hex=`echo $OrigFile | awk -F\\. '{ print substr($1,4) }'`
  82.   Dec=$(bConvert -h $Hex -d)
  83.   StrLen="${#Dec}"
  84.   if [ $StrLen = 1 ]
  85.   then
  86.      NewFile=MOD00$Dec.mpg
  87.   elif [ $StrLen = 2 ]
  88.   then
  89.      NewFile=MOD0$Dec.mpg
  90.   else
  91.      NewFile=MOD$Dec.mpg    
  92.   fi
  93. #Set aspect ration
  94.   mpgtx -j -A3 $OrigFile -o edited/$NewFile
  95. done
Advertisement
Add Comment
Please, Sign In to add comment