測試的程式碼如下,這邊是轉出為WMV的VC-1格式,
如果要轉檔成MP4的格式,需要使用"Expression Encoder 4 Pro (with codecs)"授權版本,不然會出現錯誤訊息。
using System;
using Microsoft.Expression.Encoder;
using Microsoft.Expression.Encoder.Profiles;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
MediaItem mediaItem = new MediaItem(@"C:\Temp\24.wmv");
//mediaItem.OutputFormat = new MP4OutputFormat();
WindowsMediaOutputFormat wmof = new WindowsMediaOutputFormat();
wmof.VideoProfile = new MainVC1VideoProfile();
wmof.AudioProfile = new WmaAudioProfile();
mediaItem.OutputFormat = wmof;
//Creates job and media item for the video to be encoded
Job job = new Job();
job.MediaItems.Add(mediaItem);
//Sets output directory
job.OutputDirectory = @"C:\Temp\converted";
//job.DefaultMediaOutputFileName = "24.mp4";
job.DefaultMediaOutputFileName = "24.wmv";
//Sets up progress callback function
job.EncodeProgress += new EventHandler<EncodeProgressEventArgs>(OnProgress);
//Encodes
Console.WriteLine("Encoding…");
job.Encode();
Console.WriteLine("\nFinished encoding.");
job.Dispose();
Console.ReadKey();
}
static void OnProgress(object sender, EncodeProgressEventArgs e)
{
Console.Write("\b\b\b\b\b\b\b");
Console.Write("{0:F2}%", e.Progress);
}
}
}
參考資料: