Use an MWriter object in MPlatform SDK or an MFWriter object in MFormats SDK to send an MPEG Transport Stream over UDP. Configure the source, choose the container and codecs, then start supplying media to the writer.
MPlatform connects the writer to a source object. MFormats requires your application to retrieve frames from the source and submit them to the writer.
Configure the destination and encoding
A UDP destination has the form udp://hostname:port[?options]. Use a receiver address for unicast or a multicast group address for multicast. Separate URL options with &:
udp://239.1.2.3:5000?pkt_size=1316&ttl=16
Put transport options such as pkt_size in the destination URL. Put the container, codecs and encoder options in the separate encoding configuration:
format='mpegts' protocol='udp://' video::codec='mpeg2video' video::b='5M' audio::codec='aac'
Select codecs available in your writer configuration and supported by the receiver. For MP3 audio, audio::codec='libmp3lame' is an alternative when that encoder is available.
| Configuration entry | Type and meaning |
|---|---|
format |
Container name. Use mpegts for the MPEG Transport Stream examples in this article. |
protocol |
Protocol identifier; the examples retain udp://. The destination URL specifies the address and transport options. |
video::codec |
Video encoder name. |
video::b |
Video bitrate in bits per second. For example, 5M requests 5,000,000 bits per second. |
video::g |
Integer GOP size in frames. For example, 25 represents approximately one second at 25 frames per second. Encoder behavior depends on the selected codec. |
audio::codec |
Audio encoder name. |
Apply these entries through WriterNameSet in MPlatform or WriterSet in MFormats before starting the stream.
MPlatform SDK
This C# fragment assumes that myWriter is an application-owned MWriter and mySource is an MFile with its input already opened:
string myDestination = "udp://239.1.2.3:5000?pkt_size=1316";
string myConfiguration =
"format='mpegts' protocol='udp://' " +
"video::codec='mpeg2video' video::b='5M' audio::codec='aac'";
myWriter.WriterNameSet(myDestination, myConfiguration);
myWriter.ObjectStart(mySource);
mySource.FilePlayStart();
For an already running MLive source, connect it with myWriter.ObjectStart(mySource); FilePlayStart belongs to MFile. The connected writer consumes source frames without an application frame-transfer loop.
When streaming finishes, close the writer with ObjectClose() before closing the source. Arrange this cleanup in the application's error and shutdown paths, and release the COM objects your application owns.
MWriter with the XMedia backend
In a 64-bit application configured to use XMedia, set writer.engine on MWriter before WriterNameSet. Check the active backend afterward: a request for XMedia can fall back to the legacy backend when the configuration or backend is unavailable.
The following is an alternative configuration fragment for an existing writer, before connecting it to the source:
myWriter.PropsSet("writer.engine", "xmedia");
myWriter.WriterNameSet(
"udp://239.1.2.3:5000?pkt_size=1316",
"format='mpegts' protocol='udp://' " +
"video::codec='libopenh264' audio::codec='aac'");
myWriter.PropsGet("stat::writer_backend_active", out string activeBackend);
myWriter.PropsGet("stat::writer_backend_fallback_reason", out string fallbackReason);
// Inspect activeBackend before relying on XMedia-specific behavior.
// Then connect the writer and start the source as shown above.
| MWriter property | Access | Meaning |
|---|---|---|
writer.engine |
Configurable string | Requests legacy or xmedia. The default is legacy. Set before configuring a stopped writer. |
stat::writer_backend_requested |
Read-only string | The requested backend. |
stat::writer_backend_active |
Read-only string | The selected backend: legacy or xmedia. |
stat::writer_backend_fallback_reason |
Read-only string | The reason for fallback when present. It is cleared when there is no fallback reason. |
For MPEG-TS video encoding through XMedia, an omitted video::g receives a GOP size of approximately one second: the frame rate rounded up to an integer, or 25 frames when the frame rate is unavailable. An explicitly supplied value is preserved, including zero.
This provides periodic keyframes for receivers joining an active stream. It does not guarantee a one-second playback startup time: stream detection, buffering, codec settings and network delivery also affect startup. An explicit long GOP continues to apply.
MFormats SDK
This C# fragment assumes that myWriter is an existing MFWriter and myLiveSource is an opened MFLive source. Configure the writer once before the frame loop:
string myDestination = "udp://239.1.2.3:5000?pkt_size=1316";
string myConfiguration =
"format='mpegts' protocol='udp://' " +
"video::codec='mpeg2video' video::b='5M' audio::codec='aac'";
int resetPreviousConfiguration = 1;
myWriter.WriterSet(myDestination, resetPreviousConfiguration, myConfiguration);
Run frame transfer on the application's media worker. The following fragment transfers one frame; repeat it in your existing loop and handle source completion, cancellation and errors there. It uses a one-second maximum wait, expressed in 100-nanosecond units:
MFFrame myFrame = null;
try
{
((IMFSource)myLiveSource).SourceFrameGet(10_000_000, out myFrame, "");
if (myFrame != null)
((IMFReceiver)myWriter).ReceiverFramePut(myFrame, 10_000_000, "");
}
finally
{
if (myFrame != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(myFrame);
}
An opened MFReader can supply frames through the same IMFSource interface. MFWriter sends the frames submitted by your application. After the transfer worker has stopped, call myWriter.WriterClose(0) to close the output synchronously, then close the source and release the COM objects you own.
For a receiver that must join an active stream, configure a suitable video::g in the MFWriter encoding string. For example, append video::g='25' for an approximately one-second GOP at 25 frames per second. The automatic XMedia GOP policy described above applies to the selected MWriter XMedia backend; it is not an MFWriter default.
UDP URL options
These common FFmpeg UDP transport options belong in the URL query. All entries below are configurable. Sending options go on the writer destination; receiving options go on the source URL used to open the stream. Socket buffer allocation also depends on the operating system.
Socket and sending options
| Option | Type or units | Meaning and scope |
|---|---|---|
buffer_size |
Integer bytes | Requested socket buffer size: send buffer for a writer, receive buffer for a reader. This is separate from fifo_size. |
localport |
Integer port | Local UDP port to bind. |
localaddr |
IP address string | Local address/interface. Useful for multicast on a machine with multiple network interfaces. |
pkt_size |
Integer bytes | Maximum UDP packet payload size. The examples use 1316 bytes, corresponding to seven 188-byte MPEG-TS packets. |
reuse |
1 or 0
|
Explicitly allow or disallow socket reuse. |
ttl |
Integer hop limit | Time-to-live value for outgoing multicast packets. |
connect |
1 or 0
|
Connect the UDP socket to the specified peer. On output, this can surface a destination-unreachable error. On input, it restricts packets to that peer address and port. |
broadcast |
1 or 0
|
Allow or disallow sending to a broadcast destination. |
Receiving options
| Option | Type or units | Meaning and scope |
|---|---|---|
sources |
Comma-separated IP addresses | Accept multicast packets only from the listed sender addresses. |
block |
Comma-separated IP addresses | Block multicast packets from the listed sender addresses. |
fifo_size |
Integer count of 188-byte units | Size of the UDP receive circular buffer when threaded buffering is available. This is not a byte count or a count of complete UDP datagrams. |
overrun_nonfatal |
1 or 0
|
Allow receiving to continue after a receive circular-buffer overrun. The default is 0; enabling it does not recover lost packets. |
timeout |
Integer microseconds | Report an input error when no data arrives for the specified interval. This option applies to receiving. |
Receive an active stream
Open the stream URL on the receiving source. For MPlatform, configure an MFile with FileNameSet and start it with FilePlayStart. For MFormats, open an MFReader with ReaderOpen and retrieve frames through IMFSource.
A receiver joining after transmission starts needs usable stream information and a decodable video keyframe. Allow for that acquisition time, and check received video and audio rather than relying only on a successful open call or a Running state. For multicast, verify that the selected interface and network route can reach the group.
Set video and audio PIDs
For MPEG-TS output through the legacy writer path, add integer stream IDs to the encoding configuration passed to MWriter or MFWriter:
video::streamid='256' audio::streamid='257'
Choose valid, distinct PIDs for your transport stream. MWriter's XMedia adapter does not accept explicit video::streamid, audio::streamid or their pid aliases. Such a configuration can cause selection of the legacy backend; check the active-backend properties if your application requested XMedia.

Still have questions?
Tell us what didn’t work or what you’d like clarified.