Advertisement
Guest User

Ajunta

a guest
Jun 10th, 2009
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.64 KB | None | 0 0
  1. #!/bin/bash
  2. #####################################################################
  3. #
  4. # This script takes screenshots of a movie
  5. # Depends on mplayer and imagemagick
  6. #
  7. # Made by   Starlite    <http://starl1te.wordpress.com/>
  8. # Adn modifed by    Ajunta
  9. #
  10. # This script is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU Lesser General Public
  12. # License as published by the Free Software Foundation; either
  13. # version 2 of the License, or (at your option) any later version.
  14. #
  15. #####################################################################
  16.  
  17. usage="Type shot -h for help"
  18. _help(){
  19. echo -e "\nusage: shot [options] [file] ... [fileN]\n
  20. Options:
  21.  -t <time> - Set time (in minutes) between screenshots; the number of screenshots is calculated automatically.
  22.  -n <number> - Set a fixed number of screenshots to take.
  23.  -r <percent> - Change the size of the output image. Less than 40% is recommended.
  24.  -s - Seed mode. Gives extra video and audio information. Removes spaces.
  25.  -T <number> - Set number of tiles per row and column (if given, will override number of shots to fill the grid)
  26.  -h - Display this help message\n
  27.  
  28. If you don't like taken screenshots, try to run the script once more.
  29. This script depends on Mplayer and ImageMagic.\n
  30. Usage example:
  31. shot -n 25 -r 35% ~/films/film.avi\n"
  32. }
  33.  
  34. shot(){
  35. # Making screenshots...
  36. for i in `seq 1 $shots_number`;
  37. do
  38.   randomiser=$RANDOM; let "randomiser %= 25"
  39.   hop=`echo $[$shot_time*60*$i+$randomiser]`
  40.   mplayer -ss $hop -noautosub -frames 1 -ao null -vo png "$file_path" > /dev/null 2>&1
  41.   mv 00000001.png /tmp/shots/$i.png
  42.   echo -ne "Taking screenshot #${i} \r"
  43. done
  44.   echo "Taking screenshots...           [OK]"
  45. }
  46.  
  47. tile="";
  48.  
  49. # ====== first step is here! ;-) ========
  50. # Checking options...
  51. while getopts ":t:n:r:T:sh" option
  52.     do
  53.         case $option in
  54.         t ) shot_time=$OPTARG; opt=_time;;
  55.         n ) shots_number=$OPTARG; opt=_num;;
  56.         h ) _help; opt=1; exit 1;;
  57.         s ) seed=1;;
  58.         T ) tile=$OPTARG; opt=_num;;
  59.         r ) res=$OPTARG;;
  60.         : ) echo "No argument given"; opt=1; exit 1;;
  61.         * ) echo "Unknown option"; echo $usage; opt=1; exit 1;;
  62.         esac
  63.     done
  64.  
  65. #Checking T option:
  66. if [ !["$tile" != ""] ]; then
  67.   A=`echo $tile | cut -d'x' -f1`
  68.   B=`echo $tile | cut -d'x' -f2`
  69.   shots_number=$(($A*$B))
  70.   echo $shots_number
  71. fi
  72.  
  73. echo "Number of shots "$shots_number
  74.  
  75. if [ "$res" == "" ]; then res=35%; fi
  76. if [ "$opt" == "" ]; then echo "No option given!"; echo $usage; exit 1; fi
  77. shift $(($OPTIND - 1))
  78. if [ "$1" == "" ]; then echo "No file given!"; echo $usage; exit 1; fi
  79. mkdir /tmp/shots
  80.  
  81. # Parsing files...
  82. while [ "$1" != "" ]
  83. do
  84.   file_path=$1
  85.   file_name_ext=${file_path##*/}
  86.   file_name=`echo "$file_name_ext" | sed '$s/....$//'`
  87.   randomiser=0
  88.   quality=87
  89.   movdir=`dirname "$file_path"`
  90.     if [ "$movdir" == "." ]; then
  91.     movdir=`pwd`
  92.     file_path=$movdir/$file_path
  93.     fi
  94.   cd "$movdir"
  95. echo "Processing file $file_name_ext..."
  96.  
  97. # Getting movie length...
  98. length=`mplayer -identify "$file_path" -frames 1 -ao null -vo null 2>/dev/null \
  99. | grep LENGTH | sed -e 's/^.*=//' -e 's/[.].*//'`
  100.  
  101. if [ "$length" == "" ]; then echo "Error! Can't get the length of the movie."; exit 1; fi
  102.  
  103. if [ "$opt" == "_time" ]; then
  104.     shots_number=`echo $[$length/60/$shot_time]`
  105.     shot
  106. elif [ "$opt" == "_num" ]; then
  107.     shot_time=`echo $[$length/$shots_number/60]`
  108.     shot
  109. fi
  110.  
  111. # Placing all taken screenshots in one picture...
  112. echo -n "Putting screenshots together..."
  113. cd /tmp/shots/
  114. montage -geometry +2+2  -tile $tile `ls *.png | sort -n` "$file_name".jpg #
  115. mogrify -resize $res "$file_name".jpg
  116. echo " [OK]"
  117. echo -n "Getting video info..."
  118. size=`stat -c%s "$file_path"`
  119. size=`echo $[$size/1024/1024]`
  120. format=`mplayer -frames 1 -ao null -vo null -identify 2>/dev/null "$file_path" | grep VIDEO: | cut -d " " -f 5`
  121. length=`echo $[$length/60]`
  122. # It's a tricky code here, it adds some info about the movie to the output image.
  123. echo -e "File name: $file_name_ext\nSize: $size Mb\nResolution: $format\nDuration: $length min." | convert -pointsize 16 -trim +repage text:- text.jpg
  124. convert "$file_name".jpg -quality $quality -splice 0x80 -draw 'image over 5,5 0,0 text.jpg' "$movdir/$file_name".jpg
  125. echo "           [OK]"; echo
  126. cd "$movdir"
  127.     if [ "$seed" == "1" ]; then
  128.     VIDEO=`mplayer -frames 1 -ao null -vo null -identify 2>/dev/null "$file_path" | grep VIDEO:`
  129.     AUDIO=`mplayer -frames 1 -ao null -vo null -identify 2>/dev/null "$file_path" | grep AUDIO: | cut -d "(" -f 1`
  130.     echo -e "LENGTH: $length min.\n$VIDEO\n$AUDIO"; echo
  131.     file_name_sp=`echo "$file_name" | sed 's/ /_/g'`
  132.     mv "$file_name".jpg "$file_name_sp".jpg 2>/dev/null
  133.     fi
  134. shift
  135. done
  136.  
  137. rm -r /tmp/shots
  138. echo "Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement