繁体   English   中英

将H264帧解码为Bitmap

[英]Decode H264 frame to Bitmap

我正在接收 H264 编码帧,但是当我将其转换为 bitmap 时,我只是得到一个黑屏。 决议是对的。 我已经尝试了很多东西,但找不到工作方式。 谢谢! 这是我的代码

        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);

            }
        }

H.264 是基本视频 stream 的编码,它不是单独图像的编码。

这意味着解码过程涉及视频编码的设置。 没有单个 function(至少它不应该以这种方式工作)来获取比特流和 output 视频帧。

您通常会设置 stream 解码上下文,然后在准备好时输入并拉取 output。

Windows 带有一个股票 H.264 编码器和一个典型的 API 来消费这样的解码服务是Media Foundation 它不是 .NET 的 API 因此媒体基金会使用 C#

还有媒体基金会 .NET项目,其中 C# 包装在原生媒体基金会 API 之上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM