views:

548

answers:

3

I am working in C# and have the need to capture individual frames of video files. As quickly as possible (faster than real-time), I wish to seek to a specific frame number and capture every nth frame to a graphic file format such as BMP or JPEG. It is highly desired that the frame that is captured be predictable and repeatable, i.e. do not drop frames.

I have some experience with DirectShow, but do not know if this technology is the best to use for this problem in a modern Windows .NET environment. Ideally, I would like to find a .NET or COM-based library to abstract away as much as possible. I have no need to actually display the video file on screen, and in fact would prefer not to have a Windows user interface for video playback.

Does anyone have suggestions for technologies or specific products to look into? They would need to be compatible with MPEG-2 and MPEG-4 based video files, including DivX. QuickTime support would be a nice bonus.

A: 

Aloha

The (free) program Image Grabber II.net does exactly what you describe. I seem to remember the source was also published but cannot find it now. It requires the .NET framework.

-Edoode

edosoft
Thanks for the suggestion, I could not find the source code either.
Jeremy
+2  A: 

I don't see the reason why you need to do this "faster than real-time" since you're considered doing some kind processing and not displaying any video.

I've written something similar using DirectShow.Net and .Net 2.0. Using directshow will require a bit of prior experience, or else you'll have quite a hard time trying out.

You can also access the IMediaDet interface from windows to do the frame capture. This method is simpler but there's certain limitation to it, such as MPEG2 support. I've notice that it also doesn't support "some" flv. Check out the sample at CodeProject - FrameGrabber

Quicktime support will mean installing QuickTimeAlternative

I can post the code I've written using DirectShow.Net. Let me know if you need it (I need to beautify it before posting :P ).

EDIT: NOTE: As for your "predictable" capture, there's no issue at all, as the video is not being playback at real-time, but paused, so you can seek to any point, and then extract the frame.

faulty
It appears DirectShow is the winner. Thanks for the links. I need faster than real time because I want to do additional processing on the images in the video as quickly as possible and the frame capture is part of the time the user is waiting. :)
Jeremy
In that case, you can always upgrade to faster hardware. Normally real-time implies that it's critically time sensitive. As for your case, it's just the matter of how long your user is waiting. Well, you can always entertain them with a progress bar. Do you need the code for DirectShow?
faulty
I managed to get something working with DirectShow.NET, thanks! This project is challenging because I must use DirectShow from a Windows service environment, no GUI, I have to fake my own message pump, etc.
Jeremy
A: 

Just in case someone else has this type of problem, another option is a Delphi-based ActiveX control called TVideoGrabber. Though it is not free, it is very inexpensive and does nicely as a thin wrapper around DirectShow.

TVideoGrabber is an awkward fit for my problem since my application has no GUI--it is running as a Windows service. I do have it working, but instantiating multiple controls (that may not be thread safe to start with) and running in a fake event loop, from .NET, as a Windows service... well there are several things that could go wrong. Even though I have ensured the controls are only manipulated from the creating thread, I still seem to have concurrency problems. But that's another question... :)

Jeremy