Advertisement
tolikpunkoff

videoscreenshot1

Jun 25th, 2016
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.96 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. #####################################################################
  4. # Version: 1.0.0
  5. #####################################################################
  6. # GUI для снятия скритшотов с видеофайлов скриптом shot,
  7. # использующего библиотеку Image Magic
  8. #
  9.  
  10. SHOTVIDEO(){
  11.    
  12.     if [ -z "$VIDEOFILE" ]; then
  13.         Xdialog --title " " --msgbox "$(gettext 'Не выбран видеофайл!')" 0 0  
  14.         exit 1
  15.     fi
  16.    
  17.     if [ "$INFO" = "false" ]; then
  18.           INFO="-i 0"
  19.      else INFO="-i 1"
  20.     fi
  21.        
  22.     if [ "$SEED" = "false" ]; then
  23.           SEED="-s 0"
  24.      else SEED="-s 1"
  25.     fi
  26.        
  27.     if [ "$FOLDERSHOT" = "false" ]; then
  28.           FOLDERSHOT="-f 0"
  29.      else FOLDERSHOT="-f 1"
  30.     fi
  31.  
  32.     if [ "$NUMBER" == "" ]; then NUMBER=12; fi
  33.     if [ "$PERCENTAGE" == "" ]; then PERCENTAGE=35; fi 
  34.     if [ "$FOLDER" == "" ]; then FOLDER=`dirname "$VIDEOFILE"`; fi 
  35.  
  36.     SHOT -n $NUMBER -r $PERCENTAGE"%" -c $COLOR $INFO $SEED $FOLDERSHOT "$VIDEOFILE"
  37.  
  38. }
  39. export -f SHOTVIDEO
  40.  
  41. SHOT(){
  42. #####################################################################
  43. #           Version: 1.5.9
  44. #####################################################################
  45. #
  46. # This script takes screenshots of a movie
  47. # Depends on mplayer and imagemagick
  48. #
  49. # Made by   Starlite    <http://starl1te.wordpress.com/>
  50. #
  51. # This program is free software: you can redistribute it and/or modify
  52. # it under the terms of the GNU General Public License as published by
  53. # the Free Software Foundation, either version 3 of the License, or
  54. # (at your option) any later version.
  55. #
  56. # This program is distributed in the hope that it will be useful,
  57. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  58. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  59. # GNU General Public License for more details.
  60. #
  61. # You should have received a copy of the GNU General Public License
  62. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  63. #
  64. #####################################################################
  65.  
  66. usage="Type shot -h for help"
  67.  
  68. _help(){
  69. echo -e "\nusage: shot [options] [file] ... [fileN]\n
  70. Options:
  71.  -t <time> - Set time (in minutes) between screenshots; the number of screenshots is calculated automatically.
  72.  -n <number> - Set a fixed number of screenshots to take.
  73.  -m - Manual mode. Use arrows to FF/rewind. Press [S] to make screenshots. Quit mplayer to continue.
  74.  -r <percent> - Change the size of the output image. Less than 40% is recommended.
  75.  -s - Seed mode. Gives extra video and audio information. Removes spaces from filenames.
  76.  -h - Display this help message\n
  77.  
  78. If you don't like screenshots run the script again.
  79. This script depends on Mplayer and ImageMagic. Make sure you have them installed.\n
  80. Usage example:
  81. shot -n 25 -r 35% ~/films/film.avi\n"
  82. }
  83.  
  84. shot(){
  85. # Making screenshots...
  86. for i in `seq 1 $shots_number`;
  87. do
  88.   randomiser=$RANDOM; let "randomiser %= 25"
  89.   hop=`echo $[$shot_time*60*$i+$randomiser]`
  90.   mplayer -ss $hop -noautosub -frames 1 -ao null -vo png "$file_path" &> /dev/null
  91.   mv 00000001.png /tmp/shots/$i.png &> /dev/null
  92.   echo -ne "Taking screenshot #${i} \r"
  93. done
  94.   echo "Taking screenshots...           [OK]"
  95. }
  96.  
  97. # ====== first step is here! ^_^ ========
  98. # Checking options...
  99. while getopts ":t:n:c:i:s:f:mr:sh" option
  100.     do
  101.         case $option in
  102.         t ) shot_time=$OPTARG; opt=_time;;
  103.         n ) shots_number=$OPTARG; opt=_num;;
  104.         m ) opt=_manual;;
  105.         h ) _help; opt=1; exit 1;;
  106.         s ) seed=$OPTARG;;
  107.         r ) res=$OPTARG;;
  108.         i ) info=$OPTARG;;
  109.         c ) color=$OPTARG;;
  110.         f ) foldershot=$OPTARG;;       
  111.         : ) echo "No argument given"; opt=1; exit 1;;
  112.         * ) echo "Unknown option"; echo $usage; opt=1; exit 1;;
  113.         esac
  114.     done
  115.  
  116. if [ "$res" == "" ]; then res=35%; fi
  117. if [ "$opt" == "" ]; then echo "No options given!"; echo $usage; exit 1; fi
  118. shift $(($OPTIND - 1))
  119. if [ "$1" == "" ]; then echo "No file given!"; echo $usage; exit 1; fi
  120. mkdir /tmp/shots
  121.  
  122. # Parsing files...
  123. while [ "$1" != "" ]
  124. do
  125.   file_path=$1
  126.   file_name_ext=${file_path##*/}
  127.   file_name=`echo "$file_name_ext" | sed '$s/....$//'`
  128.   randomiser=0
  129.   quality=87
  130.   testpath=`dirname "$file_path" | cut -c1`
  131.     if [ "$testpath" == "." ]||[ "$testpath" != "/" ]; then
  132.     file_path=`pwd`/$file_path
  133.     fi
  134.   path=`pwd`
  135. #########################################
  136. # GUI for shot Version: 1.0.0 -> folder
  137. #########################################
  138.   path="$FOLDER"
  139. #########################################
  140.   cd "$path"
  141. echo -e "==> Processing file $file_name_ext..."
  142.  
  143. # Getting video info...
  144. tmp="/tmp/shots/info"
  145. inf=`mplayer "$file_path" -identify -frames 1 -ao null -vo null 2>/dev/null | tee $tmp`
  146.  
  147. length=`cat $tmp | grep LENGTH | sed -e 's/^.*=//' -e 's/[.].*//'`
  148. if [ "$length" == "" ]; then echo "Error! Can't get the length of the movie."; exit 1; fi
  149.  
  150. # Calculating timing...
  151. if [ "$opt" == "_time" ]; then
  152.     shots_number=`echo $[$length/60/$shot_time]`
  153.     shot
  154. elif [ "$opt" == "_num" ]; then
  155.     shot_time=`echo $[$length/$shots_number/60]`
  156.     shot
  157. elif [ "$opt" == "_manual" ]; then
  158.     cd /tmp/shots
  159.     echo "Press [S] to make screenshots."
  160.     mplayer -ao null -vf screenshot -quiet "$file_path"
  161.     echo "Taking screenshots...           [OK]"
  162. fi
  163.  
  164. # Merging screenshots...
  165. echo -n "Putting screenshots together..."
  166. cd /tmp/shots/
  167. montage -background $COLOR -geometry +2+2 `ls *.png | sort -n` "$file_name".jpg
  168. mogrify -resize $res "$file_name".jpg
  169. echo " [OK]"
  170. echo -n "Getting video info..."
  171. size=`stat -c%s  "$file_path"`
  172. size=`echo $[$size/1024/1024]`
  173. format=`cat $tmp | grep VIDEO: | cut -d " " -f 5`
  174. length=`echo $[$length/60]`
  175.  
  176. # It's a tricky code here, it adds some info about the movie to the output image.
  177. #########################################
  178. # GUI for shot Version: 1.0.0 -> info
  179. #########################################
  180. if [ "$info" == "1" ]; then
  181.     echo -e "File name: $file_name_ext\nSize: $size Mb\nResolution: $format\nDuration: $length min." | convert -background $COLOR -pointsize 16 -trim +repage text:- text.jpg
  182.     convert -background $COLOR "$file_name".jpg -quality $quality -splice 0x80 -draw 'image over 5,5 0,0 text.jpg' "$path/$file_name".jpg
  183.     else
  184.     convert -background $COLOR "$file_name".jpg -quality $quality "$path/$file_name".jpg
  185. fi 
  186. #########################################
  187. echo "           [OK]"
  188. cd "$path"
  189. # Extra info
  190.     if [ "$seed" == "1" ]; then
  191.     #====Video====
  192.     width=`cat $tmp | grep VIDEO_WIDTH | sed -e 's/^.*=//'`
  193.     height=`cat $tmp | grep VIDEO_HEIGHT | sed -e 's/^.*=//'`
  194.     format=`cat $tmp | grep VIDEO_FORMAT | sed -e 's/^.*=//'`
  195.     vcodec=`cat $tmp | grep VIDEO_CODEC | sed -e 's/^.*=//'`
  196.     video="Format:  $format\nCodec:  $vcodec"
  197.     size="Size:  $width*$height"
  198.     #====Audio====
  199.     rate=`cat $tmp | grep AUDIO_RATE | sed -e 's/^.*=//' | tail -n 1`
  200.     acodec=`cat $tmp | grep afm: | sed -e 's/^.*: //'`
  201.     lang1=`cat $tmp | grep ID_AID_0_LANG | sed -e 's/^.*=//'`
  202.     lang2=`cat $tmp | grep ID_AID_1_LANG | sed -e 's/^.*=//'`
  203.     audio="Audio:  $rate $acodec"
  204.     lang="Dub:  1: $lang1  2: $lang2"
  205.     echo -e "\n$video\n$size\n$audio\n$lang"
  206.     #filenames trimming
  207.     file_name_sp=`echo "$file_name" | sed 's/ /_/g'`
  208.     mv "$file_name".jpg "$file_name_sp".jpg &> /dev/null
  209.     fi
  210. #########################################
  211. # GUI for shot Version: 1.0.0 -> foldershot
  212. #########################################    
  213.     if [ "$foldershot" == "1" ]; then  
  214.     rm /tmp/shots/info
  215.     rm /tmp/shots/"$file_name".jpg
  216.     rm /tmp/shots/text.jpg    
  217.     mkdir "$FOLDER"/"$file_name"
  218.     mv /tmp/shots/* "$FOLDER"/"$file_name" &> /dev/null
  219.     mv "$FOLDER"/"$file_name".jpg  "$FOLDER"/"$file_name" &> /dev/null 
  220.     fi
  221. #########################################    
  222. rm /tmp/shots/*
  223. echo
  224. shift
  225. done
  226.  
  227. rm -r /tmp/shots
  228. echo "Done"
  229. }
  230. export -f SHOT
  231.  
  232. export PROG='
  233. <window title="Видео скриншот 1.0.1">
  234. <vbox>
  235. <notebook labels="Скриншот|Помощь">
  236. <vbox>
  237.       <hbox>
  238.       <frame Выберите файл>
  239.        <hbox>
  240.          <entry accept="filename"><variable>VIDEOFILE</variable></entry>
  241.          <button>
  242.            <input file stock="gtk-open"></input>
  243.            <action type="fileselect">VIDEOFILE</action>
  244.          </button>
  245.        </hbox>
  246.       </frame>
  247.       </hbox>
  248.       <frame Количество кадров            Процент от размера>
  249.        <hbox>
  250.          <entry>
  251.            <variable>NUMBER</variable>
  252.            <default>12</default>
  253.          </entry>
  254.          <entry>
  255.            <variable>PERCENTAGE</variable>
  256.            <default>35</default>
  257.          </entry>
  258.        </hbox>        
  259.      </frame>
  260.       <frame Цвет фона>
  261.         <hbox>         
  262.           <combobox>
  263.                 <variable>COLOR</variable>
  264.                 <item>white</item>
  265.                 <item>Khaki</item>
  266.                 <item>Gray</item>
  267.                 <item>Yellow</item>                  
  268.                 <item>Red</item>      
  269.                 <item>Blue</item>
  270.                 <item>lightblue</item>      
  271.                 <item>Lime</item>                  
  272.                 <item>Purple</item>      
  273.                 <item>Green</item>    
  274.                 <item>Magenta</item>
  275.           </combobox>
  276.          <checkbox>
  277.            <label>"info"</label>
  278.            <variable>INFO</variable>
  279.            <default>yes</default>
  280.          </checkbox>          
  281.          <checkbox>
  282.            <label>"seed"</label>
  283.            <variable>SEED</variable>
  284.          </checkbox>
  285.          <checkbox>
  286.            <label>"folder"</label>
  287.            <variable>FOLDERSHOT</variable>
  288.          </checkbox>          
  289.        </hbox>      
  290.      </frame>    
  291.       <frame Путь сохранения>
  292.        <hbox>
  293.          <entry accept="directory"><variable>FOLDER</variable></entry>
  294.          <button>
  295.            <input file stock="gtk-open"></input>
  296.            <action type="fileselect">FOLDER</action>
  297.          </button>
  298.         </hbox>
  299.        <text xalign="0">
  300.          <label>Оставьте поле пустым для сохранения скриншота в директории видеофайла</label>
  301.        </text>
  302.       </frame>
  303.       <hbox>  
  304.         <button>
  305.             <label>Создать</label>
  306.             <action>SHOTVIDEO</action>
  307.             <action>Clear:VIDEOFILE</action>
  308.         </button>
  309.         <button>
  310.             <label>Выход</label>
  311.         </button>
  312.  </hbox>
  313.  </vbox>
  314.  <vbox>
  315.   <text space-fill="true">
  316.   <label>"   "</label>
  317.   </text>
  318.   <text space-fill="true">
  319.   <label>GTK 3</label>
  320.   </text>
  321.   <text space-fill="true">
  322.   <label>"   "</label>
  323.   </text>
  324.   <text space-fill="true">
  325.   <label>Графическая оболочка</label>
  326.   </text>
  327.   <text space-fill="true">
  328.   <label>для скрипта shot от</label>
  329.   </text>  
  330.   <text space-fill="true">
  331.   <label>Starlite http://starl1te.wordpress.com/</label>
  332.   </text>    
  333.   <text space-fill="true">
  334.   <label>"   "</label>
  335.   </text>  
  336.   <text space-fill="true">
  337.   <label>Требуются установленный mplayer</label>
  338.   </text>    
  339.   <text space-fill="true">
  340.   <label>и библиотека Image Magic</label>
  341.   </text>    
  342.  </vbox>
  343. </notebook>
  344. </vbox>
  345. </window>
  346. '
  347.  
  348. gtkdialog3 --program PROG > /dev/null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement