views:

33

answers:

3

I am writing some video files under Windows from a camera.
I need the data unaltered - not MP4's 'uncompressed' ie. no YUV, no color interpolation - just the raw camera sensor bytestream.

At the moment I am writing this direct to disk and re-reading it later to recode into a usable video. But with no header I have to keep track of image size, frame rate, color balance etc separately.

I could add a custom header but even if the actual video data is unreadable by anything other than my app, using an AVI file would at least give me a relatively standard header to store all the camera parameters and also means that resolution, length etc would show up in explorer.

Is there an easy way of generating an AVI header/footer without sending all the data through directshow or vfw? The data is coming in at >250MB/s and I can't lose any frames so I don't have time to do much more than dump each frame to disk.

edit: Perhaps MP4 would be better I have a lot of metadata about the camera config that isn't in the AVI standard

A: 

It sounds like you could really benefit from using opencv, it could probably handle alot of this nicely for you. Take a look and see if it suits your needs: http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html#videocapture

Robert Massaioli
A: 

You can use OpenCV to read and write avi file.
see http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html

Note that OpenCV can also be used to grab images from a camera.

Ugo
Opencv uses vfw for both camera and file access - it's great for reading VGA images from a webcam and writing uncompressed AVI - but it can't handle reading a 4K camera at 60fps!
Martin Beckett
+1  A: 

Well, after figuring out what 'reasonable' AVI headers would be for your stream (e.g. if you use a custom codec fourcc, no application would probably be able to do useful things with it -- so why bother with AVI?) you could just write a prebuild RIFF-AVI header at the beginning of your file. It's not too hard to figure out the values.

Each frame then has to be enclosed in its own RIFF chunk (4 Byte type: "00db" + 4 byte length + your data). After the fact you have to fix the num_frames and some length fields in the header. And for files >2GB don't forget the OpenDML extension for the header.

smilingthax
Didn't know about the 2Gb AVI limit, I hit that in <9secs! Looks like I need to use MP4 for all the extra header info. But for now I will just write a separate text file for the header info.
Martin Beckett
You can also write a custom riff chunk with your own type for extra headers. For MP4 / QT you have to write a table with file-positions for each frame additionally to your data-stream into the header (which can be a footer). Oh, and I forgot that RIFF chunks have to be padded for 2 byte alignment.
smilingthax