views:

1216

answers:

6

I have a directory of bitmaps that are all of the same dimension. I would like to convert these bitmaps into a video file. I don't care if the video file (codec) is wmv or avi. My only requirement is that I specify the frame rate. This does not need to be cross platform, Windows (Vista and XP) only. I have read a few things about using the Windows Media SDK or DirectShow, but none of them are that explicit about providing code samples.

Could anyone provide some insight, or some valuable resources that might help me to do this in C#?

Thanks!

+3  A: 

You can use the AVI* from avifil32 library, there is an example here (not tried):
http://www.adp-gmbh.ch/csharp/mandelbrot/index.html

This might be of interest for you:
http://bytescout.com/swfslideshowscout_example_c_sharp.html
(make flash slideshow from JPG images using C#)

Aleris
+7  A: 

At the risk of being voted down, I'll offer a possible alternative option-- a buffered Bitmap animation.

double framesPerSecond;
Bitmap[] imagesToDisplay;     // add the desired bitmaps to this array
Timer playbackTimer;

int currentImageIndex;
PictureBox displayArea;

(...)

currentImageIndex = 0;
playbackTimer.Interval = 1000 / framesPerSecond;
playbackTimer.AutoReset = true;
playbackTimer.Elapsed += new ElapsedEventHandler(playbackNextFrame);
playbackTimer.Start();

(...)

void playbackNextFrame(object sender, ElapsedEventArgs e)
{
    if (currentImageIndex + 1 >= imagesToDisplay.Length)
    {
            playbackTimer.Stop();

            return;
    }

    displayArea.Image = imagesToDisplay[currentImageIndex++];
}

An approach such as this works well if the viewing user has access to the images, enough resources to keep the images in memory, doesn't want to wait for a video to encode, and there may exist a need for different playback speeds.

...just throwing it out there.

MikeHerrera
A: 

I have not tried it, but Windows Movie Maker has an API, and XML file format you can use.

GvS
A: 

FFMPEG can easily do this.

Osama ALASSIRY
A: 

An ideal technology to achieve what you want is DirectShow Editing Services. However, if this is a one-off project then I wouldn't bother - the learning curve can be quite steep.

There's not much in the way of DES sample code available, although there's plenty of general DirectShow samples both within and outside MSDN. For your purposes I'd recommend starting here for a basic explanation of using still images as a video source.

Stu Mackellar
+1  A: 

You can use Splicer to do this.

Please see example 3 at http://www.codeplex.com/splicer/Wiki/View.aspx?title=News%20Feeds&referringTitle=Home

loraderon
Thanks for the example shout out!
Scott