videoInput - a free windows video capture library

Why it rocks....
1) Needs no additonal software installed.
2) No pop up windows to select settings.  Specify it in code.
3) Can capture from multiple capture devices at the same time.
4) Supports wide number of video capture devices.
5) It is fast.
6) It is free.

DISCLAIMER - This software is experimental, use at your own risk. 
It is released free of charge under no license, feel free to 
send me fixes, improvements etc - email is in the header file.



Update: from now on all development will be done on my Github videoInput repo. Please follow the project there, file requests, send patches etc...



Latest Release: New - videoInput0.1995 lib and src

Version 0.1995 - Jan 2009

Lots of new stuff! If there are no major issues with this release it will become the 0.2 release.

New Features:
- now set to single threaded COM - if you need multithreaded recompile and uncomment the #define in the header file
- set framerate - VI will try and set the framerate of your device as close as possible to what you request.
- adjust video setting properties (like shutter speed, pan, zoom, whitebalance etc) in code.
- new device listing code - should give better results.
- getDeviceName for returning the name of the device as a c string. Thanks Peter!
- VS 2008 projects.
- ability to reconnect to device if camera freeze is detected.

Fixes:
- some non freed memory issues.
- a bug with closest device matching.
- a potential bug from not setting the lSampleSize of the media type. Thanks Peter!
- restartDevice remembers all your settings now.

Plus See version 0.1991 notes bellow




Latest Release: New - videoInput0.1991 lib and src

Version 0.1991 - April 2008

Fixes a bug with 0.199 which can cause a crash when trying to load a camera.
Lots of memory allocation / deallocation fixes.
Threaded settings window - so you can adjust the parameters and see the results.
Hopefuly a good deal more stable.

This version has been in private testing and results have been very good so far.

If you have usb capture devices that stop capturing after a while - see the notes included in the download on how to disable Windows power saving on your USB ports. This was found to be the cause for a lot of devices freezing after a certain amount of time.


Plus See version 0.199 notes bellow




Latest Release: videoInput0.199 lib and src - bug found

Version 0.199 - December 2007

There have been some issues with certain capture cards freezing with previous releases.
This release corrects those issues but with the same functionality as 0.198.

If you have downloaded 0.198 please replace with this release!

Callback method can be set before capture begins.
Added setFormat(), to set a default format (NTSC / PAL etc)
Dev-C++ lib and build project now included
Better device shut down handling.
Now can be run from other threads

See version 0.195 notes bellow




Bad Release: Bad Release - videoInput0.198 lib and src

Bad Release - Version 0.198 - November 2007

Don't download this release - get 0.199.

Added setFormat(), to set a default format (NTSC / PAL etc)
Dev-C++ lib and build project now included
Callback method can be set in the header file.
Fixes where on a few capture cards video would stop coming after a period of time.
Better device shut down handling.
Now can be run from other threads

See version 0.195 notes bellow




Latest Release: NEW! videoInput0.195 lib and src

Version 0.195 - June 2007

Minor patch to 0.194 - fixes a naming conflict between openCV (cvaux) and videoInput.

Thanks to Golan Levin for the catching the openCV conflict as well as much needed spelling help :)

See version 0.194 notes bellow




Latest Release: videoInput0.194 lib and src

Version 0.194 - June 2007

THIS IS A BUG FIX VERSION - NEW FEATURES COMING IN 0.200
There was a couple of huge bugs in 0.191 so this release is maninly to fix them.
The first bug was to do with a lack of mutexs for the grabbing thread that would result in the capture stopping after a while.
The second bug was to do with not finding the correct closest or exact size with some capture cards.

Do not use 0.191 anymore! Try 0.194 or the more tried and tested (but less cool) 0.171VS

New stuff:
setVerbose(); to disable/enable printfs
Visual Studio Demo Project pimped! - now with openGL textures etc.

Thanks to Martin C. Martin for the threading fix and other improvements!

See version 0.191 notes bellow




Latest Release: videoInput0.191 Lean and Mean lib and src

Version 0.191 - April 2007

