#!/bin/bash
#
# video2pics4all - Create thumb_ and normal_ pics from all videos of a certain type in the current directory
# for use with Coppermine.
#
# Requirements: ffmpeg and imagicmagick must be installed.
#
# Place this file in a directory that is in your $PATH to executables such as /usr/local/bin
# Then, chmod a+x video2pic
#
#
# Run this script from within the directory where the videos reside with the command: "video2pics4all".
#
#
# File name and location for button image to overlay
overlay="/home/gordon/scripts/video2ools/playbutton.gif";
# File size for normal_ images
normalsize=640;
# File size for thumb_ images
thumbsize=109;
# Get data from terminal
echo -n "Enter video file type (flv, wmv. mov...): ";read filetype;
echo -n "Enter video time elapse (seconds): ";read timedelay;
#
for file in *.$filetype;do
	# Extract filename without extension
	filename=${file:0:(${#file})-4};
	echo;echo;echo Creating normal_$filename.jpg and thumb_$filename.jpg;echo;
	#
	# Extract screen shot from video, overlay the button and reduce the image to a thumbnail
	ffmpeg -i $file -an -ss 00:00:0$timedelay -r 1 -vframes 1 -y normal_$filename.jpg;
	# Convert to normalsize for normal_ images
	convert -resize $normalsize normal_$filename.jpg normal_$filename.jpg;
	#  Overlay the button onto the normal_ image
	composite -gravity northwest $overlay normal_$filename.jpg thumb_$filename.jpg;
	# convert the thumb_ image to thumbsize
	convert -resize $thumbsize thumb_$filename.jpg thumb_$filename.jpg;
done
echo;
echo "Complete!...";
