Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # First does a lossless MPEG-2 transcode removing commericals(cutlist must be manually made before
- # hand), then Transcodes using a second trancode profile to MPEG-4(XVID). It then updates the DB
- # for the new filesize incase you want to keep it in the recorded group and copies the file to a
- # new location for those that want to transfer the recording out for a mediacenter like XBMC.
- #
- # Based on mythtv-transcode-h264 version 0.8 by Defcronyke Webmaster.
- #
- # Arguments
- # $1 must be the directory/file to be transcoded.
- # $2 must be the output directory / file name. The directory must be writeable by the mythtv user
- # $3 must be chanid
- # $4 must be starttime
- # the full userjob command in mythtv-setup should look like this:
- #
- # /usr/bin/mythtv-transcode-mkv.sh "%DIR%/%FILE%" "/media/Store/incoming/TV/%TITLE% - S%SEASON%E%EPISODE% - %SUBTITLE%.mkv" "%CHANID%" "%STARTTIMEUTC%"
- #
- # /usr/bin/mythtv-transcode-mkv.sh "%DIR%/%FILE%" "/media/Store/incoming/Movies/%TITLE%.mkv" "%CHANID%" "%STARTTIMEUTC%"
- #
- #
- # Create the temp directory used by this script:
- # cd /var/tmp
- # mkdir mythtv-tmp
- #
- # Set permissions on the temp directory used by this script:
- # sudo chown -Rf mythtv:mythtv /var/tmp/mythtv-tmp/
- # sudo chmod -Rf 0777 /var/tmp/mythtv-tmp/
- #
- # Create Transcoder profile named HDHR (or something else, remember to adjust
- # the mythtranscode line below the "Start transcoding to MPEG-4(XVID)" comment
- #
- #
- # a temporary working directory (must be writable by mythtv user)
- TEMPDIR="/var/tmp/mythtv-tmp"
- # MythTV Install Prefix (make sure this matches with the directory where MythTV is installed)
- INSTALLPREFIX="/usr/bin"
- # don't change these
- MYPID=$$
- DIRNAME=`dirname "$2"`
- DIRNAME2=`dirname "$1"`
- BASENAME=`echo "$2" | awk -F/ '{print $NF}' | sed 's/ /_/g' | sed 's/://g' | sed 's/?//g' | sed s/"'"/""/g`
- BASENAME2=`echo "$1" | awk -F/ '{print $NF}'`
- # MySQL database login information (for mythconverg database)
- DATABASEUSER="mythtv"
- DATABASEPASSWORD="password"
- # play nice with other processes
- renice 19 $MYPID
- ionice -c 3 -p $MYPID
- # make working dir, go inside
- mkdir $TEMPDIR/mythtmp-$MYPID
- cd $TEMPDIR/mythtmp-$MYPID
- # remove commercials and do lossless MPEG-2 transcode
- $INSTALLPREFIX/mythutil --chanid "$3" --starttime "$4" --gencutlist
- $INSTALLPREFIX/mythtranscode --chanid "$3" --starttime "$4" --mpeg2 --honorcutlist
- # fix seeking and bookmarking by removing stale db info
- echo "DELETE FROM recordedseek WHERE chanid='$3' AND starttime='$4';" > update-database_$MYPID.sql
- mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database_$MYPID.sql
- echo "DELETE FROM recordedmarkup WHERE chanid='$3' AND starttime='$4';" > update-database_$MYPID.sql
- mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database_$MYPID.sql
- # Lets do the Sleep cycle here:
- # Give the first transcoder enough time to finalize and free the recording for further processing
- sleep 10s
- # Move original file to $1.done, mv temp(lossless commercial cut) file from $1.tmp to $1
- mv $DIRNAME2/$BASENAME2 $DIRNAME2/$BASENAME2.done
- mv $DIRNAME2/$BASENAME2.tmp $DIRNAME2/$BASENAME2
- # Lets do the Sleep cycle here:
- # Give the system enough time to let go of any of the files that were moved.
- sleep 10s
- # Start transcoding to MPEG-4(XVID)
- $INSTALLPREFIX/mythtranscode --chanid "$3" --starttime "$4" --profile HDHR
- # Lets do the Sleep cycle here:
- # Give the second transcoder enough time to finalize and free the recording for further processing
- sleep 10s
- # Copy the now transcoded(MPEG-4--XVID) file to it's new destination with it's new name.
- # Comment this out if you don't want to copy it to a new directory for
- # a mediaceneter like XBMC.
- cp $DIRNAME2/$BASENAME2.tmp $DIRNAME/$BASENAME
- # Lets do the Sleep cycle here:
- # Give the filesystem enough time after moving files to release them
- sleep 10s
- # Remove MPEG-2 lossless transcoded file and replace with MPEG-4(XVID) with MKV extension
- rm $DIRNAME2/$BASENAME2
- mv $DIRNAME2/$BASENAME2.tmp $DIRNAME2/$BASENAME
- # Lets do the Sleep cycle here:
- # Give the filesystem enough time after moving files to release them
- sleep 10s
- # update the database to point to the transcoded file(original not the one copied), incase it wasn't
- # able to finish the copy process
- NEWFILESIZE=`du -b "$DIRNAME2/$BASENAME" | cut -f1`
- echo "UPDATE recorded SET basename='$BASENAME',filesize='$NEWFILESIZE',transcoded='1' WHERE chanid='$3' AND starttime='$4';" > update-database_$MYPID.sql
- mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database_$MYPID.sql
- # Delete preview images of original non-transcoded video
- rm $1.-1.320x180.png
- rm $1.-1.320x240.png
- rm $1.-1.160x120.png
- rm $1.-1.100x75.png
- rm $1.png
- # Command to do all the above no matter what the produced width-height of the source video was
- #find . -name '$1*.png' -print0 | xargs -0 rm
- # comment out the below line to keep original uncut recording
- rm $DIRNAME2/$BASENAME2.done
- # cleanup temp files
- cd ..
- rm -rf mythtmp-$MYPID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement