SCTE-35 cues are carried in MPEG transport streams as a separate data stream. The SDK reads them from TS files and network streams, and writes them into TS files and streams. Each cue is attached to the video frame it belongs to.
Detecting cues
A frame with a cue carries two frame values:
SCTE-35– the cue as XML (see the format below);SCTE-35.PKT– the original section as raw bytes.
MFormats
reader.SourceFrameGet(-1, out MFFrame frame, "");
frame.MFStrGet("SCTE-35", out string cue);
if (!string.IsNullOrEmpty(cue))
Console.WriteLine(cue);
frame.MFDataGet("SCTE-35.PKT", out int size, out long pointer);
if (pointer != 0 && size > 0)
{
byte[] section = new byte[size];
Marshal.Copy(new IntPtr(pointer), section, 0, size);
}
Marshal.ReleaseComObject(frame);MPlatform
MFile and MPlaylist raise the SCTE-35 event when a frame with a cue passes. The event parameter holds the XML:
m_objFile.PropsSet("object::on_event.sync", "true");
m_objFile.OnEvent += OnFileEvent;
void OnFileEvent(string channelId, string eventName, string eventParam, object eventObject)
{
if (eventName == "SCTE-35")
{
string cue = eventParam;
// act on the cue
}
if (eventObject != null)
Marshal.ReleaseComObject(eventObject);
}Events are normally raised on a separate thread so that they do not slow down playback. For cues, timing matters, so set object::on_event.sync to true: the event is then raised in the playback thread together with the frame. Keep the handler short. You can also read the frame values in OnFrameSafe, as in MFormats.
XML format
The XML follows the structure of the SCTE-35 section. The root element is SpliceInfoSection; it holds one command element and, optionally, descriptors. Times are in 90 kHz ticks (90000 = 1 second).
| Element | Main attributes |
|---|---|
SpliceInfoSection | protocolVersion, ptsAdjustment, tier |
SpliceInsert | spliceEventId, spliceEventCancelIndicator, outOfNetworkIndicator, spliceImmediateFlag, uniqueProgramId, availNum, availsExpected; child Program (or Component componentTag) with SpliceTime ptsTime; child BreakDuration autoReturn duration |
TimeSignal | child SpliceTime ptsTime |
SpliceNull, SpliceSchedule, BandwidthReservation, PrivateCommand | Other commands |
SegmentationDescriptor | segmentationEventId, segmentationEventCancelIndicator, segmentationDuration, segmentationTypeId, segmentNum, segmentsExpected; child SegmentationUpid segmentationUpidType with the UPID as text |
AvailDescriptor, DTMFDescriptor, TimeDescriptor | Other descriptors |
Example: time_signal with a segmentation descriptor
<SpliceInfoSection protocolVersion="0" ptsAdjustment="0" tier="4095">
<TimeSignal>
<SpliceTime ptsTime="4668253151"/>
</TimeSignal>
<SegmentationDescriptor segmentationEventId="1" segmentationEventCancelIndicator="0"
segmentationTypeId="52" segmentNum="1" segmentsExpected="1"
segmentationDuration="2700000">
<SegmentationUpid segmentationUpidType="1">000093551531446</SegmentationUpid>
</SegmentationDescriptor>
</SpliceInfoSection>Segmentation type 52 (0x34) is "provider placement opportunity start"; the duration is 30 seconds.
Example: 30-second break (splice_insert)
<SpliceInfoSection protocolVersion="0" ptsAdjustment="0" tier="4095">
<SpliceInsert spliceEventId="1001" spliceEventCancelIndicator="0" outOfNetworkIndicator="1"
spliceImmediateFlag="0" uniqueProgramId="1" availNum="0" availsExpected="0">
<Program>
<SpliceTime/>
</Program>
<BreakDuration autoReturn="1" duration="2700000"/>
</SpliceInsert>
</SpliceInfoSection>Inserting cues
Enable cue output on MFWriter or MWriter with embed_scte35, as a property or in the configuration:
writer.WriterSet("udp://239.0.0.1:1234", 0,
"format='mpegts' embed_scte35='true' video::codec='mpeg2video' video::b='5M' audio::codec='aac'");Then put the XML on the frame where the cue must be sent:
// MFormats
frame.MFStrSet("SCTE-35", cueXml);
writer.ReceiverFramePut(frame, -1, "");
// MPlatform: in the synchronous OnFrameSafe event of the source
((IMFFrame)pFrame).MFStrSet("SCTE-35", cueXml);Rules:
embed_scte35works for MPEG-TS outputs: TS files, TS over UDP and SRT, RTP withformat='rtp_mpegts', and HLS. The program map gets the SCTE-35 stream (stream type 0x86, registration "CUEI").- The PID of the SCTE-35 stream is chosen automatically. Set
scte35_pidto use a specific PID (0x0020–0x1FFA); if it is taken, the next free PID is used and a warning is logged. - The cue is sent with the video frame that carries it, with the same timestamp.
- In a
SpliceInsert, aProgram/SpliceTimewithoutptsTimegets the PTS of that frame. ATimeSignalwithoutptsTimehas no time. - The encoded section must be shorter than 184 bytes; longer cues are dropped.
- If the frame has
SCTE-35.PKTbut noSCTE-35string, the raw section is sent as it is, without any change to its times.
Passing cues through
When the source of the writer is a transport stream, its cues are already on the frames. Enable embed_scte35 on the writer and they are sent again. The writer encodes the cue again from the SCTE-35 XML, so the times follow the new stream.
The XML does not hold every detail of a complex section (for example, repeated descriptors of the same kind are merged). If you need the original bytes, remove the XML on each frame with frame.MFStrSet("SCTE-35", null): the writer then sends SCTE-35.PKT unchanged. Times in the raw section are not adjusted, so use this only when the output keeps the timestamps of the input.
Samples
The SDK includes Samples\MFormats\C#\SCTE-35 Receive Sample and SCTE-35 Transmit Sample.
Still have questions?
Tell us what didn’t work or what you’d like clarified.