多线程捕获视频

发布于 2024-10-08 10:53:10 字数 189 浏览 0 评论 0原文

我需要每 xxx 分钟捕获视频并将其保存到硬盘驱动器。这将是双赢的服务,永远是捕获和节省。会有多个相机,所以我认为每个相机都使用处理线程。因此,如果我决定使用 Thread 而不是计时器,我应该在保存操作之前使用 Thread.Sleep。在我看来,这不是一个好的做法。

所以问题是我的设计(每个相机的线程)适合我的情况吗?定时器呢? 谢谢,安德鲁

I need capture video and save it to hard drive every xxx minutes. It will be win-service, which is always capturing and saving. There would be several cameras, so I think use processing thread per camera. So if I decide use Thread instead of timer, I should use Thread.Sleep before saving operation. To my mind it's not good practice.

So the question is my design(thread per camera) appropriate for my situation? What about timers?
Thanks, Andrew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

安静 2024-10-15 10:53:10

由于全局互斥体(例如,在驱动程序中),您的代码可能会偶尔出现锁定。
另外,例如,您在一个线程中有打开的输入,您将其刷新到某个流,并且您想从其他线程读取它:发生互斥锁。与定时器相同。考虑到事件驱动的机器在这里很难实现,您仍然可以回退到多个实例。

Your code may get occasional lockups due to global mutex'es (for example, in driver).
Also, for example, you have open input in one thread, you're flushing it to some stream, and you want to read it from other thread: mutex lock happens. Same with timers. Considering the event-driven machine too hard to implement here, you still can fallback to multiple instances..

鹿港小镇 2024-10-15 10:53:10

您可以在 http://www.team-mediaportal 查看开源项目 Media Portal 的代码.com/

看看他们的子项目 TvEngine3。

您可以强制它将您的相机绘制为“调谐器”设备,并将其设置为通过 api 进行录制。

重点是,他们已经解决了数百个 DirectShow 问题,而且还有很多

You could have a look at the code for the open-source project Media Portal at http://www.team-mediaportal.com/

Look at their sub-project called TvEngine3.

You could force it to graph your cameras as a "Tuner" device, and set it to record via api.

Point is, they've worked out hundreds of DirectShow issues, and there are many.

风和你 2024-10-15 10:53:10

我肯定会选择每个相机一个线程,因为您使用的相机可能少于 20-30 个。但这可能不是必需的,因为读取相机(通常)是一种非阻塞操作。

SO 上有几个关于 C# 中的网络摄像头和视频的问题。尝试查看如何从网络摄像头捕获视频?

请注意,您可能需要预先分配大块数据以避免磁盘碎片。将多个流媒体视频存储到磁盘可能会造成碎片,然后观看/复制/修改视频会非常慢。

I would definitively go for one thread per camera as chances are you'd use less than 20-30 cameras. But it is probably not required as reading a camera (usually) is a non-blocking operation.

There are several questions on webcam and video in C# on SO. Try looking at How do I capture video from a webcam?

Note that you may want to pre-allocate large chunks of data to avoid disk fragmentation. Storing multiple streaming videos to disk could really fragment stuff, and then watching/copying/modifying the videos would be really slow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文