BogdanovKirill / RtspClientSharp

Pure C# RTSP client for .NET Standard without external dependencies and with true async nature. I welcome contributions.
MIT License
706 stars 284 forks source link

Decode H264 frame to Bitmap #88

Open SpaceR3 opened 4 years ago

SpaceR3 commented 4 years ago

Hello, I cant Decode H264 frame to Bitmap \n \

        public System.Drawing.Bitmap CopyDataToBitmap(byte[] data)
        {
            //Here create the Bitmap to the know height, width and format
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap((int)2592, (int)1936, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            //Create a BitmapData and Lock all pixels to be written 
            System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(
                                 new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
                                 System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat);

            //Copy the data from the byte array into BitmapData.Scan0
            Marshal.Copy(data, 0, bmpData.Scan0, data.Length);

            //Unlock the pixels
            bmp.UnlockBits(bmpData);

            //Return the bitmap 
            return bmp;
        }
        public async void ListenVideo()
        {

            byte[] data = new byte[1024];
            IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 11111);
            UdpClient newsock = new UdpClient(ipep);
            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 11111);
            data = newsock.Receive(ref sender);
            string message = Encoding.UTF8.GetString(data, 0, data.Length);
            while (true)
            {

                data = newsock.Receive(ref sender);
                message = Encoding.UTF8.GetString(data, 0, data.Length);
                MemoryStream stream = new MemoryStream(data);
                panel1.BackgroundImage = CopyDataToBitmap(data);

                await Task.Delay(2000);

            }
        }
SpaceR3 commented 4 years ago

i just get black screen

rageshS commented 4 years ago

Is this a dead source code repository?

arthurjr07 commented 3 years ago

you can check my sample player (winforms). I am writing the frame to bitmap.

https://github.com/arthurjr07/simpleRtspPlayerWinforms