#!/bin/bash # ===================================================== # This script takes screenshots of a movie # Depends on mplayer and imagemagick # # Made by Starlite # http://starl1te.wordpress.com/ # Traducido por janitux # http://tecnosquad.org # Feel free to share and modify, but # Please, let me know if you made improvements. # Пожалуйста, дайте мне знать, если вы улучшили этот скрипт. # ===================================================== usage="Escribe shot -h para ayuda" _help(){ echo -e "\nUso: shot [opciones] [fichero]\n Options: -t - Define el tiempo (En minutos) entre las screenshots; el número de screenshots es calculado automaticamente. -n - Define el número de screenshots a tomar. -r - Cambia el tamaño de la imagen destino. Menos de 40% es lo recomendado. -h - Muestra este mensaje de ayuda.\n Solo puedes ingresar una opcion a la vez. Si no te gustaron las screenshots tomadas, prueba ejecutando el script denuevo. Este script depende de Mplayer e ImageMagic.\n Ejemplo de Uso: shot -n 25 -r 35% ~/films/film.avi\n" } shot(){ # Tomando 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 2>&1 mv 00000001.png /tmp/shots/$i.png echo -ne "Tomando Screenshot #${i} \r" done echo "Tomar Screenshots... [OK]" } # ====== first step is here! ;-) ======== # Checking options... while getopts ":t:n:r:h" option do case $option in t ) shot_time=$OPTARG; opt=_time;; n ) shots_number=$OPTARG; opt=_num;; h ) _help; opt=1; exit 1;; r ) res=$OPTARG;; : ) echo "No me has dado un argumento"; opt=1; exit 1;; * ) echo "Opcion Desconocida"; echo $usage; opt=1; exit 1;; esac done if [ "$res" == "" ]; then res=40%; fi if [ "$opt" == "" ]; then echo "No me has dado una opcion!"; echo $usage; exit 1; fi shift $(($OPTIND - 1)) if [ "$1" == "" ]; then echo "No me has dado un fichero!"; echo $usage; exit 1; fi mkdir /tmp/shots # Analizando Ficheros... while [ "$1" != "" ] do file_path=$1 file_name_ext=${file_path##*/} file_name=`echo "$file_name_ext" | sed '$s/....$//'` randomiser=0 movdir=`dirname "$file_path"` if [ "$movdir" == "." ]; then movdir=`pwd` file_path=$movdir/$file_path fi cd "$movdir" echo "Procesando el fichero $file_name..." # Obteniendo duracion del video... length=`mplayer -identify "$file_path" -frames 1 -ao null -vo null 2>/dev/null \ | grep LENGTH | sed -e 's/^.*=//' -e 's/[.].*//'` if [ "$length" == "" ]; then echo "Error! No se pudo obtener la duracion del video."; exit 1; fi if [ "$opt" == "_time" ]; then shots_number=`echo $[$length/60/$shot_time]` shot elif [ "$opt" == "_num" ]; then shot_time=`echo $[$length/$shots_number/60]` shot fi # Juntando todas las screenshots tomadas en una sola imagen... echo -n "Juntando Screenshots..." cd /tmp/shots/ montage -geometry +2+2 -compress jpeg `ls *.png | sort -n` "$file_name".jpg mogrify -resize $res "$file_name".jpg echo " [OK]" echo -n "Obteniendo informacion del video..." size=`stat -c%s "$file_path"` size=`echo $[$size/1024/1024]` format=`mplayer -frames 1 -ao null -vo null -identify 2>/dev/null "$file_path" | grep VIDEO: | cut -d " " -f 5` length=`echo $[$length/60]` # Es un codigo sucio, pero agrega información acerca del video a la imagen destino. echo -e "Fichero: $file_name_ext\nTamaño: $size Mb\nResolucion: $format\nDuracion: $length min." | convert -pointsize 16 -trim +repage text:- text.jpg convert "$file_name".jpg -splice 0x70 -draw 'image over 5,5 0,0 text.jpg' "$movdir/$file_name".jpg echo " [OK]"; echo cd "$movdir" shift done rm -r /tmp/shots echo "Listo!"