I recently worked on a project here at the port archiving our gate camera images in
SQL Server. The cool thing about having these images archived is
that we can do all sorts of cool things with the raw bytes, such as
stream them as slideshow, pull up a specific image from a given
date, or combine multiple frames to dynamically create a video from a
given time period.
Combining images into a WMV movie from .NET turned out to be quite an interesting project. Kirk Marple,
expert in all things media,graciously donated a bunch of wrapper code
to the WMF SDK, which he says he took inspiration from this article here at CodeProject.
I’ve taken a lot of this code and put together a library which you
can use to generate WMV videos on the fly, from a variety of different
input types 1) A list of image files 2) An array of Bitmap objects
and 3) A SQL DataReader containing the raw image bytes. I’ve put
together a small console app that can be used as a
utility (MovieMaker.exe) for combining multiple files into a
WMV movie, it can be run via the command line, like so:
MovieMaker.exe profile_file_name output_file_name [input filter ex: *.bmp] [input directory]
The only tricky part of this is creating the appropriate Windows
Media Encoder Profile (prx) file. To do this, you’ll need to
download the free Microsoft Windows Media – Windows Media Encoder 9 Series.
You’ll also need this installed on any machine running this, since
the code uses the WMEncoder to extract the profile information it needs
to write the video.
The console app demonstrates how to quickly write images to a WMV
file, but you’ll probably find the WMVLib class itself more useful in
your applications. Using the WMVLib class is easy,
the most straight-forward usage is to call SaveVideo with the
output file name, profile file name, and list of bitmap files to write
to the video:
Here’s a snipped of code from the MovieMaker.exe app that shows how
to encode a directory of files, given an output and profile file name.
The WMVLib’s SaveVideo method is also overloaded for source input types, such as a Bitmap array and DataReader.
Download the following applications to play around with this stuff or integrate it into your own applications.
- Download the WMVLib dlls
- Download the full solution (C# source code)
- Download the MovieMaker.exe utility
You also may want to look into the following resources when digging into this stuff:
- Windows Media Encoder 9 Series FAQ
- Microsoft.public.windowsmedia.sdk newsgroup
- Microsoft Windows Media – Getting Started with Windows Media Encoder
Good luck, and if you have questions, topics
or code to share relating to windows
media, feel free to post them in our Windows Media and GDI+ forum.