Welcome to Monopedilos
Wednesday, September 08 2010 @ 07:43 AM CDT
This shows you the differences between two versions of the page.
| — |
lossycutter [2010/02/23 16:45] (current) theophile created |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== HD-PVR Cutter ====== | ||
| + | ===== Intro ===== | ||
| + | The Hauppauge HD-PVR is a great little device that does realtime h.264/AC3 conversion of HD content from analog component inputs. It is a supported tuner in the upcoming 0.22 release of MythTV. Unfortunately, mythtranscode does not yet support lossless transcoding of HD-PVR recordings. Therefore, for long term storage of recordings, another method is necessary. | ||
| + | |||
| + | ===== Caveats ===== | ||
| + | |||
| + | |||
| + | ===== Credits ===== | ||
| + | * Robert McNamara wrote the [[http://svn.mythtv.org/trac/ticket/5809|required mythcommflag patch]] and the [[http://www.mythtv.org/wiki/User:Iamlindoro|avidemux2_cli line]] necessary to do the heavy lifting. | ||
| + | * Menny Even-Danan wrote a great [[http://ubuntuforums.org/showthread.php?t=1061733|metadata script for MythVideo]] from which I took most of the perl subroutines. | ||
| + | * I took the MySQL lookup code from [[http://www.justlinux.com/forum/showpost.php?p=878967&postcount=4|this script]] written by cybertron. | ||
| + | |||
| + | ===== Requirements ===== | ||
| + | The versions listed are the ones I am using. Earlier versions might work, I don't know. | ||
| + | * MythTV | ||
| + | * Handbrake CLI 0.9.4 | ||
| + | * LWP::UserAgent perl module | ||
| + | |||
| + | ===== Usage ===== | ||
| + | |||
| + | |||
| + | ===== The Scripts ===== | ||
| + | This process uses two scripts, both run as user jobs. The first one converts the recording to MPEG2, rebuilds the MythTV seek index, and runs the commercial flagger on the new recording. | ||
| + | |||
| + | This is what it looks like: | ||
| + | <code bash>#!/bin/sh | ||
| + | # | ||
| + | # | ||
| + | # mpeg2fixup.sh | ||
| + | # | ||
| + | # Written in 2008 by Robert McNamara. Please redistribute freely and without | ||
| + | # restriction. (robert DOT mcnamara ATSIGN g m a i l DOTCOM) | ||
| + | # | ||
| + | # Script to clean up Firewire and DVB recordings that kill mythtranscode. | ||
| + | # It appears the bogus PTS information makes mythtrascode lossless transcoding | ||
| + | # fail with error 232 (Unknown). It complains about a deadlock. | ||
| + | # | ||
| + | # This solution is not the most elegant in the world, but it *does* work and | ||
| + | # ultimately permits Myth to successfully lossless-transcode the files. | ||
| + | # | ||
| + | # There are two prerequisites for this script. The first is the xport | ||
| + | # transport stream demuxer. It is only distributed for Windows but it compiles | ||
| + | # fine on linux. Get the following file: | ||
| + | # | ||
| + | # http://www.w6rz.net/xport.zip | ||
| + | # | ||
| + | # And unzip it. Compile it with "cc -o xport xport.c" and copy the resulting | ||
| + | # file to somewhere in your path (in my case, /usr/bin). | ||
| + | # | ||
| + | # You will also need a copy of ffmpeg with AC3 and MPEG-2 support. | ||
| + | # | ||
| + | # In essence, this script demuxes the file recorded from DVB/Firewire, and | ||
| + | # remuxes the streams with ffmpeg into a "clean" MPEG container. It copies the | ||
| + | # existing recording file to the same location with extension .tmp and inserts | ||
| + | # the new file in its place. Commercial flags and cutlists are cleared, and | ||
| + | # commflagging is run on the new file. In my limited testing, Myth can now | ||
| + | # successfully transcode the resulting file losslessly. | ||
| + | # | ||
| + | # Here's how it should be set up as a userjob: | ||
| + | # | ||
| + | # mpeg2fixup.sh "%DIR%" "%FILE%" | ||
| + | # | ||
| + | # I set the script to work within /tmp. If you don't want it to do that, | ||
| + | # change the first variable below. | ||
| + | # | ||
| + | # Even on a powerful processor (I run this on a Q6600) you can expect this to cost | ||
| + | # you 10 or so minutes of processing time for each hourlong show. It's the price | ||
| + | # you pay to preserve quality and end up with lossless-transcode-able files. | ||
| + | |||
| + | WORKINGDIR=/mnt/sdd | ||
| + | |||
| + | DIR=$1 | ||
| + | FILE=$(basename "$2" '.mpg') | ||
| + | |||
| + | audiofmt=`ffmpeg -i ${DIR}/${FILE}.mpg 2>&1 | grep Audio | awk -F"," '{ print $1 }' | awk -F": " '{ print $3 }'` | ||
| + | |||
| + | if [ "$audiofmt" = "ac3" ] | ||
| + | then ffmpegarg="copy" | ||
| + | else ffmpegarg="mp2 -ab 192k" | ||
| + | fi | ||
| + | |||
| + | # Once we're done with that, let's mux everything into a new file. | ||
| + | ffmpeg -threads 2 -v 1 -i ${DIR}/${FILE}.mpg -vcodec mpeg2video -b 13000k -acodec $ffmpegarg -f vob -y ${DIR}/${FILE}.new.mpg | ||
| + | |||
| + | # Let's move the old file out of the way, and the new file into its place. | ||
| + | mv ${DIR}/${FILE}.mpg ${DIR}/${FILE}.old.mpg | ||
| + | mv ${DIR}/${FILE}.new.mpg ${DIR}/${FILE}.mpg | ||
| + | |||
| + | |||
| + | # Now we need to clear the cutlist on the file, rebuild its seektable, and rerun commflagging. | ||
| + | |||
| + | mythcommflag --clearcutlist -f ${DIR}/${FILE}.mpg | ||
| + | ERROR=$? | ||
| + | if [ $ERROR -ne 0 ]; then | ||
| + | echo "Clearing cutlist failed for $FILE with error $ERROR" | ||
| + | exit $ERROR | ||
| + | fi | ||
| + | |||
| + | # *Don't* rebuild the seektable traditionally or you will end up with screwed up times and it will be uneditable. | ||
| + | # Use mythtranscode on lossless/buildindex mode instead. | ||
| + | |||
| + | mythtranscode --mpeg2 --infile ${DIR}/${FILE}.mpg --buildindex --showprogress | ||
| + | ERROR=$? | ||
| + | if [ $ERROR -ne 0 ]; then | ||
| + | echo "Rebuilding seektable failed for $FILE with error $ERROR" | ||
| + | exit $ERROR | ||
| + | fi | ||
| + | |||
| + | # Commercial Flagging. This mostly sucks on my broken recordings, you can comment it out if | ||
| + | # you wish. I find that I basically have to go in and manually set cutpoints anyway. | ||
| + | |||
| + | mythcommflag -f ${DIR}/${FILE}.mpg | ||
| + | ERROR=$? | ||
| + | if [ $ERROR -ne 0 ]; then | ||
| + | echo "Commercial flagging failed for ${FILENAME} with error $ERROR" | ||
| + | exit $ERROR | ||
| + | fi | ||
| + | |||
| + | # Remove the contents of the working directory | ||
| + | #rm -rf "$WORKINGDIR/$FILE" | ||
| + | # If you want to remove the old recording, uncomment the last line: | ||
| + | # rm "$DIR/$FILE.old.mpg" | ||
| + | </code> | ||
| + | |||
| + | The second script, also run as a user job, should be run on the recording after setting the commercial cutpoints. | ||
| + | |||