Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

directshow - How can I create a video from a directory of images in C#?

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#?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...