MythTV Roku Commercial Skip Encode Script

Before I forget, here’s my MythTV UserJob1:
/usr/local/bin/mythipodcom.sh %DIR% %FILE%

This script runs on a MythTV recording to remove commercials and transcode to h.264 video that I’ve tested and will play on Android (Motorola Droid), iPhone (iPhone 4), Roku DVP (Original Roku Netflix Player), Boxee Box, and in Miro on Windows.

The contents of
/usr/local/bin/mythipodcom.sh

[bash]
#!/bin/bash

VIDEODIR=$1
FILENAME=$2

# remove the output file if it already exists
if [ -f "$VIDEODIR/$FILENAME.mp4" ]; then
rm -f $VIDEODIR/$FILENAME.mp4
fi

# make sure there is videodir and filename entered and it exists
if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
echo "Usage: $0 <VideoVIDEODIR> <FileName>"
exit 5
fi
if [ ! -f "$VIDEODIR/$FILENAME" ]; then
echo "File does not exist: $VIDEODIR/$FILENAME"
exit 6
fi

# Flag commercials, generate cutlist, copy cutlist, transcode, clear cutlist

/usr/bin/nice -n 19 mythcommflag –gencutlist -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "Copying cutlist failed for ${FILENAME} with error $ERROR"
exit $ERROR
else
echo "Copying cutlist successful for ${FILENAME}."
fi

CUTLIST=$(mythcommflag –getcutlist -f $VIDEODIR/$FILENAME | tail -n 1 | awk ‘{print $2}’ | sed ‘s/,/ /g’)
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "Copying cutlist failed for ${FILENAME} with error $ERROR"
exit $ERROR
fi

/usr/bin/nice -n 19 mythtranscode –mpeg2 -i $VIDEODIR/$FILENAME –honorcutlist "$CUTLIST" -o $VIDEODIR/$FILENAME.tmp

ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "Transcoding failed for ${FILENAME} with error $ERROR"
exit $ERROR
fi

mythcommflag –clearcutlist -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "Clearing cutlist failed for ${FILENAME} with error $ERROR"
rm /usr/video/$FILENAME.tmp
exit $ERROR
fi

# Create the MP4

/usr/bin/nice -n 19 ffmpeg -i "${VIDEODIR}/${FILENAME}.tmp" -s 640×480 -deinterlace -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -me_method umh -subq 8 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 2 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 4 -refs 4 -directpred 3 -trellis 1 -flags2 +wpred+mixed_refs+dct8x8+fastpskip -acodec libfaac -ac 2 -ar 48000 -ab 96k -metadata title="${FILENAME}" "${VIDEODIR}/${FILENAME}.mp4" >> "/tmp/${FILENAME}.log" 2>&1

/usr/bin/MP4Box -tmp "${VIDEODIR}" -inter 500 "${VIDEODIR}/${FILENAME}.mp4"

# Create Roku BIF thumbnail file
/usr/bin/perl /usr/local/bin/bifencode.pl ${VIDEODIR} ${FILENAME}.tmp
mv "/tmp/${FILENAME}.tmp.bif" "/tmp/${FILENAME}.bif"
mv "/tmp/${FILENAME}.bif" /var/www/stream/biffile/

# remove the temporary file

rm -f "${VIDEODIR}/${FILENAME}.tmp"
rm -f "${VIDEODIR}/${FILENAME}.tmp.map"

mv "${VIDEODIR}/${FILENAME}.mp4" /var/www/stream/
cp "${VIDEODIR}/${FILENAME}.png" /var/www/stream/

/usr/bin/perl /usr/local/bin/mythexpire.pl
/usr/bin/perl /usr/local/bin/feed.pl
/usr/bin/perl /usr/local/bin/itunesfeed.pl

[/bash]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: