Created
December 9, 2011 00:36
-
-
Save kd7lxl/1449482 to your computer and use it in GitHub Desktop.
MythTV transcode with x264
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
# Adapted from a script at http://eternalvoid.net/tutorials/mythtv-autotranscode/ | |
# 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: /path/to/this-script/mythtv-transcode-h264.sh "%DIR%/%FILE%" "%DIR%/%TITLE% - %PROGSTART%.mkv" "%CHANID%" "%STARTTIME%" | |
# a temporary working directory (must be writable by mythtv user) | |
TEMPDIR="/tmp" | |
# MySQL database login information (for mythconverg database) | |
DATABASEUSER="mythtv" | |
DATABASEPASSWORD="" | |
# MythTV Install Prefix (make sure this matches with the directory where MythTV is installed) | |
INSTALLPREFIX="/usr/bin" | |
DIRNAME=`dirname "$2"` | |
BASENAME=`echo "$2" | awk -F/ '{print $NF}' | sed 's/ /_/g' | sed 's/://g' | sed 's/?//g'` | |
BASENAME2=`echo "$1" | awk -F/ '{print $NF}'` | |
# go to correct working dir | |
cd $TEMPDIR | |
# lossless mpeg2-mpeg2 transcode | |
$INSTALLPREFIX/mythtranscode --chanid "$3" --starttime "$4" --mpeg2 | |
echo "DELETE FROM recordedseek WHERE chanid='$3' AND starttime='$4';" > update-database.sql | |
mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database.sql | |
echo "DELETE FROM recordedmarkup WHERE chanid='$3' AND starttime='$4';" > update-database.sql | |
mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database.sql | |
echo "UPDATE recorded SET basename='$BASENAME2.tmp' WHERE chanid='$3' AND starttime='$4';" > update-database.sql | |
mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database.sql | |
X264OPTS="crf=20:me=umh:bframes=5:ref=9" | |
ffmpeg -y -deinterlace -i "$1.tmp" -acodec copy -vf scale='-1:720:interl=1' -vcodec libx264 -x264opts $X264OPTS "$DIRNAME/$BASENAME" | |
# flag commercials | |
mythcommflag -c "$3" -s "$4" | |
# update the database to point to the transcoded file and delete the original recorded show. | |
NEWFILESIZE=`du -b "$DIRNAME/$BASENAME" | cut -f1` | |
echo "UPDATE recorded SET basename='$BASENAME',filesize='$NEWFILESIZE',transcoded='1' WHERE chanid='$3' AND starttime='$4';" > update-database.sql | |
mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database.sql | |
# cleanup temp files | |
rm -f \ | |
x264_2pass.log* \ | |
update-database.sql \ | |
"$1" \ | |
"$1.tmp" \ | |
"$1*.png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment