Windows音频和视频捕获软件范例 [英] Windows Audio and Video Capture Software Paradigm

查看:153
本文介绍了Windows音频和视频捕获软件范例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,该程序可以从多个音频和视频设备读取数据并将数据写入适当的容器(例如mpeg)。我已经在Linux中编写了代码,但是现在我也必须为Windows编写另一个版本。这就是我在Linux中写的方式:

I am writing a program that reads from multiple audio and video devices and writes the data to suitable containers (such as mpeg). I have wrote the code in Linux, but now I have to write another version for windows as well. This is how I wrote it in Linux:

initialize the devices (audio: ALSA, video: V4L2)
get the file descriptors
mainloop
   select on file descriptors
   respond to the proper device

不幸的是,我的专长仅是Linux,而我从未使用过Windows SDK。我不知道正确的范例是什么。人们使用fds和select的方式是否相同?在那种情况下,有没有办法从DirectShow获取fd?
哦,最后一件事,我注定只能使用一个线程来完成所有这些工作。因此,不允许同时运行多个线程并且每个线程处理一个设备的解决方案。 Linux中的代码当前也运行在一个线程上。还最好代码应使用c ++编写。谢谢。

Unfortunately my expertise is only for Linux and I have never used windows SDK. I don't know what the right paradigm is. Do people do it the same way with the fds and select? In that case is there a way to get a fd from directshow? Oh and one last thing, I am bound to use only one thread for all of this. So the solution with multiple threads running at the same time and each handling one device is not admissible. The code in Linux currently runs on one thread as well. It is also preferred that the code should be written in c++. Thank you.

第二个想法在这里只问了一个问题,那就是:一个人如何获取视频/音频的文件描述符DirectShow库中的设备。使用过V4L2和ALSA的人,我正在DirectShow中寻找相同的东西。

Second Thoughts There is only one question asked here and that is: How can one get the file descriptor of the video/audio device from DirectShow library. People who have worked with V4L2 and ALSA, I am looking for the same thing in DirectShow.

推荐答案

罗马是这些方面的专家主题,我认为您找不到更好的答案。
要添加到Roman的答案中,您可以在DirectShow中执行以下操作:

Roman is an expert in these topics and I don't think you'll find a better answer. To add to Roman's answer, you would do something like this in DirectShow:

Enumerate video/audio capture devices/select capture device
Construct DirectShow graph
  Add video and audio capture source filters to graph
  Add 2 sample grabbers to graph
  Configure sample grabber callbacks 
  Connect capture source filters to samples grabbers
  Add renderers to graph (This could be a null renderer or a video/audio renderer)
  Connect sample grabbers to renderers
Play graph
Run the event loop
DirectShow will invoke the callbacks per media sample traversing the graph.

您的图表通常如下所示:

Your graph would typically look like this:

                callback
                   |
Video capture -- sample grabber -- renderer

Audio capture -- sample grabber -- renderer
                   |
                 callback

如Roman所说,SDK中有许多示例显示了

As Roman said, there are many samples in the SDK showing how to


  • 枚举捕获源

  • 使用/配置样本采集器

  • 编写一个可在其中构建和播放图形的应用程序

关于线程主题,您将为主应用程序线程,而DirectShow将处理内部线程管理。但是请注意,如果您的回调函数处理量大,则可能会干扰播放,因为(来自 MSDN ):

On the topic of threading, you'll be writing the code for the main application thread, and DirectShow will handle the internal thread management. However note that if your callback function is processing intensive, it may interfere with playback since (From MSDN):


数据处理线程一直阻塞,直到回调方法返回为止。如果回调没有快速返回,则可能会干扰播放。

The data processing thread blocks until the callback method returns. If the callback does not return quickly, it can interfere with playback.

根据您的应用程序要求,这可能重要也可能不重要。如果很重要,您可以例如将数据传递到另一个线程进行处理。阻塞数据处理线程的结果是,对于视频,您将获得较低的帧速率。

This may or may not be important depending on your application requirements. If it is important you could e.g. pass the data to another thread for processing. The result of blocking the data processing thread is that you'll get lower framerates in the case of video.

这篇关于Windows音频和视频捕获软件范例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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