Difference between revisions of "User talk:Iamlindoro"

From MythTV Official Wiki
Jump to: navigation, search
Line 35: Line 35:
 
# successfully transcode the resulting file losslessly.
 
# successfully transcode the resulting file losslessly.
 
#  
 
#  
# Here's how it should be set up as a userjob, after making it executable with 'chmod +x':
+
# Here's how it should be set up as a userjob, after making it executable
 +
# with 'chmod +x mpeg2fixup.sh':
 
#
 
#
 
# mpeg2fixup.sh "%DIR%" "%FILE%"  
 
# mpeg2fixup.sh "%DIR%" "%FILE%"  

Revision as of 20:50, 28 September 2008

This is a script that will correct broken MPEG-2 TSs from firewire or DVB. The script replaces the original recording with a file that will work with mythtranscode rather than crashing it.

#!/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, after making it executable
# with 'chmod +x mpeg2fixup.sh':
#
# 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=/tmp

DIR=$1
FILE=$2

# Make the directory to work in:
mkdir "$WORKINGDIR/$FILE"
cd "$WORKINGDIR/$FILE"

# First step is dumping the PIDs to files
xport "$DIR/$FILE" 1 1 1
  
# Once we're done with that, let's mux everything into a new file.
ffmpeg -i bits0001.mpv -i bits0001.mpa -vcodec copy -acodec copy "$WORKINGDIR/$FILE/$FILE"

# Let's move the old file out of the way, and the new file into its place.
mv "$DIR/$FILE" "$DIR/$FILE.old"
mv "$WORKINGDIR/$FILE/$FILE" "$DIR/$FILE"

# Now we need to clear the cutlist on the file, rebuild its seektable, and rerun commflagging.

mythcommflag --clearcutlist -f "$DIR/$FILE"
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" --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"
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"