Welcome to MSDN Blogs Sign in | Join | Help

Basic code to encode a file

Here's a very small snippet of code that uses the Expression Encoder object model to create a job, add a media file to the job and then encode it. There's a lot more to the object model, but I thought this would give a little taste of the basics. In the object model we wanted to expose most features of the full Encoder application, but we also wanted to make sure the user could do the simple operations without having to write a lot of code.

public void EncodeAFile()
{
    // Create a job and a media item for the video we wish to encode
    Job job = new Job();
    MediaItem mediaItem = new MediaItem(@"C:\input\MyVideo.avi");
    // Add the media item to the job
    job.MediaItems.Add(mediaItem);
    // Set the output directory where any encoded files will go.
    job.OutputDirectory = @"c:\output";
    // Set up the progress callback function
    job.PublishProgress += new EventHandler<PublishProgressEventArgs>(OnPublishProgress);
    // Encode the file
    job.Encode();
}

void OnPublishProgress(object sender, PublishProgressEventArgs e)
{
    Console.WriteLine(e.Progress);
}
Published Friday, March 07, 2008 1:11 AM by deanro
Filed under:

Comments

Friday, March 07, 2008 6:16 AM by MSDN Blog Postings » Basic code to encode a file

# MSDN Blog Postings &raquo; Basic code to encode a file

Wednesday, March 12, 2008 9:51 AM by Nick

# re: Basic code to encode a file

Thanks Dean. I've used this to get something working and have used the VideoProfile.TryFindProfile to do some basic configuration. This is going to be very cool!

Thursday, March 13, 2008 3:11 AM by Dean Rowe's WebLog

# Changing the output profile

Once you've created a MediaItem , you're probably going to want to specify which video and/or audio profile

Thursday, March 13, 2008 4:07 AM by Noticias externas

# Changing the output profile

Once you&#39;ve created a MediaItem , you&#39;re probably going to want to specify which video and/or

New Comments to this post are disabled
 
Page view tracker