New stuff:
getPixels() now can return a buffer or have a buffer passed in
and lots of small bug fixes.
See version 0.19 notes bellow




Latest Release: videoInput0.19 lib and src

Version 0.19 - April 2007

New stuff:
-Now with non-blocking callback functionality
-Ability to choose BGR or RGB for all you openCV heads
-Stop and restart devices
-New video formats supported
-Finds nearest matching size
-Much much cleaner - trust me you want to use this one!

Includes:
-source code
-basic demo project for Visual Studio / C++
-static compiled lib for Visual Studio / C++ and project
-openGL demo app for codewarrior
-static compiled lib for codewarrior and project

NOTE: The API has changed slightly so please read videoInput.h for correct usage!! :)

VISUAL STUDIO
This release has been tested with Visual Studio 2005 express - but it should work fine with the full version too!
You need to have the windows SDK installed - which is pretty normal. Please read the visual studio notes! It will make life easier. To get the windows sdk working in VS 2005 express - you have to jump through these hoops!
http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/

DEMO APPS
The CW demo app included is a simple openGL app that creates a window and grabs video from a capture device to a texture.
The Visual Studio demo app is a bit more basic but shows how to use videoInput in your project

Use the CW demo app to check if you camera is connecting okay.




Latest Release: videoInput0.171vs lib and src

Version 0.171vs

First release with Visual C++ demo App!!!

Includes:
-source code
-static compiled lib
-Codewarrior demo app and
-VS 2005 demo app.

This release has been tested with Visual Studio 2005 express - but it should work fine with the full version too!
You need to have the windows SDK installed - which is pretty normal.

To get the windows sdk working in VS 2005 express - you have to jump through these hoops!
http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/

The demo app included is a simple openGL app that creates a window and grabs video from a capture device to a texture.
The Visual Studio demo app is pretty much identicle to the Code Warrior apps that older release of videoInput have come with.

Read the notes for release 0.17 for class useage.

Thanks to Phillip and Jared of Potion Design ( www.potiondesign.com ) for visual studio help and Dynal Patel, for remote debugging and impetus to do the whole VS thing!

More soon!!




Latest Release: videoInput0.171 lib and src

Version 0.171

Micro release! Use this version instead of previous versions. 0.18 Coming soon!!! The other versions prob aren't visual studio friendly.

Thanks to Phillip and Jared of Potion Design ( www.potiondesign.com ) for figuring out some bugs that prevented proper use in Visual Studio.

How to use in visual studio 2005:

1) go to Options->VC Directories->Library paths and specify directory where videoInput.lib is
2) go to Project->Project Settings-> Linker -> Input and add "videoInput.lib" to the list of files so that the lib is linked against




Latest Release: videoInput0.17 lib and src

Version 0.17
-Nicer implementation - now you can capture from devices 1 and 2 without having to capture from device 0.

-Now supports 1394 pixelink cameras - if you are lucky enough to have one of these cameras you can capture
at upto 1280 by 1024 .

As with previous versions instructions and examples of useage are included in the videoInput.h file

See the notes of previous releases for other features.

 Example useage
		
	videoInput::listDevices();		//optional static function to list devices
		
	videoInput * VI  = new videoInput();    //required class to manage all the cameras
	VI  ->setPhyCon(0, VI_COMPOSITE);	//optional (CAPTURE DEVICE TO SETUP, CAPTURE_CONNECTION) - use VI_COMPOSITE (defualt) for most
	
	
	VI  ->setCaptureSize(0,CAM_W,CAM_H);	//optional (CAPTURE DEVICE TO SETUP, CAPTURE WIDTH, CAPTURE HEIGHT)
	
	VI  ->setup(0);  			//required (CAPTURE DEVICE TO SETUP) - 0 is the first device
	
	//for more than one camera
	VI  ->setup(1);  			//required (CAPTURE DEVICE TO SETUP) - 1 is the second device
	
	unsigned char * frame  = new unsigned char[VI->getSize(0)];  //optional (DEVICE NUMBER) - gets the buffer size of the image handed back
	
	//for more than one camera
	unsigned char * frame2  = new unsigned char[VI->getSize(1)];  //optional (DEVICE NUMBER) - gets the buffer size of the image handed back

	
	//idle loop
		
		if(VI->grabFrame(0, frame))	//required (DEVICE NUMBER, BUFFER BIG ENOUGH FOR IMAGE) - returns rgb image as a byte array
		{
			//generic function to load to a texture
			loadImageData(frame, VI->getWidth(0), VI->getHeight(0), GL_RGB); //use VI->width etc so that you don't get a crash
		}	
		
		//for more than one camera
		if(VI->grabFrame(1, frame2))
		{
			//generic function to load to a texture
			loadImageData(frame2, VI->getWidth(1), VI->getHeight(1), GL_RGB); //use VI->width etc so that you don't get a crash
		}	
		
		
	//end idle loop




	Contact me at : theo [DOT] watson (AT) gmail [DOT] com .




