开发者

Video preview in C#

I have a webcam capture a开发者_StackOverflowpp 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:

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

  • 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() 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() 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?


This InteropBitmapRenderer I wrote might help you. Though I have it hard coded for RGBA (32bit). Not sure how it works with RGB24 as I think WPF pre-3.51 had issues with 24bit.

If your webcam supports DirectShow, you can use my WPF MediaKit and use the VideCaptureElement to display a webcam.


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.

Hope I could help you.

Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