Home / atsc     frequal.com  RSS Feed

Processing Digital Television (ATSC)

This site describes the digital television (ATSC) transport stream (TS) files and how to process them. This information will allows you to write programs to:
  • Edit ATSC transport stream (TS) files, including:
    • Splitting files
    • Merging files
    • Removing certain programs
    • Removing certain sections of programs
  • Extract information from TS files, such as
    • Station Name
    • Program Guide information

The Format

The ATSC format is defined formally in several lengthy documents on the ATSC site. The key documents are:

The Hardware

To capture over-the-air (OTA) ATSC signals now available throughout the US, you'll need an ATSC capture card. I use and recommend ones from pcHDTV. With the pcHDTV you can use the provided command-line tools or the DVR program pchdtvr to record transport stream files. These files are typically large since the captured ATSC signal contains about 9GB per hour of data.

Processing Basics

OK, you have a multi-gigabyte TS file. What's in there?

The first thing to know is that the TS file consists of 188-packets. The whole file (if it is not corrupted) is one 188-byte packet after another.

Each packet starts with a 4-byte header.

  • 8 bits: Sync byte. Should always be a fixed value
  • 1 bit: Transport Error if true, OK if false
  • 1 bit: Start of a data table if in data PID if true
  • 1 bit: High Priority if true, normal otherwise
  • 13 bits: PID: Identifies the substream in the TS to which this 188-byte packet belongs
  • 4 bits: unimportant
  • 4 bits: Continuity Counter: For this PID, this should increase monotonically

Program Association Table

If the PID is 0, immediately following the 4-byte header is a 1-byte pointer field. If the "Start of data table" is true, then the pointer indicates the number of bytes past the pointer field where the PAT begins. The PAT header has these fields:
  • 8 bits: Table ID: All 0's
  • 4 bits: Reserved
  • 12 bits: Section Length: Max 1024, Length of this PAT
  • 2 bytes: Transport Stream ID: Identifies the Subchannel
  • 2 bits: Reserved
  • 5 bits: Version Number
  • 1 bit: Currently Valid
  • 1 byte: This Section Index
  • 1 byte: Last Section Index
Take the Section Length, subtract 9, then divide by 4 to find the number of 4-byte PAT entries following this header. The PAT Entries have these fields:
  • TODO

Interesting PIDs

Each packet has a PID. A collection of packets that share a PID for a stream. Some streams carry a video channel, some carry audio data. Others carry other information, such as the association between video and audio data, and channel guides.

Here is a list of some common PIDs you'll see and what they are used for:

  • 0: Program Assocation Table: Tells the PID of the Program Map table (aduio/video association) for each program (subchannel)
  • 0x11: Commonly used for the first video stream
  • 0x14: Commonly used for the first audio stream
  • 0x21 and 0x24: First or second pair of video/audio
  • 0x41 and 0x44: Another pair of video/audio
  • 0x1ffb: PSIP

Last modified on 26 Jan 2008 by AO

Copyright © 2024 Andrew Oliver