Text capture
Introduction
Teletext is popular in Europe and provides both informational pages and captions or subtitles to television programs. In 1992, teletext was provided in 18 countries.
In North America, US federal law requires closed captioning of all non-exempt television programs starting in 2006. Some broadcasters are implementing XDS, or Extended Data Services.
TV capture chipsets implement teletext and closed captioning in different ways, and the free software code to support text capture is still missing or incomplete for some chipsets.
Supported cards
bt8x8
Cards based on the bt8x8 chip (cf. bttv devices have excellent support for text capture for both PAL/SECAM and NTSC.
Commandline output is provided by both ntsc-cc and the test/capture utility in zvbi.
saa713x
Cards based on saa713x chips (cf. saa7134 devices have excellent support for text capture under PAL/SECAM.
Pending patch submission, it is now also working on NTSC; cf. diagnostic screenshots.
ivtv
This exchange on the ivtv list suggests there is support for CC, VPS and WSS signals for the PVR-350, but that hardware limitations prevent teletext.
Similarly, this exchange from January 2005 discusses an ongoing project adding vbi support to PVR-x50. Finally, in this exchange from April 2005, Chris Kennedy discusses vbi support for pvr150/500.
The READMI.vbi in a current ivtv release has lots of details and attempts to improve it are going on.
DVB/DTV
The zvbi library supports the European standards ETSI EN 300 472 "Specification for conveying ITU-R System B Teletext in DVB bitstreams" and ETSI EN 301 775 "Specification for the carriage of Vertical Blanking Information (VBI) data in DVB bitstreams".
It can read VBI PES packets from Linux DVB devices and extract Teletext, VPS, WSS and Caption data. A demultiplexer is available to extract VBI data from DVB MPEG-2 program streams and a multiplexer to convert sliced VBI data, e. g. captured from analog devices, to DVB format. For details see the zvbi documentation. The test/capture utility in the source tarball can demonstrate these capabilities.
The American standard ATSC A/53 "ATSC Digital Television Standard" which also covers Closed Caption transport and the "digital" Closed Caption standard EIA 708-B are not currently supported by the zvbi library. See the EIA-708 Wikipedia entry and Ditital Television Closed Captioning FAQfor details.
However, Scott Larson writes that "stations are required to pass both EIA-608 (VBI) and EIA-708 (DTVCC) data. Why? Because If an ATSC receiver is connected to an NTSC TV (which is a likely occurance in the transition to digital broadcasting), the receiver is required to generate the old VBI Line 21 captions from the ATSC stream so the old TV will still have closed captions."
Scott has recently (23 September 2005) written a patch for mplayer to display closed captioning from the EIA-608 (VBI) stream; see the pchdtv forum for instructions.
cx88
The latest improvements on vbi support for cx88-based cards, aside from kernel-related stuff and modules reorganization, were made by Tom Zoerner in March of 2004. The README.cx88 still says: "some code present. Doesn't crash any more, but also doesn't work yet ..."
However, Tim sketched out exactly what needs to be done in this 22 May 2004 e-mail.
In the meantime, nxtvepg (which uses vbi information) is working on cx88 PAL tuners, cf. system requirements.
Applications
alevtv
AleVT is a teletext/videotext decoder and browser for the bttv driver (/dev/vbi) and X11.
gstreamer
The application gstreamer has incorporated support for closed captioning (they also mention some tweaks for Canadian English and French television); see Freedesktop's repository.
mtt
A teletext (PAL) browser with a Motif-based GUI and a console mode. In Debian, mtt is part of the motv package.
nxtvepg
The Nextview EPG decoder and browser is an Electronic TV Programme Guide for the analog domain (as opposed to the various digital EPGs that come with most digital broadcasts). It allows you to decode and browse TV programme listings for most of the major networks in Germany, Austria, France and Switzerland. The EPG information is read from /dev/vbi.
ntsc-cc
The application ntsc-cc handles closed captioning on bttv devices only, because it implements only the old v4l API. The saa7134 chip uses other sample rates.
For ntsc-cc to work, you typically need to be running an application for viewing or recording television, such as xawtv and mencoder. If no such application is running, ntsc-cc tends to produce garbled output.
The downside to ntsc-cc is that it doesn't link against libzvbi, which is the core of text capture under Linux, and it's not actively maintained. On the other hand, it's a great workhorse for bttv cards. Michael Schimek's test/capture utility will hopefully begin to cover the functionality of ntsc-cc.
tvtime
tvtime has built-in support for closed captioning for bttv and saa7134 cards (also others?).
In early 2004, Kevin Ko wrote a patch with useful comments to tvtime's vbidata.c; see his detailed account and the tvtime bugreport.
zapzilla
Zapping has a built-in teletext viewer called Zapzilla.
In addition, Zapping provides subtitle overlay through the closed captioning decoder built into libzvbi.
zvbi
"The zvbi library provides functions to read from Linux V4L, V4L2 and FreeBSD BKTR raw VBI capture devices, from Linux DVB devices and from a VBI proxy to share V4L and V4L2 VBI devices between multiple applications.
It can demodulate raw to sliced VBI data in software, with support for a wide range of formats, has functions to decode several popular services including Teletext and Closed Caption, a Teletext cache with search function, various text export and rendering functions.
Basically zvbi offers all functions needed by VBI applications except for the user interface. The library was written for the Zapping TV viewer http://zapping.sourceforge.net."
From the zvbi README, copyright Michael H. Schimek, Iñaki García Etxebarria, and Tom Zoerner. For further information, see the zvbi documentation, the zvbi wiki, and the zapping-misc mailing list.
There are utilities for testing in the tarball, available on zvbi's project page; cf. cvs. Closed captioning for saa7134 now works using libzvbi, and a free-standing ntsc-cc-zvbi may be available in cvs.
Technical background
Analog television
The vertical blanking interval (VBI) is an interval in a television signal that temporarily suspends transmission of the signal for the electron gun to move back up to the first line of the television screen to trace the next screen field. The vertical blanking interval can be used to carry data, since anything sent during the VBI would naturally not be displayed; various test signals, closed captioning, and other digital data can be sent during this time period.
In the PAL standard, Teletext and Caption data is digitally encoded in the vertical blanking interval (vbi) on lines 17 through 20.
In North America, closed captioning uses line 21 of the vertical blanking interval (NTSC standard).
Digital television
North American digital television (HDTV) uses the ATSC A/53 standard, cf. atsc.org. Michael Schimek writes,
"It transmits CC bytes in a user data field following a picture header, inside the video elementary stream. If the driver doesn't extract CC data on its own, and the "broadcast flag" permits this, one could perhaps read video packets from the device, or a complete MPEG-2 program stream from disk, and demultiplex in software. Libzvbi does something similar for DVB, so it shouldn't be hard to implement, if it hasn't been done already to extract DVD caption. A freestanding CC capture application would still need to tune in and choose a program ID; that's beyond the scope of libzvbi.
To complicate matters further A/53 may transmit old style caption EIA-608 as well as the newer "digital caption" EIA-708. I don't have enough information to properly implement EIA-708 caption overlay (nor is it useful for me until Zapping goes digital) but to write an ntsc-dtvcc it might suffice."
The European DVB standard transmits sliced VBI data in a separate elementary stream. Current drivers in libzvbi provide full support.
Displaying captured text
To get formatted output for overlay on the television image, Michael Schimek's decoder (part of libzvbi) works like a terminal emulator, printing caption into virtual screen memory. As long as you have "pop on" style caption, streaming is easy. For "roll up" caption it needs a more character or line oriented interface. Perhaps it would suffice to call the client and clear the screen before any vertical cursor motions and scrolling.
Testing
Recommended applications for testing under PAL/SECAM are mtt, zapping/zapzilla and alevt/d.
For lower-level testing, use the utilities in the test/ directory of the zvbi tarball, available on zvbi's project page; these are actively maintained.
The test/capture utility currently just dumps printable characters on stdout. This output needs to be "sliced". Sliced VBI is the data transmitted on each scan line. It still contains multiple logical streams, parity bits and control codes. In libzvbi "formatting" takes one stream, converts characters to Unicode and interprets control codes, giving one page of text for display. An export function would convert the text to ASCII.
To visualize the Vertical Blanking Interval on NTSC, issue
ntsc-cc -d /dev/vbi -c -w -r 11
Both bttv and saa7134 cards show orderly signals, while cx88 shows just noise.
In the zvbi test/ suite, osc similarly visualizes; cf. vbi images. The test/osc utility is more useful, since it displays which row and line are being graphed and lets you change rows with the arrow keys. NTSC closed captioning should appear on row 11, line 21.