VideoNet: Peer to Peer Video Conference Application

This application allows any two persons on the LAN/Intranet (possibly the Internet) to have a video conference. There are several video conference applications that exist today. Each has its own performance enhancement techniques. The major problem in video conferencing is that the size of the video frame is too big for transmission. Hence, the performance is based on the codec used for encoding and decoding the frame. I am using the Fast h263 Encoder library that gives a better compression rate at high speed. This application can also be used on the Internet with little modification.

Recording and Playing Audio

I have used the same RecordSound and PlaySound classes that I have used in my previous voice conference application. Here, I will provide a brief overview of how to use the RecordSound and PlaySound classes.

// Create and Start Recorder Thread
   record=new RecordSound(this);

// Create and Start Player Thread
   play=new PlaySound1(this);

// Start Recording

// Start Playing

// During audio recording, data will be available in the OnSoundData
// callback function of the RecordSound class. Here, you can place
// your code to send the data to remote host...

// To play the data received from the remote host

// Stop Recording

// Stop Playing

// At last, to Stop the Recording Thread

// To stop playing thread...

Video Capture

VideoCapture is done using the VFW (Video For Windows) API. It provides support for capturing the video from a webcam. VideoCapture.h and VideoCapture.cpp are the files that contain the code for the complete video capture process.

Here are the brief details of how to use this class:

// Create instance of Class
   vidcap=new VideoCapture();

// This is later used to call display function of the main
// dialog class when the frame is captured...

// This does lot of work, including connecting to the driver
// and setting the desired video format. Returns TRUE if
// successfully connected to videocapture device.

// If successfully connected, you can get the BITMAPINFO
// structure associated with the video format. This is later
// used to display the captured frame...

// Now you can start the capture....

// Once capture is started, frames will arrive in the "OnCaptureVideo"
// callback function of the VideoCapture class. Here you call the
// display function to display the frame.

// To stop the capture

// If your job is over....just destroy it..

If you do this much work, your code will compile well, but the linker will trouble you. You must link the suitable libraries.

#pragma comment(lib,"vfw32")
#pragma comment(lib,"winmm")

Displaying the Captured Video Frame

There are various methods and APIs for displaying the captured frame. You can use the SetDIBitsToDevice() method to directly display the frame. But, this is quite slow because it is based on the Graphics Device Interface (GDI) functions. The better method is to use DrawDib API to draw the frame. The DrawDib functions provide high performance image-drawing capabilities for device-independent bitmaps (DIBs). DrawDib functions write directly to video memory, hence providing better performance.

Here is the brief view of how to use DrawDib API to display a frame.

// Initialize DIB for drawing...
   HDRAWDIB hdib=::DrawDibOpen();

// Then call this function with suitable parameters....

// Now, if you are ready with the frame data, just invoke this
// function to display the frame

// Finally, termination...

Encoder and Decoder Library


I have used the fast h.263 encoder library for the encoding. This library was a modified version of Tmndecoder to make it faster for real-time encoding. I have converted this library from C to C++ so that it can be integrated easily into any Windows application. I have removed some of unnecessary codes/files from the fast h263 library and moved definitions and declarations in their proper .h and .cpp files.

Brief view of usage of H263 Encoder library:

// Initialize the compressor
   CParam cparams;
   cparams.format = CPARAM_QCIF;

//If you need conversion from RGB24 to YUV420, call this

// Set up the callback function
// OwnWriteFunction is the global function called during
// encoding to return the encoded data...
   WriteByteFunction = OwnWriteFunction;

// For compression, data must be in the YUV420 format...
// Hence, before compression, invoke this method

// Compress the frame.....
   cparams.format  = CPARAM_QCIF;
   cparams.inter   = CPARAM_INTRA;
   cparams.Q_intra = 8;;    //  Data in YUV format...
   CompressFrame(&cparams, &bits);

// You can get the compressed data from the callback function
// that you have registerd at the begining...

// Finally, terminate the encoder
// ExitH263Encoder();


This is the modified version of tmndecoder (H.263 decoder). It was in ANSI C. I have converted it to C++ so that it can be integrated into any windows application. I have removed some of the files that had display and file storing functions. I have removed the unnecessary code and also added some new files.

The original library dealt with files. It was not suitable to use for real-time decoding. I have made some major changes so that it can be easily integrated into the application for a real-time decoding process. Now, one can use this library to decode H263 frames. This library is quite fast and gives better performance.

Usage of the Decoder …..

//Initialize the decoder

// Decompress the frame....
// > rgbdata must be large enough to hold the output data...
// > decoder produces the image data in YUV420 format. After
//   decoding, it is converted into RGB24 format...

// Finaly, terminate the decoder

How to Run the Application

Copy the executable file onto two different machines, A & B, thath are on LAN. Run both the applications. From machine A (or B), select the connect menu item and in the popup dialog box enter the name or IP Address of the other host(B) and press the connect button. On the other machine (B), an accept/reject dialog box will appear. Press the accept button. On machine A, a notification dialog box will be displayed. Press OK to begin the conference.

That’s it….Enjoy……!!!


I would like to thank Paul Cheffers for his audio recording and playing sound classes. You are seeing this videonet application here because of Opensource libraries contributed by Openminded persons. I am grateful to developer Karl Lillevold of Tmndecoder and Roalt Aalmoes of the h.263 fast encoder library for making it free.

If you have any queries or suggestions, plese feel free to mail me at [email protected]

More by Author

Must Read