View difference between Paste ID: 2iVWDEkx and x96WYVTx
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
# videothumbs, a simple videothumbnailer
3
#
4
#  Copyright (C) 2012 Julian Hughes julianhughes<at>gmailDOTcom
5
#
6
#  This program is free software; you can redistribute it and/or modify
7
#  it under the terms of the GNU General Public License as published by
8
#  the Free Software Foundation; either version 3 of the License, or
9
#  (at your option) any later version.
10
#
11
#  This program is distributed in the hope that it will be useful,
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
#  GNU General Public License for more details.
15
#
16
#  You should have received a copy of the GNU General Public License
17
#  along with this program.  If not, see <http://www.gnu.org/licenses/>
18
19-
# REQUIRES: mplayer, ffmpeg, imagemagick
19+
20
type montage >/dev/null 2>&1 || { echo >&2 "ImageMagick is not \
21
installed or is not in your path."; exit 1; }
22
type mplayer >/dev/null 2>&1 || { echo >&2 "mplayer is not installed \
23
or is not in your path."; exit 1; }
24
type ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg is not installed \
25
or is not in your path."; exit 1; }
26
27
#user options
28
while getopts 'o:' OPTION
29
do
30
	case $OPTION in
31
	o)	oflag=1
32
		oval=$OPTARG
33
		;;
34
	esac
35
done
36
shift $(($OPTIND-1))
37
38
function ffscreens ()
39
{
40-
function mpscreens ()
40+
41
-vframes 1  -vf scale="$WIDE":"$H" "$OUT"/$(printf "%02d\n" "$t").png
42-
mplayer "$i" -noconfig all -nolirc -nojoystick -nosound -ss 5 \
42+
43-
-sstep $STEP -vf scale=$WIDE:-2 -vo png:outdir=$OUT
43+
44
45
for i in "$@" ;do
46
47
FILE="${i%.*}"
48
FILE="${FILE##*/}"
49
EXT="${i##*\.}"
50
OUT=/tmp/thumbs
51
INFO="$OUT"/info
52
53
mkdir -p "$OUT"
54
55
#set output destination. Output dir exists and writable?
56
#defaults to movie directory.
57
if [ $oflag ]; then
58
	if [ ! -d "$oval" -o ! -w "$oval" ]; then
59
	printf "\n\n\tOutput directory is not writable or doesn't exist\n\n"
60-
mkdir "$OUT"
60+
61
	fi
62
	IMGOUT=$oval/"${FILE##*/}".jpg
63
	else
64
	IMGOUT="${i%.*}".jpg
65
fi
66
67
#dump movie info to text file
68
mplayer "$i" -noconfig all -identify -vo null -ao null \
69
-frames 0 2>/dev/null |grep -E -e AUDIO -e "VIDEO|LENGTH" |\
70
awk -F "ID_" '{print $2}'|sort -u |sed '/^$/d' >"$INFO"
71
72
#for 4x10 images find movie length, divide by 40 for interval steps.
73
LENGTH=$(grep LENGTH= "$INFO"|awk -F = '{print $2}')
74-
#use mplayer based capture for mkv/mpg, ffmpeg for everything else
74+
75-
#because mplayer chokes if there is no keyframe at -ss # in avi & on 
75+
76-
# seeking some mp4.
76+
77-
if [[ $EXT == !(mkv|MKV|mpg|MPG|mpeg|MPEG) ]] ; then
77+
78-
	SCREENS=ffscreens
78+
79
H=$(grep VIDEO_HEIGHT= "$INFO" |awk -F = '{print $2}')
80-
	SCREENS=mpscreens
80+
81
WIDE=$(printf "%.0f\n" $WIDE)
82
83
#get basic codec and dimension info for printing title.
84-
mplayer "$i" -noconfig all -identify -novideo -vo null -ao null \
84+
85-
-frames 0 2>/dev/null |grep AUDIO |awk -F "ID_" '{print $2}'|sort -u |\
85+
86-
sed '/^$/d' >"$INFO" && \
86+
87-
mplayer "$i" -noconfig all -identify -nosound -vo null -ao null \
87+
88-
-frames 0 2>/dev/null |egrep "VIDEO|LENGTH" |awk -F "ID_" '{print $2}'|\
88+
89-
sort -u |sed '/^$/d' >>"$INFO"
89+
90
91
#dump uncompressed png images to temp dir while redirecting overly
92
#verbose ffmpeg output to /dev/null
93
ffscreens>/dev/null 2>&1
94
95
#make montage, clean up, quit.
96
montage -mode concatenate -geometry 252x -border 1 -tile 4x \
97
"$OUT"/*.png -title "$TITLE" "$IMGOUT" && \
98
rm -rf "$OUT"
99
100
done
101
exit 0