Latest Release: videoInput0.165 lib and src

Version 0.165
-Now supports 1394 pixelink cameras - if you are lucky enough to have one of these cameras you can capture
at upto 1280 by 1024 .
As with previous versions instructions and examples of useage are included in the videoInput.h file

See the notes of release 0.16 bellow for code useage.




Latest Release: videoInput0.16 lib and src

Version 0.16
-Added YUV formats!! - this means that you have a much larger choice of capture sizes.
-Only need one instance of videoInput to handle all the cameras you need.
-Added Driver dialog to change properties of capture device.
-Grabs RGB by default thanks to some nifty assembly code.

As with previous versions instructions and examples of useage are included in the videoInput.h file

See the notes of release 0.155 bellow for code useage.




Latest Release: videoInput0.155 lib and src

Version 0.155
-Only need one instance of videoInput to handle all the cameras you need.
-Added Driver dialog to change properties of capture device.
-Grabs RGB by default thanks to some nifty assembly code.

As with previous versions instructions and examples of useage are included in the videoInput.h file

NOTE: THIS REVISION IS A MAJOR ONE AND THE CODE IS NOT THE SAME AS FOR PREVIOUS VERSIONS
PLEASE LOOK AT THE EXAMPLES BELOW AND INCLUDED WITH SOURCE FOR PROPER USEAGE.


			
	//ONE CAMERA
			
	videoInput * VI  = new videoInput();
	//If you need to change the input
	//VI  ->serPhyCon(VI_S_VIDEO);         
	 //if you need a size other than the default
   	//VI  ->setCaptureSize(0,320,240);		  	
	VI  ->setup(1); //try to setup two cameras.
	
	//set the buffer to the size we are capturing at
	unsigned char * frame   = new unsigned char[VI->getSize(0)]; 
	while(running)
	{			
	  if(VI->grabFrame(0, frame))  //do something with the image
	}
			
	//use VI->getWidth(0) VI->getHeight(0) to get image dimensions
	//use VI->getSize(0) for image size 

			
	//TWO CAMERAS
			
	videoInput * VI  = new videoInput();
	//Only use if you need a different size than the default
	VI  ->setCaptureSize(0,320,240);		   
	//Only use if you need a different size than the default
	VI  ->setCaptureSize(1,320,240);	       
	VI  ->setup(2); //try to setup two cameras.

	//set the buffer to the size we are capturing at
	unsigned char * frame   = new unsigned char[VI->getSize(0)]; 
	//set the buffer to the size we are capturing at
	unsigned char * frame2  = new unsigned char[VI->getSize(1)]; 


	while(running)
	{			
	  if(VI->grabFrame(0, frame))  //do something with the image
	  if(VI->grabFrame(1, frame2)) //do something with the image
	}	





Latest Release: videoInput0.13 lib and src

Version 0.13 - Added the setCaptureSize function which lets you capture at a
non default capture size (needs to be a compatible resolution though).

As with previous versions instructions and examples of useage are included in the videoInput.h file


