Search code examples
streamuwpmjpegdecoder

MJPEG stream decoder for Universal Windows Platform app


I'm working on a UWP app for school where I'm trying to display a MJPEG stream from my raspberry pi in the application. All the available decoders seem to work for windows phone 8.1 but not for the new UWP apps.

Is there anything I can do to use these streams in my application?

If not, is there a tool I can use to convert the streams and stream them on another port in the right format? This can be for raspberry or just windows.

Thanks in advance


Solution

  • Here is a MJPEG Decoder that supports UWP apps. To use it, we can download MJPEG Decoder Binaries and then reference MjpegProcessor.winmd in the project.

    After this, we can use following code to display the MJPEG stream.

    public sealed partial class MainPage : Page
    {
        private MjpegDecoder mjpegDecoder;
    
        public MainPage()
        {
            this.InitializeComponent();
            mjpegDecoder = new MjpegDecoder();
            mjpegDecoder.FrameReady += mjpeg_FrameReady;
        }
    
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            mjpegDecoder.ParseStream(new Uri("URI HERE"));
        }
    
        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;
            }
        }
    }