daily pastebin goal
82%
SHARE
TWEET

landiver

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