简体   繁体   中英

Custom avi/MP4 file writer

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

Well, after figuring out what 'reasonable' AVI headers would be for your stream (eg 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.

Martin, since you are proficient in OpenCV , couldn't you just use cvCreateVideoWriter() for creating an uncompressed .avi ?

CvVideoWriter* cvCreateVideoWriter(const char* filename, int fourcc, double fps, CvSize frame_size, int is_color=1)

Regarding the foucc param, the documentation states:

Under Win32 if 0 is passed while using an avi filename it will create a video writer that creates an uncompressed avi file.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM