| Description: | AVICapture is a Visual Basic.NET 2005 partial implantation of Video for Windows (VfW) |
| Language: | Visual Basic.NET 2005 |
| Screenshot: | ![]() |
| Virus Scan: |
Introduction
AVICapture is a Visual Basic.NET 2005 partial implantation of Video for Windows (VfW) (http://msdn2.microsoft.com/en-us/library/ms713492.aspx). It is implemented with great help from “A Simple C# Wrapper for the AviFile Library” by Corinna John which can be found at http://www.codeproject.com/cs/media/avifilewrapper.asp.
Although there are an immense variety of things you can do with VfW, my need was to create an AVI with compression from a series of images, specifically the screen capture of a Windows form or control. AVICapture only implements the functions needed to write a series of bitmaps to a compressed AVI.
Rational and Background
The basis of this project was to create a Yahoo! Messenger webcam capture utility. The first step in doing this is to find a way to save the captures to a video or AVI. After many hours of searching I could not find a suitable library. Additionally the ones that came close were commercial pieces of software that had with a very high price tag. The only solution was to create my own library.
From the beginning I had the choice between Video for Windows and DirectDraw, both Microsoft technologies. It appeared that VfW was more straight forward so I flipped a coin and started in that direction. After A LOT of Microsoft API documentation I was fortunate to find “A Simple C# Wrapper for the AviFile Library.” This AVI library has everything but the kitchen sink and is well written. I have a very specific application so I carved out what I needed from the wrapper and combined it with what I already had.
Writing an AVI creator was not as easy as I predicted. The documentation is lacking and there are many pitfalls to watch out for.
Features
- Creation of an AVI file from a series of bitmaps
- CODEC compression
- CODEC selection
Usage
The first phase is to prep the many variables. You will have to know how large the bitmaps will be (they can not dynamically change size), where you want to save the file to, and frame rate. In the following example I take a Windows form as the source.
Dim rectWindow As SC_APIs.RECT
SC_APIs.GetWindowRect(hWindow, rectWindow)
iWidth = rectWindow.Right - rectWindow.Left
iHeight = rectWindow.Bottom - rectWindow.Top
'Create the bitmap
Dim bWindow As New Bitmap(cInfo.iWidth, cInfo.iHeight)
Next I set the filename and frame rate.
strSavePath = System.Environment.CurrentDirectory + "\"+ "test.avi"
iRate = 1
Then a new AVICapture object is crated by calling the following
AVIInstance = New AVICapture.AVICapture(strSavePath, iRate, iWidth, iHeight)
You can optionally set a CODEC to record your AVI with. By default AVICapture will use the Cinepak Codec by Radius if none is selected. CODECs are interesting creatures that do not always work as planned. For some reason many of the default Windows CODECs crash when used so use this feature with caution.
Dim uAVICompressOpt As New AVICapture.AVI_APIs.AVICOMPRESSOPTIONS_CLASS
Dim fiCODEC As New IO.FileInfo(System.Environment.CurrentDirectory + "\CODEC.avi")
Dim AVIInstance As AVICapture.AVICapture = New AVICapture.AVICapture(fiCODEC.FullName, 1, 1, 1)
_uAVICompressOpt = AVIInstance.returnCODEC()
fiCODEC.Delete()
Once AVIInstance has been created it is ready for you to add frames. Call the addFrame function for each new frame.
cInfo.AVIInstance.addFrame(bWindow)
Unlike DirectDraw, VfW does not use an internal clock. This means that the run time of the created AVI does not depend on the time between a call to addFrame. If you specified a frame rate of 1 and added 3 frames then you would have a 3 second movie even if you waited an hour between addFrame calls. For the above example to be effective you should add a timer that calls addFrame at the same interval as the rate.
There is a companion project with AVICapture called YCC Form Capture which demonstrates how to use this library. YCC Form Capture is a generic Windows form and control capture utility.
Bugs and Gottchas
- Some CODECs fail. Creating an AVI file can be a taxing experience and half of that trouble is in compression. AVICapture is based off of “A Simple C# Wrapper for the AviFile Library” on The Code Project. Unfortunately the base project has the same bug and I have not found a solution.
Requirements
- Microsoft .NET Framework 2.0 or above
License Agreement
The software, AVICapture, is distributed under the Creative Commons GNU General Public License which can be found at http://creativecommons.org/licenses/GPL/2.0/ The major points follow:
- No commercial distribution without permission.
- You are allowed to modify the program and source, all I ask is you keep the original credit.
- If you do modify the program it will fall under the same license agreement.
I have chosen this license to allow users to do pretty much what they want with the program. The big thing that I ask is please don't redistribute this software without acknowledgment to YCC and a link back to http://ycoderscookbook.com. I would love to hear what you think about the program and if you have made useful changes. A forum for AVICapture can be found at http://www.ycoderscookbook.com/forums/viewforum.php?f=14 under the Programs directory.
As with any piece of freeware, I have made every effort to make the software useable and friendly. With that said I take no responsibility for damage created by this program or the user’s actions. The user takes full responsibility for their actions.
Source and Executible
Full source code is provided. Please feel free to modify AVICapture as long as you read and understand the license agreement.




