Revision as of 01:09, 17 September 2012

name=unnamed
author=Christopher Neufeld
webpage=none
short=Record closed-caption data for HD-PVR recordings
long=This set of scripts provides a way, given the right hardware, to record closed-caption data for HD-PVR recordings.
file=hd-captions-finalize.sh
category=User Job Scripts
supports=S21:unset,S22:unset,S23:unset,S231:unset,S24:unset,S241:unset,S25:unset,S251:unset,S252:unset,S26:unset,S27:unset,S28:unset

Author

Christopher Neufeld

Description

This set of scripts provides a way, given the right hardware, to record closed-caption data for HD-PVR recordings.

Supports

Because there is no defined standard for the transmission of closed-caption information over high-definition connections such as component or HDMI, it is not currently possible to obtain closed caption data from recordings produced by a Hauppauge HD-PVR. One alternative that may be suitable for some users is to use the STB (set-top box) to render the captions, so that they are seen as open captions by the HD-PVR, but this has the disadvantage of not being selectable at viewing time, the captions are an inextricable part of the video data. The technique described here allows closed-caption recording, with caption text that can be turned on or off as desired during the viewing of a recording.

The technique described here allows recordings to be made with closed caption information, provided that the STB has the correct behaviour, and that you have a card capable of reading the VBI data from a composite or coaxial standard-definition stream. This procedure has been tested with a Hauppauge PVR-500.

Please note that this procedure includes post-processing after a recording is complete, so it does not work with live television, or with programs that are being watched while still being recorded. It will work for viewing recordings that have completed. The post-processing stage takes only seconds, so the show can be viewed almost immediately.

As with several other scripts, this works by dropping a .srt file into the storage directory. MythTV will automatically use such a file if it is found. The .srt file is obtained by scanning the standard-definition outputs of the STB.

Contents

Prerequisites

Before proceeding, first determine whether you have the hardware required.

You must have a STB that has standard-definition outputs as well as the component outputs used by the HD-PVR. These can be composite or coaxial. If using a coaxial connection, some changes will have to be made to the script, you will have to choose the correct input number, and will have to set the tuner frequency.

Your STB must produce output on the standard-definition outputs even when tuned to a high-definition channel.

To test these requirements, connect your television set to the standard-definition outputs of the STB. Tune the STB to a high-definition channel, and then use the television's internal settings (not the STB settings) to select closed captions. If you see captions, then your STB is suitable for use with this technique. Note that not all programs will have captions, and sometimes commercials or promos don't have them, so you might have to check several high-definition channels to determine whether or not your STB transmits VBI data.

Next, you must have a hardware device capable of reading the VBI stream from a standard-definition, analogue stream. In my case, my backend has a PVR-500 card, which can do that. I connected the composite outputs of the STB to the composite inputs of the PVR-500. Note that you only have to connect one cable, on the video plug, the two audio plugs aren't necessary for this operation, but I've plugged in all three because I don't have individual cables, only triplet cables.

You must be using at least MythTV 0.23, because we are using system events.

You must have installed the CCExtractor program. I have tested this with ccextractor version 0.59.

Parameters to determine

You may have to modify some parameters in these scripts. They should all be adjustable by editing the hd-captions-common.sh script, not the other two. The required parameters are:

The CardID of your HD-PVR. Mine is '1'. You can determine this by running the MySQL command "select cardid,cardtype from capturecard;", or simply modify the script to write cardid to a file and exit, then start a recording on the HD-PVR.

The pathname of the device file to the VBI-extracting hardware. In my case, that's the second module of my PVR-500, and on my system that's /dev/pvr_500_2

The input number of the composite input on the VBI-extracting hardware. In my case, that's '2'.

A working directory, writable by the UID that runs the mythbackend. I have a tmp directory in /myth, so I've set the working directory prefix to point under that. The script will create a new directory in which it will work, and will remove the directory when it completes.

A bias can be set here, or it can be left to zero. If set to a positive number, captions will appear that many seconds earlier in the stream. This is to allow for the possibility that there is an undetected systematic delay on your particular hardware, one that requires correction.

There is also a set of binaries used by the scripts. You should verify that the pathnames are correct for your system. In particular, ccextractor might be installed somewhere other than in /usr/bin.

Setting up

Copy all three scripts to the same directory. They should be made executable, and should be in a directory that is readable by the UID that runs the mythbackend.

In mythtv-setup, go to the screen "System Events". Add two new events. Under "Recording started", using the complete pathname, insert the script hd-captions-start.sh:

Also in mythtv-setup, under "Input Connections", on the second page for the HD-PVR, create a new recording group for the HD-PVR, and add the VBI-decoding hardware to that recording group. That ensures that the backend will not try to schedule a recording on your VBI-decoding hardware while you're using it to extract captions for the HD-PVR. Note that the backend must be restarted for this recording group change to be noticed by the scheduler.

Finished

You can now restart your backend, and you should get recordings with closed captions, selectable at viewing time.

Recording finalize script

This script, executed once the recording has finished, performs the following steps, in order:

Verify that this was an HD-PVR recording

Looks for the working directory, and exits if it wasn't found

Enters the working directory

Forks a subshell to to the work

Uses ffprobe to parse out the duration of the HD-PVR recording. I find that it can take the HD-PVR up to dozens of seconds to start recording, so we can't assume that it is as long as the requested recording interval.

Uses the end time of the recording (assumed correct) and the length of the recording to deduce the starting time of the HD-PVR stream

Compares the starting time of the HD-PVR stream with that of the VBI stream, and computes the time offset

Runs ccextractor on the previously-collected data, correcting for the time offset

Kills the first ccextractor run from the startup script, if it's still running, to free up the device file for immediate use