MXF files can carry ancillary (ANC) data in a separate data track defined by SMPTE ST 436 (often called "436M"). Broadcast servers use it to keep the VANC content of an SDI signal together with the video: CEA-708 captions, OP-47 Teletext subtitles, SCTE-104 ad triggers, AFD and other packets.
The SDK reads this track into the frames and can write it from the frames, using the same
ANC.Line.N format as SDI devices (see ANC packets: the ANC.Line.N format).
This means you can:
- play an MXF file to an SDI output with its captions, Teletext and SCTE-104;
- record an SDI input to MXF with all its VANC packets;
- extract and inspect the ANC data of a file.
Reading
Nothing has to be enabled: when an MXF file has an ST 436 track, MFReader (MFormats) and MFile (MPlatform) add the packets of each frame to that frame. Besides the raw packets, the reader decodes the known types:
| Packet in the file | Frame metadata |
|---|---|
| Any packet |
ANC.Line.N (line 0 appears as ANC.Line) |
| CEA-708 CDP (DID 0x61, SDID 0x01) |
C708, and C608 from the CEA-608 data inside the CDP |
| SCTE-104 (DID 0x41, SDID 0x07) |
SCTE-104 (see SCTE-104 in MXF files) |
| OP-47 Teletext (DID 0x43) |
OP47_* (see OP-47 Teletext subtitles in ANC) |
MFReaderClass reader = new MFReaderClass();
reader.ReaderOpen(@"C:\media\clip.mxf", "");
for (int i = 0; i < 250; i++)
{
reader.SourceFrameGet(-1, out MFFrame frame, "");
if (frame == null)
break;
frame.MFStrGet("ANC.Line.9", out string line9); // e.g. a caption packet
if (line9 != null)
Console.WriteLine($"{i}: {line9}");
Marshal.ReleaseComObject(frame);
}
reader.ReaderClose();
Marshal.ReleaseComObject(reader);
Packets are delivered with the frame they belong to, so a frame without packets returns null.
Check every frame: a one-off packet, such as an SCTE-104 trigger, can appear anywhere in the file.
Notes:
- Packets stored with 10-bit sample coding (ST 436 coding types 7–9) are skipped.
- For exact frame-to-packet matching, read the file sequentially. After a seek to a frame that is not a key frame, the first frames can carry the packets of earlier frames until the next seek.
Recording
Add mxf.anc_write='true' to the writer configuration of an MXF OP1a file. The writer then creates an
ST 436 data track and stores the ANC.Line.N packets of each frame together with that frame.
MFWriterClass writer = new MFWriterClass();
writer.WriterSet(@"C:\media\out.mxf", 0,
"format='mxf' mxf.anc_write='true' video::codec='mpeg2video' video::b='50M' audio::codec='pcm_s24le'");
In MPlatform, pass the same string to MWriter.WriterNameSet.
The writer takes the packets from the frames, so you have three ways to fill the track:
-
From an SDI input. Capture with ANC enabled (
vanc.capture_ancon Blackmagic,capture_vancon AJA, always on DELTACAST and Bluefish) and send the captured frames to the writer. -
From another MXF file. Frames read from a file with an ST 436 track already carry
ANC.Line.N. -
From your code. Set
ANC.Line.Non each frame beforeReceiverFramePut.
Only ANC.Line.N is written to the track. Captions in C608/C708 and the
SCTE-104 XML string are not converted into packets: to store them, put the corresponding packet
into ANC.Line.N yourself (for example, the CDP on line 9).
Example: adding packets in code
using System.Xml.Linq;
static void PutFrame(MFWriterClass writer, MFFrame frame, string cdpHex, string scte104Hex)
{
if (cdpHex != null)
{
var line9 = new XElement("ANC.Line.9", Packet(0x61, 0x01, cdpHex));
frame.MFStrSet("ANC.Line.9", line9.ToString(SaveOptions.DisableFormatting));
}
if (scte104Hex != null)
{
var line12 = new XElement("ANC.Line.12", Packet(0x41, 0x07, scte104Hex));
frame.MFStrSet("ANC.Line.12", line12.ToString(SaveOptions.DisableFormatting));
}
writer.ReceiverFramePut(frame, -1, "");
}
static XElement Packet(int did, int sdid, string payloadHex)
{
return new XElement("packet", new XAttribute("DID", did), new XAttribute("SDID", sdid), payloadHex);
}
If the frame already has packets on the same line, read the line with MFStrGet, add your packet and
write the whole line back. Call WriterClose(0) after the last frame.
In MPlatform, change the frames in the synchronous OnFrameSafe event of the source in the same way.
What the writer checks
- Line numbers must exist in the frame format (up to 525, 625, 750 or 1125 lines). A line outside the format is skipped with a warning in the log.
- Each packet needs a non-zero
DID, anSDID(Type 2) orDBN(Type 1), and an even number of hexadecimal digits, at most 255 bytes. A wrong packet is skipped with a warning; the other packets of the line are written. - Line numbers, packet order and payload bytes are kept as they are. Packets are stored as 8-bit luma samples, frame-wrapped for interlaced video and progressive-frame-wrapped for progressive video.
- A frame without packets gets an empty element in the track, so the track stays aligned with the video.
Limitations
-
mxf.anc_writeis off by default and applies to MXF only; other containers ignore it. - The video must be encoded at the input frame rate. Changing the frame rate, transwrapping existing video packets and play-while-recording files are not supported.
- If the frame timestamps jump or the writer cannot keep up (more than 256 frames waiting), ANC stays empty until the writer is closed or reconfigured. Check the log for warnings.
- The ST 436 track is created only when the first stream of the file is video.
Checking the result
- Open the finished file with MFReader and compare
ANC.Line.Nof the frames with what you wrote. To see OP-47 packets as raw data only, open the file withop47.decode=false. - In MediaInfo, look for an "Ancillary data / SMPTE ST 436" track. MediaInfo also names the packet types it recognizes, such as CDP, OP-47 or SCTE-104.
Still have questions?
Tell us what didn’t work or what you’d like clarified.