Here is a couple of scripts I have to remove commercials and export to avi as user jobs, they shouldn't be too hard to combine and modify for your purpose
Code:
#!/bin/bash
VIDEOIN=$1
FILENAME=$2
QUERY=/tmp/$FILENAME.sql
# Check to see if there is a cutlist
echo "select cutlist from recorded WHERE basename = '$FILENAME'" > $QUERY
CUTLISTEXIST=$(mysql -u mythtv -pmythtv -h mb01 mythconverg < $QUERY |grep -e 1 -e 0)
# If no cutlist exist exit,
if [ $CUTLISTEXIST = 0 ]
then
echo "No Cutlist" >> /var/log/mythtv/mythbackend.log
else
# Exporting video minus the data in the cutlist
CUTLIST=$(mythcommflag --getcutlist -f $VIDEOIN | tail -n 1 | awk '{print $2}' | sed 's/,/ /g')
if [ $? -ne 0 ]; then
echo "Copying cutlist failed for ${FILENAME} ($VIDEOIN) with error $?"
exit $?
fi
mythtranscode -m -i $VIDEOIN --honorcutlist "$CUTLIST" --showprogress -o "$VIDEOIN.tmp"
if [ $? -ne 0 ]; then
echo "Transcoding failed for ($VIDEOIN) with error $?"
exit $?
fi
rm -f "$VIDEOIN"
rm -f "$VIDEOIN.tmp.map"
mv "$VIDEOIN.tmp" "$VIDEOIN"
mythcommflag -f $VIDEOIN --rebuild
# Removing the cutlist from recording (but leaving commercial flags)
mythcommflag --clearcutlist -f $VIDEOIN
ERROR=$?
if [ $ERROR -eq 0 ]; then
# Fix the database entry for the file
echo "UPDATE recorded SET cutlist = 0, commflagged = 0, filesize = $(ls -l $VIDEOIN | awk '{print $5}') WHERE basename = '$FILENAME';" > $Q$
mysql mythconverg -h mb01 -u mythtv -pmythtv < $QUERY
fi
fi
rm -f $QUERY
Code:
#!/bin/bash
VIDEOIN=$1
FILENAME=$2
# Variable used to get name of file on filesystem
FSNAME=$3 #$(echo $VIDEOIN |gawk -F'/' '{ print $4 }')
# Check to see if there is a cutlist
echo "select cutlist from recorded WHERE basename = '$FSNAME'" > /tmp/query
CUTLISTEXIST=$(mysql -u mythtv -pmythtv -h mb01 mythconverg </tmp/query |grep -e 1 -e 0)
echo "$VIDEOIN ---- $FILENAME ---- $FSNAME ---- $CUTLISTEXIST" > /tmp/variables1
OUTDIR="/myth/video/videos"
# Sanity checking, to make sure everything is in order.
if [ -z "$VIDEOIN" -o -z "$FILENAME.avi" ]; then
echo "Usage: $0 <PathToVideoFileName> <OutFile> <OutDirectory>"
exit 5
fi
if [ ! -f "$VIDEOIN" ]; then
echo "File does not exist: $VIDEOIN" >> /tmp/exportlog 2>&1
exit 6
fi
# If no culist exist, export to avi directly else cut out commercials then export
if [ $CUTLISTEXIST = 0 ]
then
ffmpeg -i "$VIDEOIN" -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec libmp3lame -ab 128k "$OUTDIR/$FILENAME.avi" -deinterlace
else
# Exporting video minus the data in the cutlist
CUTLIST=$(mythcommflag --getcutlist -f $VIDEOIN | tail -n 1 | awk '{print $2}' | sed 's/,/ /g')
if [ $? -ne 0 ]; then
echo "Copying cutlist failed for ${FILENAME} ($VIDEOIN) with error $?" >> /tmp/exportlog 2>&1
exit $?
fi
mythtranscode -m -i $VIDEOIN --honorcutlist "$CUTLIST" --showprogress -o "$OUTDIR/$FILENAME.tmp" >> /tmp/exportlog 2>&1
if [ $? -ne 0 ]; then
echo "Transcoding failed for ${FILENAME} ($VIDEOIN) with error $?" >> /tmp/exportlog 2>&1
exit $?
fi
# Now we'll convert the new temp file to avi using ffmpeg
ffmpeg -i "$OUTDIR/$FILENAME.tmp" -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec libmp3lame -ab 128k "$OUTDIR/$FILENAME.avi" -deinterlace >> /tmp$
if [ $? -ne 0 ]; then
echo "Could not covert file to avi. Aborted with error $?" >> /tmp/exportlog 2>&1
fi
# Now, regardless of an ffmpeg error we'll remove the interim files
rm -f "$OUTDIR/$FILENAME.tmp" "$OUTDIR/$FILENAME.tmp.map" >> /tmp/exportlog 2>&1
fi