Search code examples
c#uwpmjpeg

How do I display MJPEG stream in UWP


I have a video stream that comes as MJPEG over HTTP.

I tried to use MjpegProcessor using https://channel9.msdn.com/coding4fun/articles/MJPEG-Decoder link.

As per the instructions provided I have referenced MjpegProcessor.winmd dll in my project. But it seems that FrameReady event doesn't have Bitmap/BitmapImage member. What I am doing wrong? Is their any other way to stream MJPEG in UWP?


Solution

  • Yeah, there is no Bitmap/BitmapImage in FrameReadyEventArgs in UWP. In UWP apps, we should use FrameBuffer property like following:

    private async void mjpeg_FrameReady(object sender, FrameReadyEventArgs e)
    {
        using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
        {
            await ms.WriteAsync(e.FrameBuffer);
            ms.Seek(0);
    
            var bmp = new BitmapImage();
            await bmp.SetSourceAsync(ms);
    
            //image is the Image control in XAML
            image.Source = bmp;
        }
    }