Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- #####################################################################
- # Version: 1.0.0
- #####################################################################
- # GUI для снятия скритшотов с видеофайлов скриптом shot,
- # использующего библиотеку Image Magic
- #
- SHOTVIDEO(){
- if [ -z "$VIDEOFILE" ]; then
- Xdialog --title " " --msgbox "$(gettext 'Не выбран видеофайл!')" 0 0
- exit 1
- fi
- if [ "$INFO" = "false" ]; then
- INFO="-i 0"
- else INFO="-i 1"
- fi
- if [ "$SEED" = "false" ]; then
- SEED="-s 0"
- else SEED="-s 1"
- fi
- if [ "$FOLDERSHOT" = "false" ]; then
- FOLDERSHOT="-f 0"
- else FOLDERSHOT="-f 1"
- fi
- if [ "$NUMBER" == "" ]; then NUMBER=12; fi
- if [ "$PERCENTAGE" == "" ]; then PERCENTAGE=35; fi
- if [ "$FOLDER" == "" ]; then FOLDER=`dirname "$VIDEOFILE"`; fi
- SHOT -n $NUMBER -r $PERCENTAGE"%" -c $COLOR $INFO $SEED $FOLDERSHOT "$VIDEOFILE"
- }
- export -f SHOTVIDEO
- SHOT(){
- #####################################################################
- # Version: 1.5.9
- #####################################################################
- #
- # This script takes screenshots of a movie
- # Depends on mplayer and imagemagick
- #
- # Made by Starlite <http://starl1te.wordpress.com/>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- #####################################################################
- usage="Type shot -h for help"
- _help(){
- echo -e "\nusage: shot [options] [file] ... [fileN]\n
- Options:
- -t <time> - Set time (in minutes) between screenshots; the number of screenshots is calculated automatically.
- -n <number> - Set a fixed number of screenshots to take.
- -m - Manual mode. Use arrows to FF/rewind. Press [S] to make screenshots. Quit mplayer to continue.
- -r <percent> - Change the size of the output image. Less than 40% is recommended.
- -s - Seed mode. Gives extra video and audio information. Removes spaces from filenames.
- -h - Display this help message\n
- If you don't like screenshots run the script again.
- This script depends on Mplayer and ImageMagic. Make sure you have them installed.\n
- Usage example:
- shot -n 25 -r 35% ~/films/film.avi\n"
- }
- shot(){
- # Making screenshots...
- for i in `seq 1 $shots_number`;
- do
- randomiser=$RANDOM; let "randomiser %= 25"
- hop=`echo $[$shot_time*60*$i+$randomiser]`
- mplayer -ss $hop -noautosub -frames 1 -ao null -vo png "$file_path" &> /dev/null
- mv 00000001.png /tmp/shots/$i.png &> /dev/null
- echo -ne "Taking screenshot #${i} \r"
- done
- echo "Taking screenshots... [OK]"
- }
- # ====== first step is here! ^_^ ========
- # Checking options...
- while getopts ":t:n:c:i:s:f:mr:sh" option
- do
- case $option in
- t ) shot_time=$OPTARG; opt=_time;;
- n ) shots_number=$OPTARG; opt=_num;;
- m ) opt=_manual;;
- h ) _help; opt=1; exit 1;;
- s ) seed=$OPTARG;;
- r ) res=$OPTARG;;
- i ) info=$OPTARG;;
- c ) color=$OPTARG;;
- f ) foldershot=$OPTARG;;
- : ) echo "No argument given"; opt=1; exit 1;;
- * ) echo "Unknown option"; echo $usage; opt=1; exit 1;;
- esac
- done
- if [ "$res" == "" ]; then res=35%; fi
- if [ "$opt" == "" ]; then echo "No options given!"; echo $usage; exit 1; fi
- shift $(($OPTIND - 1))
- if [ "$1" == "" ]; then echo "No file given!"; echo $usage; exit 1; fi
- mkdir /tmp/shots
- # Parsing files...
- while [ "$1" != "" ]
- do
- file_path=$1
- file_name_ext=${file_path##*/}
- file_name=`echo "$file_name_ext" | sed '$s/....$//'`
- randomiser=0
- quality=87
- testpath=`dirname "$file_path" | cut -c1`
- if [ "$testpath" == "." ]||[ "$testpath" != "/" ]; then
- file_path=`pwd`/$file_path
- fi
- path=`pwd`
- #########################################
- # GUI for shot Version: 1.0.0 -> folder
- #########################################
- path="$FOLDER"
- #########################################
- cd "$path"
- echo -e "==> Processing file $file_name_ext..."
- # Getting video info...
- tmp="/tmp/shots/info"
- inf=`mplayer "$file_path" -identify -frames 1 -ao null -vo null 2>/dev/null | tee $tmp`
- length=`cat $tmp | grep LENGTH | sed -e 's/^.*=//' -e 's/[.].*//'`
- if [ "$length" == "" ]; then echo "Error! Can't get the length of the movie."; exit 1; fi
- # Calculating timing...
- if [ "$opt" == "_time" ]; then
- shots_number=`echo $[$length/60/$shot_time]`
- shot
- elif [ "$opt" == "_num" ]; then
- shot_time=`echo $[$length/$shots_number/60]`
- shot
- elif [ "$opt" == "_manual" ]; then
- cd /tmp/shots
- echo "Press [S] to make screenshots."
- mplayer -ao null -vf screenshot -quiet "$file_path"
- echo "Taking screenshots... [OK]"
- fi
- # Merging screenshots...
- echo -n "Putting screenshots together..."
- cd /tmp/shots/
- montage -background $COLOR -geometry +2+2 `ls *.png | sort -n` "$file_name".jpg
- mogrify -resize $res "$file_name".jpg
- echo " [OK]"
- echo -n "Getting video info..."
- size=`stat -c%s "$file_path"`
- size=`echo $[$size/1024/1024]`
- format=`cat $tmp | grep VIDEO: | cut -d " " -f 5`
- length=`echo $[$length/60]`
- # It's a tricky code here, it adds some info about the movie to the output image.
- #########################################
- # GUI for shot Version: 1.0.0 -> info
- #########################################
- if [ "$info" == "1" ]; then
- 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
- convert -background $COLOR "$file_name".jpg -quality $quality -splice 0x80 -draw 'image over 5,5 0,0 text.jpg' "$path/$file_name".jpg
- else
- convert -background $COLOR "$file_name".jpg -quality $quality "$path/$file_name".jpg
- fi
- #########################################
- echo " [OK]"
- cd "$path"
- # Extra info
- if [ "$seed" == "1" ]; then
- #====Video====
- width=`cat $tmp | grep VIDEO_WIDTH | sed -e 's/^.*=//'`
- height=`cat $tmp | grep VIDEO_HEIGHT | sed -e 's/^.*=//'`
- format=`cat $tmp | grep VIDEO_FORMAT | sed -e 's/^.*=//'`
- vcodec=`cat $tmp | grep VIDEO_CODEC | sed -e 's/^.*=//'`
- video="Format: $format\nCodec: $vcodec"
- size="Size: $width*$height"
- #====Audio====
- rate=`cat $tmp | grep AUDIO_RATE | sed -e 's/^.*=//' | tail -n 1`
- acodec=`cat $tmp | grep afm: | sed -e 's/^.*: //'`
- lang1=`cat $tmp | grep ID_AID_0_LANG | sed -e 's/^.*=//'`
- lang2=`cat $tmp | grep ID_AID_1_LANG | sed -e 's/^.*=//'`
- audio="Audio: $rate $acodec"
- lang="Dub: 1: $lang1 2: $lang2"
- echo -e "\n$video\n$size\n$audio\n$lang"
- #filenames trimming
- file_name_sp=`echo "$file_name" | sed 's/ /_/g'`
- mv "$file_name".jpg "$file_name_sp".jpg &> /dev/null
- fi
- #########################################
- # GUI for shot Version: 1.0.0 -> foldershot
- #########################################
- if [ "$foldershot" == "1" ]; then
- rm /tmp/shots/info
- rm /tmp/shots/"$file_name".jpg
- rm /tmp/shots/text.jpg
- mkdir "$FOLDER"/"$file_name"
- mv /tmp/shots/* "$FOLDER"/"$file_name" &> /dev/null
- mv "$FOLDER"/"$file_name".jpg "$FOLDER"/"$file_name" &> /dev/null
- fi
- #########################################
- rm /tmp/shots/*
- echo
- shift
- done
- rm -r /tmp/shots
- echo "Done"
- }
- export -f SHOT
- export PROG='
- <window title="Видео скриншот 1.0.1">
- <vbox>
- <notebook labels="Скриншот|Помощь">
- <vbox>
- <hbox>
- <frame Выберите файл>
- <hbox>
- <entry accept="filename"><variable>VIDEOFILE</variable></entry>
- <button>
- <input file stock="gtk-open"></input>
- <action type="fileselect">VIDEOFILE</action>
- </button>
- </hbox>
- </frame>
- </hbox>
- <frame Количество кадров Процент от размера>
- <hbox>
- <entry>
- <variable>NUMBER</variable>
- <default>12</default>
- </entry>
- <entry>
- <variable>PERCENTAGE</variable>
- <default>35</default>
- </entry>
- </hbox>
- </frame>
- <frame Цвет фона>
- <hbox>
- <combobox>
- <variable>COLOR</variable>
- <item>white</item>
- <item>Khaki</item>
- <item>Gray</item>
- <item>Yellow</item>
- <item>Red</item>
- <item>Blue</item>
- <item>lightblue</item>
- <item>Lime</item>
- <item>Purple</item>
- <item>Green</item>
- <item>Magenta</item>
- </combobox>
- <checkbox>
- <label>"info"</label>
- <variable>INFO</variable>
- <default>yes</default>
- </checkbox>
- <checkbox>
- <label>"seed"</label>
- <variable>SEED</variable>
- </checkbox>
- <checkbox>
- <label>"folder"</label>
- <variable>FOLDERSHOT</variable>
- </checkbox>
- </hbox>
- </frame>
- <frame Путь сохранения>
- <hbox>
- <entry accept="directory"><variable>FOLDER</variable></entry>
- <button>
- <input file stock="gtk-open"></input>
- <action type="fileselect">FOLDER</action>
- </button>
- </hbox>
- <text xalign="0">
- <label>Оставьте поле пустым для сохранения скриншота в директории видеофайла</label>
- </text>
- </frame>
- <hbox>
- <button>
- <label>Создать</label>
- <action>SHOTVIDEO</action>
- <action>Clear:VIDEOFILE</action>
- </button>
- <button>
- <label>Выход</label>
- </button>
- </hbox>
- </vbox>
- <vbox>
- <text space-fill="true">
- <label>" "</label>
- </text>
- <text space-fill="true">
- <label>GTK 3</label>
- </text>
- <text space-fill="true">
- <label>" "</label>
- </text>
- <text space-fill="true">
- <label>Графическая оболочка</label>
- </text>
- <text space-fill="true">
- <label>для скрипта shot от</label>
- </text>
- <text space-fill="true">
- <label>Starlite http://starl1te.wordpress.com/</label>
- </text>
- <text space-fill="true">
- <label>" "</label>
- </text>
- <text space-fill="true">
- <label>Требуются установленный mplayer</label>
- </text>
- <text space-fill="true">
- <label>и библиотека Image Magic</label>
- </text>
- </vbox>
- </notebook>
- </vbox>
- </window>
- '
- gtkdialog3 --program PROG > /dev/null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement