View Full Version : Capturing AVI through DirectShow
dvd_
12th February 2009, 21:59
I built a filter graph in my application and im capturing video to an AVI file using a capture device.
one requirement is to split the recorded AVI file into segments of fixed size.
what's the best approach to do so?
my current solution is to create a thread that checks periodically the AVI file size, and when it exceeds a fixed value - to stop the recording and restart it in a new AVI file (segment).
the trouble with this solution is that it doesnt always work as expected: i think its because of the frequency that windows reports the new file size. for example, for about 10 seconds after the recording had started - windows still reoprts the file size as 0. only after those 10 seconds it updates its size.
is there a better way to implement the division to segments?
thanks
Nick
12th February 2009, 22:27
If you are taking filesize to mean as in a fixed number of megabytes per file, why not capture to a single file then use AviChop (http://www.softpedia.com/get/Multimedia/Video/Video-Editors/AviChop.shtml) to cut it into segments?
dvd_
12th February 2009, 22:34
it needs to be done on-the-fly.
JohnnyMalaria
13th February 2009, 00:01
If you are programming DirectShow then one option is to write your own custom filter that acts as a pass-through filter but counts the number of frames passed and fires an event to your application (or just sets a Win32 event). That's what we do in one of our applications (it fires an event every time a new frame arrives). Your application would then stop the capture, change the output file for the File Writer filter and start capturing again (no need to rebuild the graph). This can occur within less than the duration of a frame depending on exactly how you implement things.
Use the in-place transform filter example in the SDK as a starting point. Fire the event from within your IBaseFilter::Transform() implementation.
dvd_
13th February 2009, 07:41
If you are programming DirectShow then one option is to write your own custom filter that acts as a pass-through filter but counts the number of frames passed and fires an event to your application (or just sets a Win32 event). That's what we do in one of our applications (it fires an event every time a new frame arrives). Your application would then stop the capture, change the output file for the File Writer filter and start capturing again (no need to rebuild the graph). This can occur within less than the duration of a frame depending on exactly how you implement things.
Use the in-place transform filter example in the SDK as a starting point. Fire the event from within your IBaseFilter::Transform() implementation.
thanks. that's a great a starting point.
i'll look more into it.
dvd_
13th February 2009, 13:55
two followup questions:
1. i understand that creating a filter will give me the ability to control the incoming frames, but will i be able to read the file size correctly?
my goal is to divide the avi file to fixed size segments, and for instance 10000 frames could result in file size X under a certain codec and file size Y != X under a different codec.
2. can the IAsyncReader interface help me in terms of getting the current recorded stream length?
JohnnyMalaria
13th February 2009, 14:31
1. You can get the raw size of each frame from the IMediaSample interface each time Transform() is called. Summing these will give you a reasonable approximation of the output file size but it won't be exact since there will be the AVI header and index entries that add to the size. You may be able to call a WIN32 API function to get the current size of the file if you need byte accuracy (I don't know if you will run into the 10 second issue you described, though).
2. Do you mean IAsyncReader? I thought your source was a capture device? If you source is an AVI file then you can get the information for the start/stop/duration etc via the IMediaControl() interface (I think it's that one or possibly IMediaSeeking()). If the source is something else like MPEG or raw DV then you have to estimate the duration when the file is opened.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.