From Tim's website
Jump to: navigation, search

This method uses free software to transfer recordings from a Humax to a PC and prepare them to be burnt to a DVD. I use a mix of Windows and Linux, but most of the tools will run on either operating system.

I record Freview (DVB-T) transmissions using either a Humax 9800T PVR or MythTV. MythTV produces .mpg files containing the transmitted stream. These can be processed in the same way as the .ts files transferred from the Humax, just skip the 'Transfer' step.

Transfer from Humax

Transfer files from the Humax PVR-9200T using a USB cable and Humax Media Controller:

Faster transfers are possible if the hard disk is removed from the Humax and connected directly to a PC.

Each transferred file contains the transmitted FreeView bit stream. For example, using

ffmpeg -i "My Film.ts"
Input #0, mpegts, from 'My Film.ts':
 Duration: 03:26:53.71, start: 1499.160422, bitrate: 3840 kb/s
 Program 4287
   Stream #0:0[0xc9]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p, 720x576 [SAR 64:45 DAR 16:9], 15000 kb/s, 25.25 fps, 25 tbr, 90k tbn, 50 tbc
   Stream #0:1[0xca](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16, 256 kb/s
   Stream #0:2[0xce](eng): Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, s16 (visual impaired)
   Stream #0:3[0xcd](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)

Trim and Demux

I use ProjectX to demux the file. This spearates the audio and video strems. ProjectX also allows the stream to be edited, removing unwanted segments. The editing is optional, but I use it to trim the start and end of the recording and to remove commercials. For a single file I do this manually with the GUI, but for a collection of files I use comskip to find the approximate start and end of the commercial breaks.

Automatic cut point generation

This can be done natively on Windows, or on Linux using 'wine':

wine comskip.exe --ini=comskip.ini "My Film.ts"

The comskip.ini file is generated by the GUI. It needs to contain the following to ouput cut points in a format we can use:

output_edlx=1

This causes an .edlx file to be generated, which can be converted to an .Xcl for projectX using the following shell operations:

filebase="My Film.ts"

# Create a temporary text file containing the cut points from the .edlx file
tmpfile="$filebase"".tmp"
sed -n 's/<region start="\([0-9]*\)" end="\([0-9]*\)"\/>/\1\n\2/p' <"$filebase"".edlx" >> "$tmpfile"

# Create a .Xcl file with the ProjectX header indicating binary cut points
outfile="$filebase"".Xcl"
echo "CollectionPanel.CutMode=0" > "$outfile"

# Copy the cut points from the temporary file to the .Xcl file. Cut points in
# the .edlx file start with an advert start. ProjectX expects the cut points
# to start with a program start. The cut point at the end is also unnecessary.
firstcut=`head -n 1 "$tmpfile"`
if [ $firstcut -lt 1000000 ]; then
  # First cut appears to be at the start of the stream, so remove it
  # Also remove the last point, since it marks the end of the stream
  head -n -1 "$tmpfile" | tail -n +2 >> "$outfile"
else
  # First cut is too far into the stream to be at the start, so the stream
  # probably starts in program material. Add an extra cut point at the start.
  # Also remove the last point, since it marks the end of the stream
  echo "0" >> "$outfile"
  head -n -1 "$tmpfile" >> "$outfile"
fi

Comskip inserts cut points with the intention that they can be used to skip to the end of the adverts during playback. There are often unwanted cut points inserted during adverts, and the location of the cut point may not be perfect. For these reasons I always read the automatically generated .Xcl file in to ProjectX and adjust the cut points as required.

Cut point edit or manual generation

The .Xcl file can be edited or generated from ProjectX.

  1. Load the .ts or .mpg file in to ProjectX
  2. Load the automatically generated .Xcl file (if one was generated)
  3. Edit the cut points using the short cuts
    1. a: add, d: delete
    2. n: next, p: previous
    3. Arrows with Shift or Ctrl to move the cursor through the file with different size steps.
  4. For multiple files, save the .Xcl

Trim and Demux

  • For a single file, select demux and QuickStart from the ProjectX GUI
  • For multiple files, run in a batch script:
