View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 1 post ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Wed Jun 06, 2007 4:29 pm 
Offline
Joined: Sat Mar 17, 2007 1:37 am
Posts: 32
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

_________________
os: knoppmyth r5e50
mobo: asus p5pe-vm
cpu: intel celeron 2.66 d
memory: 256mb ddr ram
video: asus geforce 6200 agp
tuner: hauppauge pvr 150 mce
disk: seagate 250gb sata


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu