C++ DirectShow 视频和音频捕获 - 开始
在应用程序开发过程中遇到一些问题后,我终于放弃了使用 VFW。
感谢 StackOverflow,我现在意识到 VFW 已经过时,并希望切换到 DShow,让我的应用程序能够在 Vista/W7 上运行。
不幸的是,工作已经完成并且应用程序已发送给客户端,但是当我们意识到 Vista / W7 上的帧速率存在问题时,我们决定重写视频类并使用 DirectShow 建立良好的音频/视频网络摄像头的捕获引擎。
这将很棘手,因为我们从未使用 DShow 进行编码,现在我们正在寻找一些具体示例,说明如何:
连接到选定的网络摄像头
类似于:capDriverConnect
将摄像头分辨率设置为 640x480 和 RGB24 格式(我们需要这样做每帧为 RGB24 到 YUV420)
类似于:capSetVideoFormat / capCaptureSetSetup
为此网络摄像头设置音频捕获
类似于:capSetAudioFormat
注册两个回调:
- 一个用于视频帧(我们将帧传递给视频编码器)
类似于:capSetCallbackOnVideoStream
- 一个用于波形缓冲区(我们将把波形缓冲区传递给音频编码器)
类似于:capSetCallbackOnWaveStream
能够在父窗口的某处显示预览窗口
类似于:capPreview
在需要时执行启动/停止操作
- 开始 - 意味着连接并开始捕获音频/视频帧
- 断开连接 - 意味着停止捕获音频视频帧
执行对实际帧的绘制
类似于:
SetBitmapBits(CameraInput.GetFrameBitmap(),w*h*3,vdhdr->lpData); // 用gdi+画一些东西 GetBitmapBits(CameraInput.GetFrameBitmap(),w*h*3,vdhdr->lpData);//用数据设置回帧
上述所有内容都已经用 VFW 完成,但正如我之前所写,不幸的是我们需要切换 do直接展示。
有没有人可以帮助我们完成一门课程,将我们从数月的 Direct Show 学习中解救出来?
I have finally managed to drop working with VFW after several problems I have encountered during the application development.
Thanks to StackOverflow, I am now aware that VFW is obsolete and wish to switch to DShow, to let my application work with Vista/W7.
Unfortunately, the work has been made and application has been shipped to the client, but as soon as we realized we have troubles with frame rates on Vista / W7 - we decided to rewrite the video class and use DirectShow to establish a good audio/video capture engine for webcameras.
This will be tricky, as we never coded with DShow, and right now we are looking for few specific examples of how to:
Connect to a selected webcamera
similar to: capDriverConnect
Set camera resolution to 640x480 and RGB24 format ( we need to do RGB24 to YUV420 for each frame )
similar to: capSetVideoFormat / capCaptureSetSetup
Set audio capturing for this webcamera
similar to: capSetAudioFormat
Register two callbacks:
- One for video frame ( we will pass frames to video encoder )
similar to: capSetCallbackOnVideoStream
- One for wave buffer ( we will pass wave buffer to audio encoder )
similar to: capSetCallbackOnWaveStream
Be able to show a preview window somewhere on parent window
similar to: capPreview
Perform Start/Stop operation when needed
- Start - would mean, connect and start capturing audio/video frames
- Disconnect - would mean, stop capturing audio video frames
Perform drawing to the actual frame
similar to:
SetBitmapBits(CameraInput.GetFrameBitmap(),w*h*3,vdhdr->lpData);
// draw something with gdi+
GetBitmapBits(CameraInput.GetFrameBitmap(),w*h*3,vdhdr->lpData);//set back the frame with data
All of the above was already made with VFW, but as I wrote before we unfortunately need to switch do Direct Show.
Is there anyone who could help us out achieving a class that could rescue us from months of studying Direct Show ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的例子是 来自 Microsoft 的示例。
你的问题仍然是用 VFW 来表述的,所以很难按书面回答。例如,在 DirectShow 中,您不会注册回调来对视频帧进行编码。相反,您需要开发一个编码器过滤器来从捕获源接收数据。
作为替代方案,如果您仅针对 Vista 及更高版本,则可以使用 微软媒体基金会。我没有这方面的经验,所以我不知道与 DirectShow 相比学习曲线如何。
Your best bet for examples will be the ones from Microsoft.
Your questions are still phrased in terms of VFW so it's hard to answer them as written. For example, in DirectShow you wouldn't register a callback for to encode a video frame. Instead, you'd develop an encoder filter that would receive data from the capture source.
As an alternative, if you're only targeting Vista and later, there is the Microsoft Media Foundation. I have no experience with it so I don't know how the learning curve compares to DirectShow.
我建议您使用 FFDshow 过滤器在 GraphEdit 上构建图表。
EditGraph 正在演示如何在 DirectShow 上构建图形,
我认为您不需要自己构建过滤器类。构建图表后,您就可以使用 GraphEdit 观看视频。实现图表是一项非常简单的任务。
I'd suggest you to build a graph on GraphEdit using FFDshow filters.
EditGraph is making a demonstration of building a graph on DirectShow
I don't think you need you build the filter class by your own. After you'll build the graph and you'd be able to watch the video using GraphEdit. Implementing the graph is a very simple task.