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]
Hereâs an example movie assembled from 5 bitmap files.
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:
public static void SaveVideo(
string fileName,
string profileFileName,
string[] files
);
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.
// Find the input files
string [] files = Directory.GetFiles(inputDirectory, fileFilter);
// Throw exceptions if we have any missing info
if(files.Length < 1)
throw new Exception("No JPEG files found!");
if(outputFileName.Length == 0)
throw new ArgumentException("No output file specified!");
if(prxFileName.Length == 0)
throw new ArgumentException("No profile file specified!");
// Finally save the video
WMVService.SaveVideo(outputFileName, prxFileName, files);
Console.WriteLine();
Console.WriteLine(String.Format("{0} frames written to file {1}", files.Length, outputFileName));
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.
You also may want to look into the following resources when digging into this stuff:
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.
-Brendan
Read: Dynamically Generate Windows Media Videos in .NET