Video preview in C#

◇◆丶佛笑我妖孽 提交于 2019-12-11 13:54:25

问题


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:

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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2209255/video-preview-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!