I need capture video and save it to hard drive every xxx m开发者_如何学Pythoninutes. 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
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..
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.
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.
精彩评论