If your captions come from your own system (a live transcription service, a script, a database), you can turn the text into CEA-608 data and put it on the frames. The SDK then sends the captions to SDI outputs and embeds them into files and streams like captions from any other source.
The SDK installation includes complete examples:
- MFormats:
Samples\MFormats\C#\Sample CC608 ANC Sender - MPlatform:
Samples\MPlatform.Basic\C#\ANC CC608 Sender Sample
How CEA-608 works
CEA-608 is a slow, simple stream: each frame carries two bytes per field. A pair of bytes is either two characters or one command. The caption decoder in the receiver executes the commands and draws the characters.
- Characters are mostly ASCII 0x20–0x7E. A few codes are different from ASCII, for example 0x2A is "á", 0x5C is "é", 0x7E is "ñ".
- Commands start with a byte 0x10–0x1F. The first byte also selects the caption channel. For channel CC1 it is mostly 0x14.
- Odd parity: bit 7 of every byte is a parity bit, so that each byte has an odd number of 1-bits. The receiver ignores bytes with wrong parity.
- Padding: when there is nothing to send, the pair is 0x80 0x80 (two null characters with parity).
- Redundancy: commands are usually sent twice in a row, in two consecutive frames. The receiver executes the command once.
At 30 frames per second, one channel carries about 60 characters per second, so a caption must be prepared before it needs to appear.
Caption modes
- Pop-on: the text is written into a hidden memory and shown at once with a command. Used for prerecorded programs. This article uses this mode.
- Roll-up: the text appears as it arrives, on the bottom 2–4 rows, which scroll up. Used for live programs.
- Paint-on: the text appears character by character in place.
Useful commands for CC1
| Command | Bytes without parity | Bytes with parity | What it does |
|---|---|---|---|
| RCL – resume caption loading | 14 20 | 94 20 | Start pop-on mode: following text goes into hidden memory |
| ENM – erase non-displayed memory | 14 2E | 94 AE | Clear the hidden memory |
| EOC – end of caption | 14 2F | 94 2F | Show the hidden memory (swap hidden and displayed) |
| EDM – erase displayed memory | 14 2C | 94 2C | Remove the caption from the screen |
| RU2 / RU3 / RU4 – roll-up | 14 25 / 14 26 / 14 27 | 94 25 / 94 26 / 94 A7 | Start roll-up mode with 2, 3 or 4 rows |
| CR – carriage return | 14 2D | 94 AD | Roll-up: move the text up one row |
| BS – backspace | 14 21 | 94 A1 | Delete the last character |
| PAC – row 14, column 0, white | 14 50 | 94 D0 | Put the cursor at the start of row 14 |
| PAC – row 15, column 0, white | 14 70 | 94 70 | Put the cursor at the start of row 15 (the bottom row) |
A PAC (preamble address code) places the cursor. The screen has 15 rows of 32 characters. For other rows, columns, colors and channels, see the CEA-608 standard.
Example: "Hello World!" as a pop-on caption
| Frame | Pair (with parity) | Meaning |
|---|---|---|
| 1, 2 | 94 20 | RCL, sent twice |
| 3, 4 | 94 AE | ENM, sent twice |
| 5, 6 | 94 70 | PAC row 15, sent twice |
| 7 | C8 E5 | "He" |
| 8 | EC EC | "ll" |
| 9 | EF 20 | "o " |
| 10 | 57 EF | "Wo" |
| 11 | F2 EC | "rl" |
| 12 | 64 A1 | "d!" |
| 13, 14 | 94 2F | EOC, sent twice – the caption appears |
| 15 … | 80 80 | Nothing to send |
To remove the caption later, send EDM (94 2C) twice.
Putting the bytes on the frames
The frame data key C608 holds 4 bytes: the pair for field 1 and the pair for field 2. Channels CC1 and CC2
are in field 1; field 2 (CC3, CC4) is usually 0x80 0x80. Set C608 on every frame, including
0x80 0x80 when there is nothing to send, so that the caption stream on the output is continuous.
The following class builds the pairs and gives one pair per frame:
using System.Collections.Generic;
class Cea608PopOnEncoder
{
private readonly Queue<byte[]> _pairs = new Queue<byte[]>();
// Odd parity: bit 7 is set when bits 0..6 have an even number of ones
private static byte Parity(int value)
{
int b = value & 0x7F;
int ones = 0;
for (int i = 0; i < 7; i++)
ones += (b >> i) & 1;
return (byte)(ones % 2 == 0 ? b | 0x80 : b);
}
private void Command(int b1, int b2)
{
byte[] pair = { Parity(b1), Parity(b2) };
_pairs.Enqueue(pair);
_pairs.Enqueue(pair); // commands are sent twice
}
// Shows up to 32 characters on the bottom row
public void Show(string text)
{
if (text.Length > 32)
text = text.Substring(0, 32);
if (text.Length % 2 != 0)
text += " ";
Command(0x14, 0x20); // RCL
Command(0x14, 0x2E); // ENM
Command(0x14, 0x70); // PAC: row 15, column 0
for (int i = 0; i < text.Length; i += 2)
_pairs.Enqueue(new[] { Parity(Char608(text[i])), Parity(Char608(text[i + 1])) });
Command(0x14, 0x2F); // EOC: display
}
public void Clear()
{
Command(0x14, 0x2C); // EDM
}
// 4 bytes for the C608 key of the next frame
public byte[] NextFrame()
{
byte[] field1 = _pairs.Count > 0 ? _pairs.Dequeue() : new byte[] { 0x80, 0x80 };
return new byte[] { field1[0], field1[1], 0x80, 0x80 };
}
private static int Char608(char c)
{
return c >= 0x20 && c <= 0x7E ? c : '?'; // keep it simple: basic ASCII only
}
}
MFormats
var encoder = new Cea608PopOnEncoder();
encoder.Show("Hello World!");
while (running)
{
reader.SourceFrameGet(-1, out MFFrame frame, "");
FrameData.RemoveCaptions(frame); // drop captions of the source, if any
FrameData.Set(frame, "C608", encoder.NextFrame());
renderer.ReceiverFramePut(frame, -1, ""); // or writer.ReceiverFramePut
Marshal.ReleaseComObject(frame);
}
FrameData is the helper from Embedding, replacing and removing captions in files and streams:
it copies a byte array into the frame with MFDataSet and frees the temporary memory.
MPlatform
m_objFile.PropsSet("object::on_frame.sync", "true");
m_objFile.PropsSet("object::on_frame.data", "true");
m_objFile.OnFrameSafe += (string channelId, object pFrame) =>
{
IMFFrame frame = (IMFFrame)pFrame;
FrameData.RemoveCaptions(frame);
FrameData.Set(frame, "C608", encoder.NextFrame());
Marshal.ReleaseComObject(pFrame);
};
The event is raised for every frame of the object, so the captions advance with the video. If the object can drop or repeat frames, the caption stream is affected in the same way.
Where the captions go
-
SDI output: the renderer sends
C608as CEA-608 in ANC, as a CDP and, in NTSC, on line 21 (seecc_outputin Configuring SDI devices). -
File or stream: enable
embed_ccon the writer (see Embedding, replacing and removing captions in files and streams). The writer also creates an SCC file next to the output by default.
Checking the result
Receive the signal with another SDK application and draw the captions with MCCDisplay (cc_type=608,
channel=1), see Previewing captions and subtitles with MCCDisplay. For an SDI input, enable caption
capture first (vanc.capture_cc on Blackmagic, capture_cc on AJA). Files can also be checked with
tools such as CCExtractor.
Still have questions?
Tell us what didn’t work or what you’d like clarified.