C#中的视频预览 [英] Video preview in C#

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

问题描述

我有一个网络摄像头捕获应用程序,我正在尝试在我的 WPF UI 中实现视频预览.捕获发生在 C++ DLL 中.我有一个当前的解决方案,但我对它不太满意.主要目标是 UI 中的视频预览不会过多地干扰 C++ DLL,因为它必须压缩视频帧并将它们写入磁盘.我将无法显示每一帧,因为压缩会占用大量 CPU.

I have a webcam capture app and I'm trying to implement a video preview in my WPF UI. Capturing happens in a C++ DLL. I have a current solution but I'm not too happy with it. The main goal is that the video preview in the UI doesn't interfere with the C++ DLL much, as it has to compress the video frames and write them to disk. I won't be able to display every frame, because the compression is fairly CPU-intensive.

我目前的视频预览解决方案是:

My current video preview solution is:

  • 我的窗口中使用了一个 Image 控件,它的 Source 属性数据绑定到一个名为 VideoPreviewSource 的 BitmapSource

  • An Image control is used in my window, and its Source attribute is data-binded to a BitmapSource called VideoPreviewSource

我设置了一个 System.Threading.TimerCallback 来更新我的预览.计时器回调函数分派到可以更新 UI(使用 this.Dispatcher.BeginInvoke)的线程,该线程调用 UpdatePreview()

I set up a System.Threading.TimerCallback to update my preview. The timer callback function dispatches to a thread which can update the UI (using this.Dispatcher.BeginInvoke) which calls UpdatePreview()

UpdatePreview() 向 C++ DLL 请求视频帧.对 DLL 的调用将图像的原始数据放在 byte[] _rawImageData 中,我在窗口的构造函数中分配了一次.

UpdatePreview() asks the C++ DLL for a video frame. The call to the DLL puts the image's raw data in byte[] _rawImageData, which I allocate once in my window's constructor.

UpdatePreview() 然后将 VideoPreviewSource 设置为: BitmapSource.Create(width, height, 96, 96, pf, null, _rawImageData, width * 4);最后调用 OnPropertyChanged("VideoPreviewSource").

UpdatePreview() then sets VideoPreviewSource to: BitmapSource.Create(width, height, 96, 96, pf, null, _rawImageData, width * 4); Finally OnPropertyChanged("VideoPreviewSource") is called.

似乎如果我使计时器更频繁,垃圾收集的调用频率就会降低,并且基本上看起来像是内存泄漏.

It seems like if I make the timer more frequent, garbage collection is called less often and it basically looks like a memory leak.

有没有更好的视频预览方法?

Any better approach to a video preview?

推荐答案

我尝试了一个名为 Ozeki SIP SDK 的 SDK 和以下内容 http://www.voip-sip-sdk.com/p_93-introduction-to-ozeki-voip-sip-sdk-voip.html 提供有关如何进行视频通话的信息​​.

I tried an SDK called Ozeki SIP SDK and the followings http://www.voip-sip-sdk.com/p_93-introduction-to-ozeki-voip-sip-sdk-voip.html provide information about how to make a video call.

希望能帮到你.

问候

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

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