Tech Tip - Closed Captioning Line 21 Insertion

Easy insertion of closed captioning formats into and out of an MPEG stream
PixelTools products can insert and extract a wide variety of closed captioning formats into and out of an MPEG stream. Our products can also add captioning during MPEG encoding. Currently supported formats include CEA-708, CEA-608, SCTE20, SCTE21, ATSC, DVD, and Analog. The tools include support for CC1 through CC4.
PixelTools MPEGRepairHD can:
- Insert closed captioning - line 21 (CC) Data into elementary video streams during encoding or to existing encoded elementary streams
- Extract and display digital and analog CC data from elementary and multiplexed streams
- Encode CC data per CEA-708, CEA-608, ATSC, or DVD specifications
- Transcode between CC formats
- Automate processing via batch mode
Expert WorkShop SDK can:
-
Embed all of the above CC processing in your application
Closed Captioning Samples
There are a large number of methods for adding closed captioning to MPEG video files. PixelTools currently supports seven different closed caption insertion specifications.
You can download sample files containing captioning encoded with all of the formats that we support.
CEA 708 DTV User moveable and re-sizable captioning for HDTV (cea708dtv.mpg)
CEA 708 NTSC Backward compatible CEA-608 captioning in CEA 708 (cea708ntsc.mpg)
CEA 708 DTV & NTSC Both CEA 608 and HDTV captioning (cea708.mpg)
SCTE 20 CEA-608 captioning in a SCTE-20 wrapper (scte20.mpg)
ATSC/CEA 608 CEA-608 captioning in an ATSC wrapper (atsc.mpg)
CEA 608 (also known as Divicom standard) CEA-608 captioning in user data (cea.mpg)
DVD Line 21 CEA 608 captioning that can be decoded by the set top (These captions are in addition to any DVD subtitles that are decoded by the DVD player itself) (dvd.mpg)
Adding closed captioning during encoding
During Encoding
Closed captioning insertion is controlled via the Encoding Decision List (edl) text file. The EDL file is read during the encode operation. The EDL file contains the closed captioning text string and the first frame number or time code where the text string will appear. The EDL file must be named Expert.edl and must be located in the directory where your encoded MPEG file is being stored. The CLOSEDCAPTION command specifies the closed captioning text string. An example of the format of the closed captioning is presented in the top of the sample Expert.edl provided with the product. The formatted closed captioning data is added to the appropriate frame user_data fields as requested in the Expert.edl file.
Using Raw Text as Input The following is an example of the Edl closed captioning file commands:
FRAME 1038
CLOSEDCAPTION
The little brown cow jumped over
FRAME 1146
CLOSEDCAPTION
the moon!Using Closed Captioning .SCC file as Input
The closed captioning EDL file can also be of popular closed caption file format (.scc) which consists of the time code followed on the same line by a sequence of sets of 4 HEX codes representing the actual closed captioning data that will be added to the video user_data.
The following is an example of the Edl with formatted closed captioning command:
00:00:00:14 9426 9426 94ad 94ad 9470 9470 9137 9137
00:00:13:06 942c 942cUsing Line 21 Hex data as Input
Also, any pre-formatted closed captioning data (using any closed captioning standard) can be added via the HEXUSERDATA edl command. Just add the frame number or time code of the frame user data and the actual user data, up to 72 characters long, after the HEXUSERDATA command. . An example of the format of the hex user data is presented in the top of the sample Expert.edl provided with the product.
The following is an example of the Edl raw user data file commands:
FRAME 1038
HEXUSERDATA 04 ff 29 d0 55 9f 28 44
FRAME 1039
HEXUSERDATA 05 ff 39 d4 22 9f 28 44</
FRAME 1102
HEXUSERDATA 05 ff 39 d4 22 9f 28 44
Closed Captioning Format
The Closed Captioning Format selection controls the actual formatting of the text or SCC EDL and DDL commands into the MPEG user data and controls the specific user data locations. The Format selection control is located in the Encode section of MPEGRepairHD in the Optimize Encode | Configure | Line 21 property page. Note that the insertion of closed captioning data into an existing stream using the Decode Fix process utilizes the Closed Captioning Format set in the Encode configuration.
The following Closed Captioning format options are available:
CEA 708 DTV
This option causes up to eighteen closed captioning characters to be inserted into picture header user data fields in display order. When converting text to CEA-708 data, DTV Window 0 will be initialized and enabled. Your closed captioning text will be written to this window at the specified frame or time code.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 47 41 39 34
CEA 708 NTSC
This option causes up to two closed captioning characters to be inserted into picture header user data fields in display order. These bytes are added to the NTSC channel in the field per your Closed Captioning Style selection. This channel was designated by the CEA to facilitate legacy closed caption processing in CEA-708 systems.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 47 41 39 34
CEA 708 DTV & NTSC
This option causes up to eighteen closed captioning characters to be inserted into picture header user data fields in display order and up to two closed captioning characters to be added to the NTSC channel in your selected field. When converting text to CEA-708 data, DTV Window 0 will be initialized and enabled. Your closed captioning text will be written to this window at the specified time. This option causes the same closed captioning text to be written to both the CEA-708 window and the NTSC channels.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 47 41 39 34
CEA 608 (default)
This option causes up to two closed captioning characters to be inserted into picture header user data fields in transmission order. The characters will be entered into the Field 1 or Field 2 closed captioning field per your Closed Captioning Style selection.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 02 09
ATSC / CEA 608
This option causes up to two closed captioning characters to be inserted into picture header user data fields in display order. The data formatted per CEA-608 and is wrapped in a SCTE-21 and ATSC header. The characters will be entered into the Field 1 or Field 2 closed captioning fields per your Closed Captioning Style selection.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 47 41 39 34
DVD
This option causes up to 30 closed captioning characters to be inserted into GOP header user data fields. The first set of user data will be inserted at the first GOP at or after the Frame number or time code set in the EDL or DDL file. The remaining user data (over the 30 character per GOP limit) will be inserted in subsequent GOP headers. The characters will be entered into the Field 1 or Field 2 closed captioning field per your Closed Captioning Style selection.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show user data at EVERY GOP header that will start with the Hex values: 43 43 01 f8 9e. The GOP headers will contain the closed captioning data or will contain NULL data.
SCTE 20
This option causes up to two closed captioning characters to be inserted into picture header user data fields in display order. The data formatted per CEA-608 is inserted per the ANSI/SCTE 20 standard. The two captioning characters are not byte aligned and so will not be immediately recognizable when extracted in the MPEGRepairHD decode statistics. The characters will be entered into the Field 1 or Field 2 closed captioning fields per your Closed Captioning Style selection.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show 7 bytes of user_data in the Picture Headers that will start with the Hex values: 03 81.
To an existing MPEG
stream
Closed captioning can be added to an existing elementary stream. This is accomplished using the PixelTools decode functionality in conjunction with a Decision List (ddl) text file. The DDL file contains the closed captioning text string and the first frame number or time code where the text string will appear. The DDL file must be named Expert.ddl and must be located in the directory where your output “fixed” MPEG file is being stored. To enable processing of the Expert.ddl file, check the Decode Function Enable | Configure | Fix Stream | Use Commands in DDL file option and enter the name of the file the will include the closed captions in the Save Fixed File edit box. The CLOSEDCAPTION command in the Expert.ddl file specifies the closed captioning text string. An example of the format of the closed captioning is presented in the top of the sample Expert.ddl provided with the product. The formatted closed captioning data is added to the appropriate frame user_data fields as requested in the Expert.ddl file after depressing the Control Decode | Run button with your source file in the Decode MPEG File to Decode or Analyze edit box . You can speed up the process by depressing the Speed button with the slashed monitor to disable decode display.
The ddl file format is similar to that of the
edl file format presented above. In addition to the text strings
supported with the CLOSEDCAPTION command, any formatted user data can
be inserted via the HEXUSERDATA command. Also, the .scc closed
caption format is supported. (Be sure to rename the .scc file as Expert.ddl).
Displaying closed captioning via MPEGRepairHD GUI
The MPEGRepair Decoder can extract and display closed captioning information in several formats.
Hex User Data
Closed Captioning Data CEA Field1 DVD Field1 CEA-708 All CEA-708 Window1 ->Window8 |
Click on image to
see actual size. |
Closed Captioning Overlay Opening the Decode Display window using the De speed button will bring up a window that will display all of the frames in display order. Selecting the Text Overlays | Closed Captioning | Your Option will cause all of your selected closed captioning text detected in the stream to be over laid on the decoded video. The Field1 option displays all Field1 captions that have been added via the CEA-608, ATSC, DVD, SCTE 20, or CEA-708 NTSC standards. The text appears with a greenish color above the Field2 text. The Field2 option displays all Field2 captions that have been added via the CEA-608, ATSC, DVD, SCTE 20, or CEA-708 NTSC standards. The text appears with a reddish color below the Field1 text. The CEA-708 option displays all of the CEA-708 captions that are written to windows 1 through 8. The text appears with a bluish color below the Field2 text.
|
Extracting Digital Closed Captioning Data
Select your file containing the digital closed captioning in the File to Decode or Analyze Edit box. In the Decode Configure | Extract Streams dialog, check the Save Digital Data option and enter or browse the name of the file to hold your extracted data. Running the decoder will cause all user_data to be saved in your selected output file.
Extracting Analog Closed Captioning Data
Select your file containing the analog closed captioning in the File to Decode or Analyze Edit box. In the Decode Configure | Extract Streams dialog, check the Save Analog Data option and enter or browse the name of the file to hold your extracted data.
Running the decoder will cause the two CC bytes to be extracted from the analog modulated white line at the top of each frame. The parity bit will be stripped off of the data before it is saved. The data in your selected analog CC file will be ASCII text which will include the CC words displayed on the screen. The data will also include the CC control characters which will be intermixed with the readable text.
Extraction in the Statistics Log
All data displayed in the Decode Statistics Log
will also be stored in the Decode.log file. You can select between
the raw user_data and the translated ASCII text and control codes using
the Decode | Statistics | Video Statistics menu options.
Adding closed captioning via ExpertWorkshop SDK
During Encoding
To enable the addition of closed
captioning data while encoding a file, create an encoding edl text file
as described above using the CLOSEDCAPTION, or HEXDATA commands or use
one of the supported closed captioning file format. Use the EdlFullFileName
configuration parameter to point to the edl file. During the ExpEncodeNextFrame
API command, the selected edl file will be read to determine if any
closed captioning data needs to be added to the user_data in the encoded
frame.
The two closed captioning bytes also be added to each frame by adding them to the ClosedCaptionBuffer parameter of the calls to ExpEncodeNextFrame. These two bytes will be stuffed into video user_data using the format and wrapper as defined in the Closed Captioning Format.
During Decoding
To enable the addition of closed
captioning data while decoding a file, create a decoding ddl text file
as described above using the CLOSEDCAPTION, or HEXDATA commands or use
one of the supported closed captioning file format. Store the name of the resultant MPEG file that will contain
the closed captioning data in the DecodeFixName member of the ExpDecFix_str. The
ExpDecFix_str is a member of the VidDecodeParams_struc which is sent
to the decoder as a member of the ExpDecConfigure API call. During
calls to ExpDecodeNextFrame, the source stream is written to the resultant
MPEG stream along with the appropriate user_data containing the closed
captioning text per the ddl file.
Closed Captioning Insertion Format
The Closed Captioning Format is set using the ExpEncodeConfigure call
where the
ExpEncParameters_str | Line21Params_struc CCType contains the
actual format.
CCType of:
CEA608 = 0
ATSC_CEA608 = 1
DVD_CC = 2
CEA708_DTV = 3
CEA708_NTSC = 4
CEA708_DTV_NTSC = 5
SCTE20 = 6
Specification
The CGMS and APS flags are added to the MPEG video user data as Extended Data in the line 21 emulation of digital data as specified in the Advanced Television Systems Committee Inc (ATSC) Digital Television Standard A/53, the ISO/IEC 13818-2 MPEG video standard, the Society of Cable and Telecommunications Engineers (SCTE) ANSI/SCTE 20 2004 Methods for Carriage of Closed Captions and Non real-time Sampled Video and ANSI/SCTE 21 2001 Standard for Carriage of NTSC VBI Data in Cable Digital Transport Streams specification, and the Consumer Electronics Association CEA-708-B Digital Television (DTV) Closed Captioning specification, and the Consumer Electronics Association CEA-608-C Line 21 Data Service specification.
Supplemental Information
Line 21 data can have many uses and is governed by multiple overlapping specifications in support of government and industry regulations. A little history may aid in the understanding of the features.
Analog
In the 1970’s, extra bandwidth was exploited in the television
broadcast signal that occurred in a normally dead period while the electron
gun was being repositioned to start the painting of each new field. A
US federal mandate required that most broadcasts include closed captioning.
It was determined that two ASCII characters could reliably be included
in the vertical retrace interval (line 21) right before the first visible
horizontal line. Simple decode circuitry was mandated to
be included in all TVs that would provide the extraction and storage
of the line 21 data and allow the TV user to add the closed caption characters
as an overlay to the video in the next fields. Other industry users
fought for access to the line 21 data. The Copy Generation Management
System (CGMS) provided a three state flag that would cause new industry
and federally mandated TV decoders to prevent copying of selected video
content. The flags are “Copy Freely”, “Copy Once”,
and “Copy Never”. The old Macrovision technology of
interfering with the TV broadcast synchronization signals to prevent
video copying was also embedded in line 21 data with Analog Protection
System (APS) flags that instruct the video decoder to interfere with
selected synchronization signals. Also video content rating, program
type information, and program schedule data is broadcast via the line
21
Digital
The advent of MPEG compressed video brought with it more possibilities
for higher bandwidth closed captioning channel and other supplementary
data channels. One of the digital constraints though was to make
the new system backwards compatible with older TV technologies IE allow
for just two bytes of data per field. This evolution has resulted in
a large array of specifications that support the new and old capabilities.
Line 21 data can be added to user_data of each frame of elementary
MPEG video. Line 21 data can also be added as a special stream
within a MPEG transport stream.
Digital Television offers a variety of display sizes and aspect ratios. To accommodate these different dimensions, the CEA-708 specification includes enhanced display features as compared to the older CEA-608 specification. CEA-608 decoders were required to place the captioning overlay in a defined section of the screen and with a specified font size. CEA-708 decoders draw the captioning text in a user defined window anywhere on the display. The user can interactively move and re-size this captioning window. The captioning commands define anchor points that will not move when this window is resizes. As such, CEA-708 requires quite a bit more control overhead to utilize the advanced features. This makes CEA-608 streams not easily converted into full featured CEA-708 streams. CEA-708 does include four optional bytes per frame which are designated as NTSC captioning bytes for backward compatibility with CEA-608 decoders. It is possible to add both the DTV CEA-708 captioning in additional to the NTSC bytes in the sample CEA-708 headers.
Specifications
The Consumer Electronics Association publishes CEA-608-C Line 21 Data
Service that details data formats for closed captioning services and
extended data (including CGMS and APS). The CEA publishes CEA-708-B
Digital Television Closed Captioning that details usage of a 9600 bps
closed channel (ten times the bandwidth of the original channel). The
Advanced Television Systems Committee Inc (ATSC) publishes the Digital
Television Standard A/53 specification that details a format for adding
line 21 data to user_data of an MPEG-2 stream. The International
Organization for Standardization (ISO) publishes the ISO/IEC 13818-2
MPEG video standard that details the inclusion of user_data in compressed
video streams. The Society of Cable and Telecommunications Engineers
(SCTE) publishes the ANSI/SCTE 20 2004 Methods for Carriage of Closed
Captions and Non real-time Sampled Video and ANSI/SCTE 21 2001
Standard for Carriage of NTSC VBI Data in Cable Digital Transport Streams
specification that defines additional VBI services.
PixelTools line 21 support
At the lowest level, MPEGRepairHD is capable of adding frame accurate
user_data during MPEG encoding or to an already existing video elementary
stream. This will support all of the above data services provided
that the data is packaged in the correct format. MPEGRepairHD can add
up to 128 eight bit data bytes to designated frames during encoding
using an Encoding Decision List (EDL) file or to an existing MPEG stream
using a Decoding Decision List (DDL) file. These text files specify
the frame number and corresponding data bytes which will be inserted
in the user_data at the selected picture header. The data bytes
must be formatted appropriately per the desired usage. The encoding
EDL and the decoding DDL files utilize the identical format.
At a higher level, MPEGRepairHD can add CEA-708 or CEA-608 closed captions during encoding or to an existing stream as listed in a simple text file. The EDL command file reads closed caption text strings, formats your closed caption text and inserts it into user_data fields starting at your requested frame number. The MPEGRepairHD Decode | Configure | Fix Stream dialog also allows selection of a similar DDL closed caption text file that will be formatted and added to an existing MPEG stream. The Encode and Decode closed caption text commands are of identical format regarding current status of adding Line 21 data as a separate transport layer within a transport stream.
Using Line 21 Hex data as Input
Also, any pre-formatted closed captioning data (using any closed
captioning standard) can be added via the HEXUSERDATA edl command. Just
add the frame number or time code of the frame user data and the actual
user data, up to 72 characters long, after the HEXUSERDATA command.
. An example of the format of the hex user data is presented
in the top of the sample Expert.edl provided with the product.
The following is an example of the Edl raw user data file commands:
FRAME 1038
HEXUSERDATA 04 ff 29 d0 55 9f 28 44
FRAME 1039
HEXUSERDATA 05 ff 39 d4 22 9f 28 44
FRAME 1102
HEXUSERDATA 05 ff 39 d4 22 9f 28 44
Closed Captioning Format
The Closed Captioning Format selection controls the actual formatting of the text or SCC EDL and DDL commands into the MPEG user data and controls the specific user data locations. The Format selection control is located in the Encode section of MPEGRepairHD in the Optimize Encode | Configure | Line 21 property page. Note that the insertion of closed captioning data into an existing stream using the Decode Fix process utilizes the Closed Captioning Format set in the Encode configuration.
The following Closed Captioning format options are available:
CEA 708 DTV
This option causes up to eighteen closed captioning characters to be inserted into picture header user data fields in display order. When converting text to CEA-708 data, DTV Window 0 will be initialized and enabled. Your closed captioning text will be written to this window at the specified frame or time code.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 47 41 39 34
CEA 708 NTSC
This option causes up to two closed captioning characters to be inserted into picture header user data fields in display order. These bytes are added to the NTSC channel in the field per your Closed Captioning Style selection. This channel was designated by the CEA to facilitate legacy closed caption processing in CEA-708 systems.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 47 41 39 34
CEA 708 DTV & NTSC
This option causes up to eighteen closed captioning characters to be inserted into picture header user data fields in display order and up to two closed captioning characters to be added to the NTSC channel in your selected field. When converting text to CEA-708 data, DTV Window 0 will be initialized and enabled. Your closed captioning text will be written to this window at the specified time. This option causes the same closed captioning text to be written to both the CEA-708 window and the NTSC channels.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 47 41 39 34
CEA 608 (default)
This option causes up to two closed captioning characters to be inserted into picture header user data fields in transmission order. The characters will be entered into the Field 1 or Field 2 closed captioning field per your Closed Captioning Style selection.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 02 09
ATSC / CEA 608
This option causes up to two closed captioning characters to be inserted into picture header user data fields in display order. The data formatted per CEA-608 and is wrapped in a SCTE-21 and ATSC header. The characters will be entered into the Field 1 or Field 2 closed captioning fields per your Closed Captioning Style selection.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show Picture user data that will start with the Hex values: 47 41 39 34
DVD
This option causes up to 30 closed captioning characters to be inserted into GOP header user data fields. The first set of user data will be inserted at the first GOP at or after the Frame number or time code set in the EDL or DDL file. The remaining user data (over the 30 character per GOP limit) will be inserted in subsequent GOP headers. The characters will be entered into the Field 1 or Field 2 closed captioning field per your Closed Captioning Style selection.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show user data at EVERY GOP header that will start with the Hex values: 43 43 01 f8 9e. The GOP headers will contain the closed captioning data or will contain NULL data.
SCTE 20
This option causes up to two closed captioning characters to be inserted into picture header user data fields in display order. The data formatted per CEA-608 is inserted per the ANSI/SCTE 20 standard. The two captioning characters are not byte aligned and so will not be immediately recognizable when extracted in the MPEGRepairHD decode statistics. The characters will be entered into the Field 1 or Field 2 closed captioning fields per your Closed Captioning Style selection.
Analyzing the actual user data using the MPEGRepairHD Decode Statistics window will show 7 bytes of user_data in the Picture Headers that will start with the Hex values: 03 81.
Adding closed captioning to an existing stream
Closed captioning can be added to an existing elementary stream. This is accomplished using the PixelTools decode functionality in conjunction with a Decision List (ddl) a text, .scc or .cap file. The DDL file contains the closed captioning text string and the first frame number or time code where the text string will appear. The DDL file must be named Expert.ddl and must be located in the directory where your output “fixed” MPEG file is being stored. To enable processing of the Expert.ddl file, check the Decode Function Enable | Configure | Fix Stream | Use Commands in DDL file option and enter the name of the file the will include the closed captions in the Save Fixed File edit box. The CLOSEDCAPTION command in the Expert.ddl file specifies the closed captioning text string. An example of the format of the closed captioning is presented in the top of the sample Expert.ddl provided with the product. The formatted closed captioning data is added to the appropriate frame user_data fields as requested in the Expert.ddl file after depressing the Control Decode | Run button with your source file in the Decode MPEG File to Decode or Analyze edit box . You can speed up the process by depressing the Speed button with the slashed monitor to disable decode display.
The ddl file format is similar to that of the
edl file format presented above. In addition to the text strings
supported with the CLOSEDCAPTION command, any formatted user data can
be inserted via the HEXUSERDATA command. Also, the .scc closed
caption format is supported. (Be sure to rename the .scc file as Expert.ddl).
Let us know if we can help or request a free demo of our products. View our products features at a glance.
Visit our products page and check out at our PixelTools Store to purchase any of our products
Thank you for your interest in PixelTools



