Android / iOS


AVI Video

libkohn_avi - AVI creator

This is a tiny library I made (with zero dependencies) for creating AVI files. It basically has 3 functions:

struct kavi_t *kavi_open( char *filename, int width, int height, char *fourcc, int fps, struct kohn_avi_audio_t *audio); void kavi_add_frame(struct kavi_t *kavi, unsigned char *buffer, int len); void kavi_close(struct kavi_t *kavi);

I've been working on an RTSP client API for recording video and decided to add these three functions. As long as they are called before the AVI file is closed, the framerate, codec, and size can be changed for the whole video:

void kavi_set_framerate(struct kavi_t *kavi, float fps); void kavi_set_codec(struct kavi_t *kavi, const char *fourcc); void kavi_set_size(struct kavi_t *kavi, int width, int height);

To use this library, simply call kavi_open() to create the avi file, kavi_add_frame() for every raw frame, and kavi_close() to finalize it all. I included a sample program called jpeg2avi which can take a series of jpeg files and create an avi using the mjpeg codec. The mjpeg code of course is just an avi file with a series of jpegs in it. To use this program, if you had a directory full of jpegs with filenames like frame000.jpeg, frame001.jpeg, frame002.jpeg, etc, simply run jpeg2avi like so:

jpeg2avi out.avi /path/to/jpegs/frame%03d.jpeg 15

I also have a new demo program which I called axis2avi. It's a pretty short program that uses popen() with wget (yeah, cheesy.. but I was in a hurry and it works great) to grab JPEG frames and stick them in an AVI file. It has the URL to an Axis camera hardcoded in the source code, so it will have to be edited to work with another networked camera. The program can grab frames every X seconds or every time the user presses enter. A ctrl-C should safely close the AVI file. I made a demo video using my Axis 211 camera doing "stop motion" video with some toys and put it on YouTube here:


May 13, 2010 - Audio was completely broken until this version :(. So anyway, audio works now. Audio is really only useful in the case of mjpeg, raw, or RLE compressed video since those frames can't include audio information. With mpeg and such audio can be mixed into the video. Also, I created a program that can fix broken AVI files using this library. Check the video_fixer_upper page for more info.

This library is distributed under the LGPL license.

Related Projects

Graphics: SSE Image Processing, GIF, TIFF, BMP/RLE, JPEG, AVI, kunzip, gif2avi, Ringtone Tools, yuv2rgb, RTSP


libkohn_avi-2011-02-14.tar.gz (Source Code) (Windows Binaries)

Older Versions

libkohn_avi-2011-01-30.tar.gz (Source Code)
libkohn_avi-2010-05-13.tar.gz (Source Code)
libkohn_avi-2008-08-13.tar.gz (Source Code) (Windows Binaries)
libkohn_avi-2008-04-09.tar.gz (Source Code) (Windows Binaries)

Copyright 1997-2021 - Michael Kohn