KVideo is a simple C++ wrapper for v4l[2] framegrabber devices and standards compliant Firewire cameras. This is intended for developers that want to add video capture to their applications and don't want a common API for the different libraries that handle these different cameras.

The video.h header allows for two methods for accessing video frames. The simpler is to just call call open() with the width and height you want and then calling Video::capture() which returns a buffer with the video format you request and dimentions of Video::width() and Video::height. If you are just using capture() you never need to call stopCapture(), that will be called in the Video destructor. But if you want to switch to the other mode of frame capture you will need to call it after you've finished using the last captured frame. One thing to note is that the Video class owns the captured frame so it is only valid until the next capture or stopCapture call.

The more complex capture method is to use streaming. First you call startStreaming() for which you can specify the frames per second and the number of buffers you want. Once you make the call the buffers will be filled via DMA transfer, and when you call streamingFrameGet() it will simply give you a pointer to one of them in FIFO order. The catch to using this interface is that you must call streamingFrameReturn() with the pointer returned from streamingFrameGet() when you are done with it. Depending on the driver you may have to call streamingFrameReturn() before you can call streamingFrameGet() again. It's safest to always do this, if you look at kvideo which uses this interface it draws a frame as soon as it gets it and does not draw anything in it's draw method. The alternative is to copy the buffer and return the original. When you are done you should call stopStreaming which will stop the background DMA transfers.

Here's what you really need to know

cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/kvideo login
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/kvideo co kvideo
Just hit return for the login password then use the second command to download the source you will want to read the README. You will also want to look at these projects:

Here's a screenshot of the kvideo config dialog.

Here's the full video.h interface:

// -*- Mode: c++ -*-
// $Id: video.h,v 2003/05/20 13:47:16 kristjansson Exp $
// $Source: /cvsroot/kvideo/kvideo/src/video.h,v $
#ifndef __VIDEO_H__
#define __VIDEO_H__

#define VIDEO_DBG 1


#define VIDEO_NONE           0
#define VIDEO_RGB08          1  /* bt848 dithered */
#define VIDEO_GRAY           2
#define VIDEO_RGB15_LE       3  /* 15 bpp little endian */
#define VIDEO_RGB16_LE       4  /* 16 bpp little endian */
#define VIDEO_RGB15_BE       5  /* 15 bpp big endian */
#define VIDEO_RGB16_BE       6  /* 16 bpp big endian */
#define VIDEO_BGR24          7  /* bgrbgrbgrbgr (LE) */
#define VIDEO_BGR32          8  /* bgr-bgr-bgr- (LE) */
#define VIDEO_RGB24          9  /* rgbrgbrgbrgb (BE) */
#define VIDEO_RGB32         10  /* -rgb-rgb-rgb (BE) */
#define VIDEO_LUT2          11  /* lookup-table 2 byte depth */
#define VIDEO_LUT4          12  /* lookup-table 4 byte depth */
#define VIDEO_YUYV	    13  /* 4:2:2 */
#define VIDEO_YUV422P       14  /* YUV 4:2:2 (planar) */
#define VIDEO_YUV420P	    15  /* YUV 4:2:0 (planar) */
#define VIDEO_MJPEG	    16  /* MJPEG (AVI) */
#define VIDEO_JPEG	    17  /* JPEG (JFIF) */
#define VIDEO_UYVY	    18  /* 4:2:2 */
#define VIDEO_FMT_COUNT	    19

typedef unsigned char uchar;
typedef uchar* ucharP;
typedef std::vector StrVector;

class V4LInfo;
class IEEE1394Info;
#define INITIAL_WIDTH 640  
#define INITIAL_HEIGHT 480

class Video {
  V4LInfo                     *v4l;
  IEEE1394Info                *ieee1394;
  // general
  const char                  *devStr;
  const char                  *devNameStr;

  bool _canCapture, _isStreaming;
  int _fps, _buffers;
  static StrVector devices;
  static StrVector deviceNames;
  ~Video() { stopCapture(); stopStreaming(); }

  static const StrVector& getDevices() { return devices; }
  static const StrVector& getDeviceNames() { return deviceNames; }

  const char* getDevice();
  const char* getDeviceName();
  void setDevice(const char*);

  void open(const char* dev=0, int w=-1, int h=-1, int fmtid=VIDEO_BGR32);
  void open(int w=-1, int h=-1, int fmtid=VIDEO_BGR32);
  int getWidth();
  int getHeight();

  bool canCapture() { return _canCapture; }
  unsigned char* capture();
  void stopCapture();

  int startStreaming(int fps=-1, unsigned int buffers=2);
  unsigned char* streamingFrameGet();
  void streamingFrameReturn(unsigned char*);
  void stopStreaming();

  float getHue();
  void setHue(float);

  float getColor();
  void setColor(float);

  float getContrast();
  void setContrast(float);

  float getBrightness();
  void setBrightness(float);

  const StrVector getInputList();
  int getInput();
  void setInput(int);
  void setInput(const char*);

  const StrVector getNormList();
  int getNorm();
  void setNorm(int);

  const StrVector getAudioList();
  int getAudio();
  void setAudio(int);

  static int init();
  int openDevice(const char* device);
  int _openDevice();
  void closeDevice();
  void openV4L(int w, int h, int fmtid);
  void open1394(int w, int h, int fmtid);

namespace LinuxVideo { 
  typedef Video LinuxVideo::Video;