This project has moved and is read-only. For the latest updates, please go here.

Writing bitmaps into a AVI file

Dec 27, 2015 at 6:15 AM
I have the sample working in Visual Studio 2013 and can play the recorded file, recorded with either the MJpeg encoder or the vfw264 encoder, in WMP and VLC.

the question is I a file full of JPeg images that get decoded into bitmaps. I need to record these images into something playable by WMP or VLC. Before I try to figure out how to do so with SharpAvi, can someone tell me if this is possible with this SDK.

Dec 28, 2015 at 1:08 PM
SharpAvi encoders expect BGR32 (top-down) bitmap images as input. Given that you can convert your JPEG images to this format - you're OK.
There are several methods for converting JPEG to bitmap in .NET depending on what you prefer. Look in API for working with images in Windows Forms or WPF.
Dec 28, 2015 at 5:50 PM
Thanks for the reply! You are correct I can change a JPEG image into a bitmap with no difficulty at all. What I wanted to make sure was that SharpAVI could take individual images and let me put them into a avi file one image at a time? Based on the example I think the answer is yes and you have supplied the knowledge that the bitmap needs to BGR and not RGB.

The images will probably not be decompressed from JPEGs in 33mS yet I need to resultant video to run at 30 fps as that was the speed of the original video that was captured as a file of JPEG images. Is there anything special I need to do to accomplish this?

Dec 29, 2015 at 3:45 PM
I do not need to supply frames in realtime when writing your AVI. Frame rate of a resulting video is defined by AviWriter.FramesPerSecond property.
Please take a look at the docs to get basic understanding of using SharpAVI.
Dec 31, 2015 at 3:55 AM
Edited Dec 31, 2015 at 3:56 AM
I have read the documentation several times and have studied the example program. What is interesting to me, is that you put the RecordScreen into a separate thread and you do a screen grab every 1/10th of a second. Yet you are saying that I do not need such a mechanism. I can push buffers in the WriteStreamAsync with no regard to whether I am writing them faster or slower than 30 fps which is the rate I need.

Is it a coincidence that you did screen grabs at the same rate as the frames per second?

Dec 31, 2015 at 2:31 PM
Sample app captures the screen at fixed 10 fps rate, and simply writes the next frame right when it's captured. I also want that video frames are played back at the natural speed they were captured, so FramesPerSecond is set to the same 10 fps. And it has nothing in common with the rate of writing frames. For example, I could put captured frames in memory buffer. And each time it gets full write all frames in the buffer in a loop. The result would be the same - video played back with 10 fps. The playback rate of AVI is defined solely by FramesPerSecond, nothing else.

Your task is not to capture, but to put existing sequence of JPEG frames into an AVI file. Depending on your requirements, you may not even need asynchronous writing. Simply call IAviVideoStream.WriteFrame for each of the converted frames in a loop.