Search code examples
c#uwpvideo-streamingh.264

Play UDP H.264 byte stream in UWP with MediaElement


I'm receiving an H.264 stream over UDP from a Tello drone. I want to show the video in real time in a UWP app. I've tried writing to a MemoryStream that's assigned to a MediaSource which is assigned to a MediaElement. No joy.

var mediaSource = MediaSource.CreateFromStream(_stream.AsRandomAccessStream(), "video/avc");
_mediaPlayerElement.Source = mediaSource;

Years ago I used DirectShow. I was looking at Media Foundation, but it seems like these were deprecated many years ago.

At this point I'm at a loss for ideas to try. How can I get UDP streamed H.264 to display in a UWP app?


Solution

  • UWP MediaElement has Media Foundation on its backend (Media Foundation is in good standing and it is the current low level media API in Windows including UWP). However, there is no built-in support for the protocol you are looking for. You are supposed to develop an integration layer that converts the data you have into something MediaElement can consume.

    It might be a protocol handler, for example, as you basically want to inject H.264 data and format it in Media Foundation friendly way so that MediaElement could apply standard decoder and route the content through Media Foundation pipeline to presentation. Page 12 of Media Extensions presentation should be a good reference point in terms of API used.

    Or it could also be a, presumably simpler, Media Stream Source, explained here in Building video and audio streaming apps presentation on slides 5, 20.