Android / iOS


libkohn_avi / readavi

Posted: Sometime in 2004?
Updated: December 30, 2021


This is some code I wrote long ago for creating AVI files and debugging them. The / libkohn_avi.dll can be given frames of jpeg files or other formats to create a video from them while readavi will dump the AVI headers to text so the internals of the container can be viewed in a human readable way. Both programs have zero dependencies so they should easily build by simply typing "make" on a Unix system or on Windows using MSYS.


There are basically 3 functions for libkohn_avi:

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. To use this program, if there is 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

There is also a demo program called axis2avi. It's a pretty short program that uses popen() with wget 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.

A demo video using an Axis 211 camera doing "stop motion" video with some toys can be seen on YouTube here:



The AVI file format is an audio/video file "container" that can hold raw video, mjpeg, xvid, divx, and many other compressed audio and video formats. This simple little program is an example how to parse AVI files and will dump the AVI headers from a file. I found this program quite useful for debugging AVI files created by programs I wrote and for figuring out what video codecs an AVI file using. Basic usage is:

./readavi somefile.avi

All code on this page is distributed under the LGPL license.

Related Projects

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


git clone

Older Versions

readavi-2013-05-22.tar.g z (Source Code) (Source Code)
libkohn_avi-2011-02-14.tar.gz (Source Code) (Windows Binaries)

Copyright 1997-2022 - Michael Kohn