Besides video and audio, every frame in MFormats and MPlatform carries side data: closed captions, ancillary (ANC) packets, Teletext, SCTE triggers and service values. Sources put this data on the frame, and renderers and writers take it from the frame. Your application can read, change, add or remove it on any frame it has access to.
This article explains the four methods of IMFFrame that work with side data and lists the keys that the SDK uses.
Strings and binary data
Side data is stored by name (a key) and comes in two kinds:
| Kind | Read | Write | Used for |
|---|---|---|---|
| String | MFStrGet(key, out string value) |
MFStrSet(key, value) |
XML descriptions of ANC packets and SCTE messages, decoded text |
| Binary | MFDataGet(key, out int size, out long pointer) |
MFDataSet(key, size, pointer) |
Caption packets (CEA-608, CEA-708), raw SCTE-35 sections |
A few rules apply to both kinds:
- A missing key is not an error:
MFStrGetreturnsnull, andMFDataGetreturns a zero pointer. -
MFDataSetcopies the buffer. You can free your memory right after the call. - The pointer returned by
MFDataGetpoints into the frame. Copy the data before you release the frame. - To remove a string, pass
null:MFStrSet(key, null). To remove binary data, pass a negative size:MFDataSet(key, -1, 0). - Metadata belongs to one frame. A value that must be repeated (for example, a caption byte pair on every frame) must be set on every frame.
Reading and writing in MFormats
In MFormats you hold each frame in your own code, so you can read or change metadata between SourceFrameGet and ReceiverFramePut:
using System;
using System.Runtime.InteropServices;
using MFORMATSLib;
MFFrame frame = null;
try
{
reader.SourceFrameGet(-1, out frame, "");
// String metadata
frame.MFStrGet("SCTE-35", out string scte35Xml);
// Binary metadata
frame.MFDataGet("C608", out int size, out long pointer);
if (pointer != 0 && size > 0)
{
byte[] cc608 = new byte[size];
Marshal.Copy(new IntPtr(pointer), cc608, 0, size);
}
// Write metadata before the frame goes to a renderer or writer
frame.MFStrSet("ANC.Line.9", "<packet DID='0x52' SDID='0x01'>0102030405</packet>");
renderer.ReceiverFramePut(frame, -1, "");
}
finally
{
if (frame != null)
Marshal.ReleaseComObject(frame);
}Reading and writing in MPlatform
In MPlatform, frames pass between objects inside the SDK. Use the OnFrameSafe event of the object whose frames you need (MFile, MPlaylist, MLive, MMixer and others). To change a frame and have the change go further down the pipeline, the event must be synchronous and must carry the frame data:
using MPLATFORMLib;
using MFORMATSLib;
m_objFile.PropsSet("object::on_frame.sync", "true"); // the pipeline waits for your handler
m_objFile.PropsSet("object::on_frame.data", "true"); // the event receives the frame
m_objFile.OnFrameSafe += OnFrameSafe;
void OnFrameSafe(string bsChannelID, object pMFrame)
{
IMFFrame frame = (IMFFrame)pMFrame;
try
{
frame.MFStrGet("SCTE-35", out string scte35Xml);
frame.MFStrSet("ANC.Line.9", "<packet DID='0x52' SDID='0x01'>0102030405</packet>");
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pMFrame);
}
}Keep the handler short: with on_frame.sync=true the object waits for it on every frame. For a console application or a service without a message loop, also set object::events.use_window to false.
Keys reference
Ancillary data
| Key | Kind | Content | Details |
|---|---|---|---|
ANC.Line.N |
String | ANC packets of SDI line N as XML | ANC packets: the ANC.Line.N format |
HANC.Line.N |
String | Horizontal ANC packets of line N (AJA capture only) | Configuring SDI devices |
VANC.Lines, HANC.Lines
|
String | List of the lines that carried packets on this frame (AJA capture only) | Configuring SDI devices |
VANC |
Binary | Raw VANC lines of a Blackmagic capture, for transparent pass-through to a Blackmagic output | Configuring SDI devices |
Closed captions and XDS
| Key | Kind | Content |
|---|---|---|
C608 |
Binary, 4 bytes | CEA-608 byte pairs of this frame: bytes 0–1 for field 1 (CC1, CC2), bytes 2–3 for field 2 (CC3, CC4, XDS). Bytes include the odd parity bit. |
C708 |
Binary | Caption Distribution Packet (CDP, SMPTE 334-2) preceded by the 4-byte tag ccdp. Present when the source carries a CDP, even if the CDP holds only CEA-608 data. |
GA94 |
Binary | ATSC A/53 caption user data (as found in MPEG-2 and H.264 video) preceded by the 4-byte tag GA94
|
ATSC |
Binary | Legacy name for ready-made A/53 user data. Writers use it before GA94 and C708 when it is present. Do not use it in new code. |
XDS |
String | Decoded XDS information (program name, V-Chip rating). Added by MCCDisplay. |
See About closed captions for the meaning of each format and the way the SDK chooses between them.
Subtitles and Teletext
| Key | Kind | Content |
|---|---|---|
OP47_TEXT, OP47_PAGE_LIST, OP47_PAGE_NUMBER and other OP47_*
|
String | Decoded OP-47 Teletext. See OP-47 Teletext subtitles in ANC. |
SUB_TEXT, SUB_XML
|
String | Subtitle show and hide events (Teletext, OP-47 with op47.subtitles=true) |
SUB_TEXT_SNAPSHOT |
String | Text of SRT/ASS subtitles visible on this frame; empty between cues |
DVB-OCR |
String | Text recognized from DVB bitmap subtitles when subtitle.ocr is enabled |
SCTE-35 and SCTE-104
| Key | Kind | Content |
|---|---|---|
SCTE-35 |
String | SCTE-35 splice information section as XML. Read from transport streams, written by MFWriter/MWriter with embed_scte35=true. |
SCTE-35.PKT |
Binary | The same SCTE-35 section as raw bytes |
SCTE-104 |
String | Parsed SCTE-104 message from SDI or MXF. On output, a message to send in VANC. |
SCTE-104-invalid |
String | SCTE-104 packet that could not be parsed (Blackmagic capture) |
See About SCTE-35 and SCTE-104.
Other keys
| Key | Kind | Content |
|---|---|---|
SRMT_START_TIME |
String | Original start time of the frame in the source, in 100-ns units, before rate or time changes. Divide by 10,000,000 to get seconds. |
__crc32_ |
Binary | CRC32 of the frame video. The value is returned in the pointer argument. |
hwtm_abs, hwtm
|
Binary | Blackmagic capture only: hardware time of the frame in 100-ns units (absolute and relative to the first frame). The value is returned in the pointer argument with size 0. Use it to match frames of several Blackmagic inputs. |
unix_utc |
String | Time in milliseconds since 1 January 1970 (UTC) when the frame entered MDelay. Added only when mdelay.add_mark_unix_utc=true. |
MFPrint.X, MFPrint.Y, MFPrint.Width, MFPrint.Height
|
String | Position and size of the text block drawn by the last MFPrint call on this frame |
Licensing
Captions, Teletext and SCTE data require a license with the Closed Captions option. Without it, the SDK removes C608, C708, GA94, SCTE-104, SCTE-35, SCTE-35.PKT, SUB_TEXT_SNAPSHOT and decoded Teletext from frames, so they are neither delivered to your code nor output. ANC.Line.N strings are not affected.
Still have questions?
Tell us what didn’t work or what you’d like clarified.