视频流滞后 [英] Video Stream Lag

查看:84
本文介绍了视频流滞后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速提问。我在WPF应用程序中有一个Image元素,我通过执行以下操作将视频从Kinect流式传输到此图像元素: 

Quick questions. I have an Image element in a WPF application, I am streaming the video from the Kinect to this image element by doing the following: 

bitmap = BitmapSource.Create(image.Width, image.Height, 96, 96, PixelFormats.Bgr32, null,
                    image.Bits, image.Width * image.BytesPerPixel);

image1.Source = bitmap;

它有效,但是我注意到我遇到了一些滞后问题,基本上它会冻结几秒钟我一次又一次。 

It works, however I notice I am getting some lag issues, basically it will freeze for a couple of seconds every now and again. 

我想知道是否有更高效的方式。看起来我正在以30fps创建一个新的Bitmap,将像素从平面图像复制到位图会更好吗?这样的事情: 

I was wondering if there is a more efficient way. It looks like I am creating a new Bitmap at 30fps, would it be better to copy the pixels from the planer image into the bitmap? Something like this: 

PlanarImage image = e.ImageFrame.Image;
bitmap.CopyPixels(image.Bits, image.Width * 4, 0);
image1.Source = bitmap;

其中e来自videoframeready事件。我试过这个似乎不起作用,它捕获第一帧然后图像元素永远不会刷新。 

Where e comes from the videoframeready event. I have tried this and it doesn't seem to work, it captures the first frame then the image element is never refreshed. 

思考? 

推荐答案

是的,在每一帧上创建新的位图最终会迫使垃圾收集进入,这将导致您观察到的故障。

Yes, creating new bitmaps on every frame will eventually force garbage collection to kick in, which will cause the glitching you've observed.

您对bitmap.CopyPixels的调用与您想要的完全相反。它将像素
位图复制到数组。

Your call to bitmap.CopyPixels is doing the exact opposite of what you want. It copies pixels from the bitmap to the array.

你可能想要使用WriteableBitmap类,并调用它的WritePixels方法。

You'll probably want to use the WriteableBitmap class, and call its WritePixels method.

从代码中的类和属性,我看到你正在使用SDK的Beta版本。你能否升级到Kinect for Windows SDK 1.0? SDK 1.0中的KinectColorViewer示例类(由KinectExplorer示例应用程序使用)演示了将帧复制到WriteableBitmap的
最佳做法。

From the classes and properties in your code, I see that you're using a Beta version of the SDK. Can you please upgrade to Kinect for Windows SDK 1.0? The KinectColorViewer sample class (used by the KinectExplorer sample application) in SDK 1.0 demonstrates best practices for copying frames to a WriteableBitmap.

John

K4W Dev

John
K4W Dev


这篇关于视频流滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