Partager via


Changing the output profile

Once you've created a MediaItem, you're probably going to want to specify which video and/or audio profile you want to encode it with. There are a number of ways to obtain a video and audio profile. If you have your own PRX file that you wish to use, you can load it with code something like this

 VideoProfile videoProfile;
AudioProfile audioProfile;
LocalProfiles.LoadProfileFromFile(@"C:\MyProfile.prx", out videoProfile, out audioProfile);

Once you have the profile loaded you can then set it on the MediaItem like so

 mediaItem.VideoProfile = videoProfile;
mediaItem.AudioProfile = audioProfile;

If you want to use one of the built-in profiles you can obtain it with code something like this by just searching for the name of the profile.

VideoProfile videoProfile = VideoProfile.FindProfile("Hardware Device - zune");

This does have the disadvantage that the code isn't going to work on a non English version of Expression Encoder as the string will be localized into a different language. So in the RTM version of Expression Encoder we will include a static list of Video and Audio Profiles that match the built-in profiles we supply, so you'll be able to write the code a little easier like this

 // Code from the future
mediaItem.VideoProfile = VideoProfiles.HardwareDeviceZune;

Once you've set the profile you may want to tweak it further by changing some of the individual parameters. You can do this with code like the following

 // Funky code alert
mediaItem.VideoProfile = (VideoProfile)mediaItem.VideoProfile.Clone();

// Set the video bitrate and change the dimensions of the output video
mediaItem.VideoProfile.Bitrate = 64000;
mediaItem.VideoProfile.Height = 80;
mediaItem.VideoProfile.Width = 120;

You may have noticed the ever so slightly funky code at the beginning :-). At the moment, when you get an instance of a VideoProfile or AudioProfile class back we're internally creating what is essentially a read only version. So if you try to change one of the parameters you'll get an exception. To fix this at the moment, you need to make a copy of the class before you can change it and this is what the Clone line does. When the RTM version of Expression Encoder comes out, this hopefully should no longer be necessary and you'll be able to change things directly as you'd expect.

After you've done all this, you can go ahead and call Encode on the job and you should end up with a video file that matches the profiles that you've set.

Comments

  • Anonymous
    March 12, 2008
    PingBack from http://msdnrss.thecoderblogs.com/2008/03/13/changing-the-output-profile/

  • Anonymous
    April 22, 2008
    (This post assume you’ve already installed Expression Encoder Beta 2 available from here , and

  • Anonymous
    May 08, 2008
    This post is an update to the previous Getting started with the Expression Encoder Object Model post,