java -jar ProjectX.jar -cut "My Film.Xcl" -demux "My Film.ts"

The result will be a video stream with the extension .m2v, one or more audio streams with the extension .mp2, and possibly other streams such as subtitles. Delete all the output files except the .m2v and the desired .mp2 (usually the largest).

It's also worth checking any large log files for errors. ProjectX will drop any frames with errors. This isn't a problem if the original signal quality was good - it may just drop the odd frame here or there, but with a poor signal it can result in segments being dropped. The only indication of this is in the log files. If this happens I usually delete the recording and set MythTV to record it again when it is next shown.

Multiplex to a VOB

The separate streams need to be combined to create a VOB file with a format suitable for DVD playback:

mplex -f 8 -o "VOBs/$filename.vob" "Demuxed/$filename.mp2" "Demuxed/$filename.m2v"

Build a DVD image

I collect tens of recordings before writing them to DVD. This allows me to group similar recordings on the same DVD, and also arrange them to fill the DVDs efficiently. I make the selection using a spreadsheet and script, and the resulting file selection ends up in an array. I generate an XML file from this array as follows:

echo "<dvdauthor dest=\"./DVDs/Disc $discname\">"          >  "$discname.xml"
echo "  <titleset>"                                        >> "$discname.xml"
echo "    <titles>"                                        >> "$discname.xml"
echo "      <video format=\"pal\"/>"                       >> "$discname.xml"
nfilm=0
for filename in "${filenames[@]}"
do
  title=`echo $filename | sed 's/[0-9]* [0-9]* \([^\.]*\).vob/\1/g'`
  echo "    <pgc>"                                         >> "$discname.xml"
  if [ $layer_break -eq $[$nfilm+1] ]; then
    total_seconds=`mplayer -nojoystick -nolirc -vo null -ao null -frames 0 -identify "./VOBs/$filename" | grep ID_LENGTH | cut -d = -f 2`
    cut_point=`echo "$total_seconds*($total_size/2-$side1_size)/${sizes[$nfilm]}" | bc`
    cut_hh=$[$cut_point/3600]; cut_point=$[$cut_point-$[$cut_hh*3600]]
    cut_mm=$[$cut_point/60]; cut_ss=$[$cut_point-$[$cut_mm*60]]
    echo "$nfilm: $title (Layer break at time $cut_hh:$cut_mm:$cut_ss)"
    echo "      <vob file=\"./VOBs/$filename\">"           >> "$discname.xml"
    echo "        <cell end=\"$cut_hh:$cut_mm:$cut_ss\" chapter=\"1\"/>"   >> "$discname.xml"
    echo "        <cell start=\"$cut_hh:$cut_mm:$cut_ss\" chapter=\"0\"/>" >> "$discname.xml"
    echo "      </vob>"                                    >> "$discname.xml"
  else
    echo "$nfilm: $title"
    echo "      <vob file=\"./VOBs/$filename\"/>"          >> "$discname.xml"
  fi
  echo "    </pgc>"                                        >> "$discname.xml"
  nfilm=$[$nfilm+1]
done
echo "    </titles>"                                       >> "$discname.xml"
echo "  </titleset>"                                       >> "$discname.xml"
echo "</dvdauthor>"                                        >> "$discname.xml"

If a layer break is required it will be inserted between recordings if possible, otherwise the recording that lies across the layers will be split in to cells. Playback will be seamless, although older players may pause for a second during the layer switch. For this reason, it is better if the recordings can be ordered to provide an equal number of bytes in the first and second half (so the layer break is between recordings).

The resulting .xml file is read by 'DVD author', which generates a directory containing the files to write to the DVD. A second call is required to create the table of contents file.

export VIDEO_FORMAT=PAL
dvdauthor -x "$discname.xml"
dvdauthor -o "./DVDs/Disc $discname" -T

Burn the DVD

Finally I use ImgBurn on Windows to write the directory to a DVD. This excellent tool will generally work out what you actually need to get a working DVD.