#!/bin/sh
#written by Helmchyn
#to be distributed under the terms of the GPL v.2 and any later version
format=jpg
if [ -z "$1" ];then
dir="video/"
else
dir=$1
fi
echo "$dir" |grep '/$' || dir="$dir/"
idxdir=`echo ."$dir"_idx |sed 's/\///g' |sed 's/ /_/g'`
idxhtml=`echo $dir.html |sed 's/\///g'`
#echo Indexdir: $idxdir
if [ -d "$idxdir" ]; then
echo "indexdir already exists"
else
mkdir $idxdir
echo " indexdir has been created"
fi
#rm -f $idxdir/*.$format
rm -f "$idxhtml"
#echo Old index files have been removed
echo Stand by while creating new snapshots...
#Header of HTML file
echo "" >"$idxhtml"
echo "
$dir" >>"$idxhtml"
echo " " >>"$idxhtml"
echo " " >>"$idxhtml"
#generate 4 Snapshots of each movie and write them into HTML file
cnt=0
for cur in `ls -1 "$dir" |sed 's/ /%_%/g'`; do
cur=`echo $cur |sed 's/%_%/ /g'`
cnt=`expr $cnt + 1`
#get some Parameters for the encoding
length=`mplayer "$dir$cur" -identify -frames 0 -vo null 2>/dev/null |grep "ID_LENGTH=" |cut -d"=" -f2 |cut -d"." -f1`
seg=`expr $length / 5`
width=`mplayer "$dir$cur" -identify -frames 0 -vo null 2>/dev/null |grep "ID_VIDEO_WIDTH=" |cut -d"=" -f2 |cut -d"." -f1`
height=`mplayer "$dir$cur" -identify -frames 0 -vo null 2>/dev/null |grep "ID_VIDEO_HEIGHT=" |cut -d"=" -f2 |cut -d"." -f1`
width=`expr $width / \( $height / 75 \) 2>/dev/null ||echo 100`
height=75
if [ -n "$width" ]; then
if [ $width -gt 100 ]; then
height=`expr $height / \( $width / 100 \)`
width=100
fi
fi
#produce the Frames
scnt=1
while [ $scnt -lt 5 ]; do
mplayer "$dir$cur" -ss `expr $scnt \* $seg` -frames 3 -vf scale=$width:$height -ao null -vo jpeg >>/dev/null 2>>/dev/null
if [ -f 00000002.$format ];then
cp -f 00000002.$format "$idxdir/$cur-$scnt.$format" 2>/dev/null ||echo -n .
else
cp -f 00000001.$format "$idxdir/$cur-$scnt.$format" 2>/dev/null ||echo -n .
fi
scnt=`expr $scnt + 1`
done
rm -f 0000000?.$format
#insert linebreaks for movie titles
line=`echo $cur |sed 's/.\{20\}/&
/g'`
#Part of the HTML file
if [ `expr $cnt % 4` -eq 1 ]; then
echo -e " " >>"$idxhtml"
echo -e " " >>"$idxhtml"
fi
echo -e " " >>"$idxhtml"
echo -e " " >>"$idxhtml"
for fcnt in `seq 1 4`; do
echo -e " | " >>"$idxhtml"
echo -e " " >>"$idxhtml"
echo -e " | " >>"$idxhtml"
if [ $fcnt -eq 2 ]; then
echo -e " " >>"$idxhtml"
echo -e " " >>"$idxhtml"
fi
done
echo -e " " >>"$idxhtml"
echo -e " " >>"$idxhtml"
echo -e " " >>"$idxhtml"
echo -e " | " >>"$idxhtml"
if [ `expr $cnt % 4` -eq 0 ]; then
echo -e "
" >>"$idxhtml"
else
echo -e " " >>"$idxhtml"
fi
done
#Tail of the HTML file
if [ `expr $cnt % 4` -ne 0 ]; then
echo -e " | " >>"$idxhtml"
echo -e " " >>"$idxhtml"
fi
echo "
" >>"$idxhtml"
echo " " >>"$idxhtml"
echo "" >>"$idxhtml"
echo done