LinHES Forums
http://forum.linhes.org/

mythvideo thumbnails script
http://forum.linhes.org/viewtopic.php?f=17&t=15534
Page 1 of 1

Author:  imstr8trippin [ Wed Jun 06, 2007 4:29 pm ]
Post subject:  mythvideo thumbnails script

i've taken the scripts written by segaera (http://www.gossamer-threads.com/lists/mythtv/users/182848?search_string=mythvideo%20thumbnails;#182848) 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:

Code:

#!/bin/sh

# this script will loop through all videos in videometadata,
# capture a screenshot for each, move each screenshot to the
# COVERPATH dir, and update each row in videometadata with
# the appropriate information.  Only rows with coverfile=
# 'No Cover' are processed.  A percentage of the length
# of each video is used for the capture position to account
# for clips of widely varying lengths.

# only run as mythtv so writing to /myth is allowed
if [ $(whoami) != 'mythtv' ]; then
        echo "This script must run under user mythtv."
        exit 1
fi

# intialize variables
DB='mythconverg'
USER='root'
OUTPATH='/tmp'
COVERPATH='/myth/video/.covers'
FRAME='00000002.jpg'
SKIPOFFSET='35'

# query videos with no cover image
VIDEOS="mysql $DB -u $USER \
        -e \"SELECT intid,filename FROM videometadata \
        WHERE coverfile='No Cover';\" -BN"

sh -c "$VIDEOS"|while read line
#echo "$FILE"|while read line
do

        ID=`echo "$line" |cut -f 1`
        FILE=`echo "$line" |cut -f 2`

        echo "processing $FILE with primary key id $ID"

        # if video is mpeg, use ffmpeg12 codec to avoid pixelation
        if echo "$FILE" | egrep ".*\.mp[e]*g" ; then
                VC='-vc ffmpeg12'
        else
                VC=''
        fi

        # use mplayer to get length of video in seconds
        length=`mplayer -vo null -nosound -identify \
                -vc dummy "$FILE" | \
                egrep "^(ID_LENGTH=)" | cut -d '=' -f 2`
 
        if [ -z $length ]; then
                echo "mplayer was unable to get the $FILE length."
                continue
        fi

        SKIP=`echo $length*$SKIPOFFSET/100|bc -l`
        echo "calcuated skip seconds: $SKIP"

        # command to get jpeg from video
        mplayer -noframedrop -ss $SKIP -vo \
                jpeg:quality=50:outdir=$OUTPATH -frames 2 $VC -nosound "$FILE" &

        wait

        echo mv $OUTPATH/$FRAME $COVERPATH/intid.$ID.jpg

        # move jpeg from outpath to coverpath
        if ! mv -f "$OUTPATH/$FRAME" "$COVERPATH/intid.$ID.jpg" ; then
                echo "Move failed. Will not update videometadata table..."
                rm -f "$OUTPATH/$FRAME"

        else
                # SQL to update table with cover image path
                UPDATE=`mysql $DB -u $USER \
                        -e "UPDATE videometadata SET coverfile='$COVERPATH/intid.$ID.jpg' \
                        WHERE intid=$ID LIMIT 1 ;" -BN`

        fi

done
 


exit 0

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/