//Example Useage
//Use grabFrame() instead of grabFrameRGB() 
//if you are converting to grayscale as it saves frames.

	//from one device

	VI = new videoInput();
	int noOfDevices = VI->listDevices();
	
	if(noOfDevices>0){
		// capture from Composite
		//optional	VI->setPhyCon(0); 
		
		//use to capture at a non-default but compatabile size
		//optional	VI->setCaptureSize(320,240); 
		
		VI->start(0);
		
		VI->grabFrameRGB(buffer); 

		//and now do something with the buffer

	}	
	
	delete(VI);
	
	
	
	//that is it done!  easy huh?
	//or for multiple devices
	
	VI = new videoInput();
	VI2 = new videoInput();
	
	int noOfDevices = VI->listDevices();

	
	
	if(noOfDevices>0){
		VI->setPhyCon(0); // capture from Composite
		VI->start(0);
		VI->grabFrameRGB(buffer);		
	}
	if(noOfDevices>1){
		VI2->setPhyCon(1); // capture from S-Video
		VI2->start(1);
		VI2->grabFrameRGB(buffer);		
	}	

	delete(VI);
	delete(VI2);
	



Latest Release: videoInput0.12 lib and src

Version 0.12 Supports USB web cams and also to select the non default physical interface (ie S-Video) from a capture device.

As with previous versions instructions and examples of useage are included in the videoInput.h file


//Example Useage
//Use grabFrame() instead of grabFrameRGB() 
//if you are converting to grayscale as it saves frames.

	#include "videoInput.h"
	videoInput * myVideo1;
	videoInput * myVideo2;
	unsigned char * buffer1 = new unsigned char[320*240*3];
	unsigned char * buffer2 = new unsigned char[320*240*3];

	myVideo1 = new videoInput();
	int noOfDevices = myVideo1->listDevices();
		
	if(noOfDevices>0){
		myVideo1->start(0);
		myVideo1->grabFrameRGB(buffer1);		
	}	
	
	delete(myVideo1);
	
	//that is it done!  easy huh?
	
	//or for multiple devices (for the fancy pants)
	
	myVideo1 = new videoInput();
	myVideo2 = new videoInput();
	
	int noOfDevices = myVideo1->listDevices();
	myVideo1->setPhyCon(0); // capture from Composite
	myVideo2->setPhyCon(1); // capture from S-Video
	
	
	if(noOfDevices>0){
		myVideo1->start(0);
		myVideo1->grabFrameRGB(buffer1);		
	}
	if(noOfDevices>1){
		myVideo2->start(1);
		myVideo2->grabFrameRGB(buffer2);		
	}	

	delete(myVideo1);
	delete(myVideo2);



Release: videoInput0.11 lib and src

Version 0.11 has a number of changes most importantly in the way devices are listed please re-read the h file for info.

Info:
Here is an early working alpha release of videoInput which can capture from most installed capture devices on windows in a few lines of code.

To use just include the lib and header file thats all you need. The header file has info on how to use it - it is very easy to use just a few lines of code.

The source is just two files videoInput.cpp and videoInput.h. There are two codewarrior 8 project files one builds a simple app which grabs one frame and writes to a raw file(320 by 240 RGB). The other compiles as a lib. Included are all the DirectShow libs and header files needed so you should only need codewarrior to compile. The streams.h file had to be modified to work for codewarrior and the correct src for the file is commented into the end of the videoInput.h file in case you need it. Things to note:

The image handed back is BGR not RGBA - it can return RGB too but if you are going to convert it to black and white anyway just use the regular grabFrame call.

You have to supply a unsigned char * buffer to the grabFrame function that is the right size for your device. If your device captures at 320 by 240, you need to have a buffer[320*240*3] at least so it can store the whole image.

Tested on the Hauppauge WinTV Pro USB Capture card and the Pinnacle PCTV Card other cards probably work but I don't know for sure.

Can handle multiple cameras as you can see above, needs a new instance of the class for each camera.

This code is to make people's lives easier (hopefully) , I don't care how it is used. If you have bugs, questions, comments or improvements I would love to hear them.

Contact me at : theo [DOT] watson (AT) gmail [DOT] com .