1

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

Andrew Kalashnikov
  • 3,073
  • 5
  • 34
  • 57
  • 2
    How are you capturing the video? which APIs are you using? I am asking because if you use DirectShow, then you can record live video without even blocking current thread. – Gerardo Grignoli Dec 19 '10 at 00:50
  • Yes I use DirectShowNet library. What do u mean without blockng. How should i flush strean to disk every 5 minutes. – Andrew Kalashnikov Dec 19 '10 at 18:09

3 Answers3

0

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..

kagali-san
  • 2,964
  • 7
  • 48
  • 87
  • I think we must assume that 1) the drivers are thread safe and 2) that the programmer is capable of implementing threads (with considerations for mutexes and deadlocks). At least have something to back up the assumption that drivers are not thread safe. :) – Tedd Hansen Feb 22 '11 at 10:20
0

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.

servermanfail
  • 2,532
  • 20
  • 21
0

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.

Community
  • 1
  • 1
Tedd Hansen
  • 12,074
  • 14
  • 61
  • 97