2008-01-28

Grab one sample using DirectX

ISampleGrabber:: SetCallback
SetOneShot

ImediaDet::GetBitmapBits


#include "AtlBase.h" // For atl smart pointers
#include "dShow.h" // DirectShow header
#include "Qedit.h" // SampleGrabber filter


====
http://www.codeproject.com/KB/audio-video/VideoAnaFramework.aspx

1. IMediaDet
Maybe this is the most easy to use solution. There is an article that demonstrates this, which is unluckily written in Chinese. Readers of my article will probably not understand that one. The main idea of this approach is:

(1) Create an instance of the IMediaDet interface.
(2) Open a video file.
(3) Enumerate all streams from the video using get_OutputStreams() and find the video stream.
(4) Get information regarding the video stream, e.g. duration or the frame image size.
(5) Use GetBitmapBits() to obtain the frame image at some specified media time, or WriteBitmapBits() if you simply save a snapshot of that frame to a file.

Perhaps this is the simplest way to enumerate all of the frames of a video file. Unfortunately, its performance is not satisfying, as I mentioned before.

2. ISampleGrabber, one shot mode

There is a good article demonstrating this approach. It is not much more difficult to use than using IMediaDet, but its performance is also not much better. The advantages of using this over IMediaDet are:

(1) Easy of use.
(2) Ease of process control, as you can freely jump to any part of the video or just finish the job.

So, this is suitable for just getting some snapshots from the video.

3. Write a transform filter

By writing your own transform filter, you can just do your job inside the DirectShow framework. This approach is the most powerful and efficient one. On the other hand, you need to know DirectShow quite well to get it work. It is also quite difficult to realize a transform filter. There are several MSDN articles explaining how to write a transform filter, as well as an example realizing a sample grabber trans-in-place filter. Note that the demonstrated sample grabber here is quite like ISampleGrabber, working in callback mode and not in one-shot mode. This seems too difficult for me, however, and there appears to be too many things to consider for I'm just a green hand at DirectShow. In the end, I decided not to use this.


4. Alternatives to DirectShow

As far as I know, there is another widely used framework that may complete my task: OpenCV. OpenCV is a well known open-source and cross-platform computer vision library, of which video tasks are merely a small part. I just came up with some build problems with it initially, but maybe I should look into it later.

No comments:

Post a Comment