Advertisement
bonelifer

Untitled

Oct 10th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # First does a lossless MPEG-2 transcode removing commericals(cutlist must be manually made before
  4. # hand), then Transcodes using a second trancode profile to MPEG-4(XVID). It then updates the DB
  5. # for the new filesize incase you want to keep it in the recorded group and copies the file to a
  6. # new location for those that want to transfer the recording out for a mediacenter like XBMC.
  7. #
  8. # Based on mythtv-transcode-h264 version 0.8 by Defcronyke Webmaster.
  9. #
  10.  
  11. # Arguments
  12. # $1 must be the directory/file to be transcoded.
  13. # $2 must be the output directory / file name. The directory must be writeable by the mythtv user
  14. # $3 must be chanid
  15. # $4 must be starttime
  16. # the full userjob command in mythtv-setup should look like this:
  17. #
  18. # /usr/bin/mythtv-transcode-mkv.sh "%DIR%/%FILE%" "/media/Store/incoming/TV/%TITLE% - S%SEASON%E%EPISODE% - %SUBTITLE%.mkv" "%CHANID%" "%STARTTIMEUTC%"
  19. #
  20. # /usr/bin/mythtv-transcode-mkv.sh "%DIR%/%FILE%" "/media/Store/incoming/Movies/%TITLE%.mkv" "%CHANID%" "%STARTTIMEUTC%"
  21. #
  22. #
  23. # Create the temp directory used by this script:
  24. # cd /var/tmp
  25. # mkdir mythtv-tmp
  26. #
  27. # Set permissions on the temp directory used by this script:
  28. # sudo chown -Rf mythtv:mythtv /var/tmp/mythtv-tmp/
  29. # sudo chmod -Rf 0777 /var/tmp/mythtv-tmp/
  30. #
  31. # Create Transcoder profile named HDHR (or something else, remember to adjust
  32. # the mythtranscode line below the "Start transcoding to MPEG-4(XVID)" comment
  33. #
  34. #
  35.  
  36. # a temporary working directory (must be writable by mythtv user)
  37. TEMPDIR="/var/tmp/mythtv-tmp"
  38.  
  39.  
  40.  
  41. # MythTV Install Prefix (make sure this matches with the directory where MythTV is installed)
  42. INSTALLPREFIX="/usr/bin"
  43.  
  44. # don't change these
  45. MYPID=$$
  46. DIRNAME=`dirname "$2"`
  47. DIRNAME2=`dirname "$1"`
  48. BASENAME=`echo "$2" | awk -F/ '{print $NF}' | sed 's/ /_/g' | sed 's/://g' | sed 's/?//g' | sed s/"'"/""/g`
  49. BASENAME2=`echo "$1" | awk -F/ '{print $NF}'`
  50.  
  51. # MySQL database login information (for mythconverg database)
  52. DATABASEUSER="mythtv"
  53. DATABASEPASSWORD="password"
  54.  
  55. # play nice with other processes
  56. renice 19 $MYPID
  57. ionice -c 3 -p $MYPID
  58.  
  59. # make working dir, go inside
  60. mkdir $TEMPDIR/mythtmp-$MYPID
  61. cd $TEMPDIR/mythtmp-$MYPID
  62.  
  63. # remove commercials and do lossless MPEG-2 transcode
  64. $INSTALLPREFIX/mythutil --chanid "$3" --starttime "$4" --gencutlist
  65. $INSTALLPREFIX/mythtranscode --chanid "$3" --starttime "$4" --mpeg2 --honorcutlist
  66.  
  67. # fix seeking and bookmarking by removing stale db info
  68. echo "DELETE FROM recordedseek WHERE chanid='$3' AND starttime='$4';" > update-database_$MYPID.sql
  69. mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database_$MYPID.sql
  70. echo "DELETE FROM recordedmarkup WHERE chanid='$3' AND starttime='$4';" > update-database_$MYPID.sql
  71. mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database_$MYPID.sql
  72.  
  73. # Lets do the Sleep cycle here:
  74. # Give the first transcoder enough time to finalize and free the recording for further processing
  75. sleep 10s
  76.  
  77. # Move original file to $1.done, mv temp(lossless commercial cut) file from $1.tmp to $1
  78. mv $DIRNAME2/$BASENAME2 $DIRNAME2/$BASENAME2.done
  79. mv $DIRNAME2/$BASENAME2.tmp $DIRNAME2/$BASENAME2
  80.  
  81. # Lets do the Sleep cycle here:
  82. # Give the system enough time to let go of any of the files that were moved.
  83. sleep 10s
  84.  
  85. # Start transcoding to MPEG-4(XVID)
  86. $INSTALLPREFIX/mythtranscode --chanid "$3" --starttime "$4" --profile HDHR
  87.  
  88. # Lets do the Sleep cycle here:
  89. # Give the second transcoder enough time to finalize and free the recording for further processing
  90. sleep 10s
  91.  
  92. # Copy the now transcoded(MPEG-4--XVID) file to it's new destination with it's new name.
  93. # Comment this out if you don't want to copy it to a new directory for
  94. # a mediaceneter like XBMC.
  95. cp $DIRNAME2/$BASENAME2.tmp $DIRNAME/$BASENAME
  96.  
  97. # Lets do the Sleep cycle here:
  98. # Give the filesystem enough time after moving files to release them
  99. sleep 10s
  100.  
  101. # Remove MPEG-2 lossless transcoded file and replace with MPEG-4(XVID) with MKV extension
  102. rm $DIRNAME2/$BASENAME2
  103. mv $DIRNAME2/$BASENAME2.tmp $DIRNAME2/$BASENAME
  104.  
  105. # Lets do the Sleep cycle here:
  106. # Give the filesystem enough time after moving files to release them
  107. sleep 10s
  108.  
  109. # update the database to point to the transcoded file(original not the one copied), incase it wasn't
  110. # able to finish the copy process
  111. NEWFILESIZE=`du -b "$DIRNAME2/$BASENAME" | cut -f1`
  112. echo "UPDATE recorded SET basename='$BASENAME',filesize='$NEWFILESIZE',transcoded='1' WHERE chanid='$3' AND starttime='$4';" > update-database_$MYPID.sql
  113. mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < update-database_$MYPID.sql
  114.  
  115. # Delete preview images of original non-transcoded video
  116. rm $1.-1.320x180.png
  117. rm $1.-1.320x240.png
  118. rm $1.-1.160x120.png
  119. rm $1.-1.100x75.png
  120. rm $1.png
  121.  
  122. # Command to do all the above no matter what the produced width-height of the source video was
  123. #find . -name '$1*.png' -print0 | xargs -0 rm
  124.  
  125. # comment out the below line to keep original uncut recording
  126. rm $DIRNAME2/$BASENAME2.done
  127.  
  128. # cleanup temp files
  129. cd ..
  130. rm -rf mythtmp-$MYPID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement