<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>
i've taken this scripts written by segaera and consolidated everything into one script. also, this script will run the query to get the videos to update only once, whereas segaera's is running once for each video. furthermore, this script takes the length of the video into account when skipping ahead for the screenshot position. a percentage is used instead of a fixed value to get a good capture in videos of widely varying lengths. here it is:<br><br>#!/bin/sh<br><br># this script will loop through all videos in videometadata,<br># capture a screenshot for each, move each screenshot to the<br># COVERPATH dir, and update each row in videometadata with<br># the appropriate information. Only rows with coverfile=<br># 'No Cover' are processed. A percentage of the length<br># of each video is used for the capture position to account<br># for clips of widely varying lengths.<br><br># only run as mythtv so writing to /myth is allowed<br>if [ $(whoami) != 'mythtv' ]; then<br> echo "This script must run under user mythtv."<br> exit 1<br>fi<br><br># intialize variables<br>DB='mythconverg'<br>USER='root'<br>OUTPATH='/tmp'<br>COVERPATH='/myth/video/.covers'<br>FRAME='00000002.jpg'<br>SKIPOFFSET='35'<br><br># query videos with no cover image<br>VIDEOS="mysql $DB -u $USER \<br> -e \"SELECT intid,filename FROM videometadata \<br> WHERE coverfile='No Cover';\" -BN" <br><br>sh -c "$VIDEOS"|while read line<br>#echo "$FILE"|while read line<br>do<br><br> ID=`echo "$line" |cut -f 1`<br> FILE=`echo "$line" |cut -f 2`<br><br> echo "processing $FILE with primary key id $ID"<br><br> # if video is mpeg, use ffmpeg12 codec to avoid pixelation<br> if echo "$FILE" | egrep ".*\.mp[e]*g" ; then<br> VC='-vc ffmpeg12'<br> else<br> VC=''<br> fi<br><br> # use mplayer to get length of video in seconds<br> length=`mplayer -vo null -nosound -identify \<br> -vc dummy "$FILE" | \<br> egrep "^(ID_LENGTH=)" | cut -d '=' -f 2`<br> <br> if [ -z $length ]; then<br> echo "mplayer was unable to get the $FILE length."<br> continue<br> fi<br><br> SKIP=`echo $length*$SKIPOFFSET/100|bc -l`<br> echo "calcuated skip seconds: $SKIP"<br><br> # command to get jpeg from video<br> mplayer -noframedrop -ss $SKIP -vo \<br> jpeg:quality=50:outdir=$OUTPATH -frames 2 $VC -nosound "$FILE" &<br><br> wait<br><br> echo mv $OUTPATH/$FRAME $COVERPATH/intid.$ID.jpg <br><br> # move jpeg from outpath to coverpath<br> if ! mv -f "$OUTPATH/$FRAME" "$COVERPATH/intid.$ID.jpg" ; then<br> echo "Move failed. Will not update videometadata table..."<br> rm -f "$OUTPATH/$FRAME"<br><br> else<br> # SQL to update table with cover image path<br> UPDATE=`mysql $DB -u $USER \<br> -e "UPDATE videometadata SET coverfile='$COVERPATH/intid.$ID.jpg' \<br> WHERE intid=$ID LIMIT 1 ;" -BN`<br><br> fi<br><br>done<br> <br><br><br>exit 0<br><br></body>
</html>