The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Dynamically Generate Windows Media Videos in .NET

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brendan Tompkins

Posts: 158
Nickname: brendant
Registered: Apr, 2005

Brendan Tompkins is .NET Developer and founder of CodeBetter.Com
Dynamically Generate Windows Media Videos in .NET Posted: Jun 29, 2005 11:59 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Brendan Tompkins.
Original Post: Dynamically Generate Windows Media Videos in .NET
Feed Title: Brendan Tompkins
Feed URL: /error.htm?aspxerrorpath=/blogs/brendan.tompkins/Rss.aspx
Feed Description: Blog First. Ask Questions Later.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Brendan Tompkins
Latest Posts From Brendan Tompkins

Advertisement

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

Topic: WS-I Basic Security Profile Sample App Preview Previous Topic   Next Topic Topic: BizTalk Adapter for SharePoint v2

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use