'LibVLCSharp Play H264 video stream in WPF

I am developing a project based on ADB to transmit mobile phone screen, and transmit H264 video stream to PC through socket, but LibVLCSharp is in a frozen screen situation after playing, the screen is always kept at the first frame, and the screen is not updated

        TCSocketServer.GetObject().streamReceiver += (byte[] buffer) =>
        {

            var media = new Media(_libvlc, new StreamMediaInput(new MemoryStream(buffer)));
            Dispatcher.Invoke(new Action(() =>
            {
                this.VideoView.MediaPlayer.Play(media);

            }));

        };

LibVLC init

LibVLC _libvlc = new LibVLC("--demux=H264", "--rawvid-fps=24");

The picture is always in the state of the first frame, and the picture cannot be updated Freeze screen

Hope my problem will be solved as I am in a hurry to develop this project



Solution 1:[1]

You can't do it that way : you would receive a byte array, and only this byte array would be read.

Do you have a Stream that represents your socket that you could use directly? An intermediate MemoryStream won't help because it would declare the size of the stream to be what's currently inside. That would work only if you had downloaded your entire video before playing it.

You could use a Pipe in-between, as shown in this (paid) sample :

https://github.com/jeremyVignelles/libvlcsharp-nonfree-samples/blob/main/Common/PipeMediaInput.cs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cube45