本文整理汇总了C#中Job.Encode方法的典型用法代码示例。如果您正苦于以下问题:C# Job.Encode方法的具体用法?C# Job.Encode怎么用?C# Job.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Job
的用法示例。
在下文中一共展示了Job.Encode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncodeVideo
public static void EncodeVideo(FileInfo inputFile, FileInfo outputFile)
{
DirectoryInfo outDir = outputFile.Directory;
if (!outDir.Exists)
{
outDir.Create();
}
MediaItem mediaItem = new MediaItem(inputFile.FullName);
int bitrate = GetBitrate(mediaItem);
using (Job job = new Job())
{
job.OutputDirectory = outDir.FullName;
job.CreateSubfolder = false;
job.MediaItems.Add(mediaItem);
SetProfile(mediaItem);
// We can also use some of the presets. In that case comment the SetProfile line above for something like the one below:
// //H264VimeoSD preset settings: Output Format: MP4. Container: MP4. Video Codec: H.264 - Main.
// //Video size: 640, 480. Video Bitrate: 2500 Kbps. Video Encoding: CBR SinglePass.
// //Audio Codec: AAC. Audio Channels: Stereo. Audio Bitrate: 128 Kbps. Audio Encoding: CBR Single Pass
// job.ApplyPreset(Presets.H264VimeoSD);
job.Encode();
}
if (!outputFile.FullName.Equals(mediaItem.ActualOutputFileFullPath, StringComparison.InvariantCultureIgnoreCase))
{
throw new Exception(String.Format("The output file specified: '{0}' does not match the actual output file '{1}'", outputFile.FullName, mediaItem.ActualOutputFileFullPath));
}
}
示例2: RunEncoding
static void RunEncoding ()
{
Job EncodingJob = new Job ();
EncodingJob.JobId = System.IO.Path.GetFileNameWithoutExtension (Input);
MediaItem InputMediaItem = new MediaItem (Input);
EncodingJob.OutputDirectory = System.IO.Path.GetDirectoryName (Output);
EncodingJob.DefaultMediaOutputFileName = System.IO.Path.GetFileName (Output);
EncodingJob.CreateSubfolder = false;
Microsoft.Expression.Encoder.Profiles.VideoProfile VideoProfileFromFile = null;
Microsoft.Expression.Encoder.Profiles.AudioProfile AudioProfileFromFile = null;
Microsoft.Expression.Encoder.Profiles.PrxParser.LoadProfileFromFile (ProfileFileName, out VideoProfileFromFile, out AudioProfileFromFile);
Microsoft.Expression.Encoder.WindowsMediaOutputFormat OutputFormatInstance = new Microsoft.Expression.Encoder.WindowsMediaOutputFormat ();
OutputFormatInstance.VideoProfile = VideoProfileFromFile;
OutputFormatInstance.AudioProfile = AudioProfileFromFile;
Microsoft.Expression.Encoder.EncoderObject InputFile = new Microsoft.Expression.Encoder.EncoderObject ();
InputMediaItem.OutputFormat = OutputFormatInstance;
EncodingJob.MediaItems.Insert (0, InputMediaItem);
if (File.Exists (Output))
WMB.Basics.SecureFileDelete (Output);
EncodingJob.Encode ();
}
示例3: Encode
/// <summary>
/// Encodes the job using any passed presets and custom destinations
/// </summary>
/// <param name="job"></param>
/// <param name="PresetName"></param>
/// <param name="Destination"></param>
private static void Encode(Job EncoderJob, string PresetName, string Destination)
{
// Set up the progress callback function
EncoderJob.EncodeProgress += new EventHandler<EncodeProgressEventArgs> (OnProgress);
//Sets preset if it was set and encodes job
try
{
if (PresetName != null)
{
Preset PresetToUse = Preset.FromFile (PresetName);
EncoderJob.ApplyPreset (PresetToUse);
foreach (MediaItem Item in EncoderJob.MediaItems)
{
TimeSpan ClipDuration = TimeSpan.FromTicks (Item.FileDuration.Ticks);
//TimeSpan AudioDuration = TimeSpan.FromTicks (Item.AudioOverlayEndTime.Ticks - 1);
//TimeSpan UsedDuration = (ClipDuration > AudioDuration) ? AudioDuration : ClipDuration;
foreach (Source ItemSource in Item.Sources)
{
foreach (Clip ItemClip in ItemSource.Clips)
{
ItemClip.StartTime = TimeSpan.Zero;
ItemClip.EndTime = ClipDuration;
}
}
}
}
EncoderJob.CreateSubfolder = false;
EncoderJob.OutputDirectory = Destination;
EncoderJob.DefaultMediaOutputFileName = "{OriginalFilename}" + "_" + Path.GetFileNameWithoutExtension (PresetName)
+ "_" + ".{DefaultExtension}";
EncoderJob.Encode ();
}
catch (EncodeErrorException Excp)
{
// Console.WriteLine("EncodeErrorException Error: " + Excp.ToString());
WMB.Basics.ReportErrorToEventViewer("EncodeErrorException bei \"" + PresetName + "\"):\r\n"
+ Excp.ToString ());
return;
}
catch (PresetNotFoundException Excp)
{
// Console.WriteLine("PresetNotFoundException: " + Excp.ToString());
WMB.Basics.ReportErrorToEventViewer("PresetNotFoundException bei \"" + PresetName + "\"):\r\n"
+ Excp.ToString());
return;
}
}
示例4: Main
static void Main(string[] args)
{
MediaItem mediaItem;
if (args.Length == 0) {
System.Console.WriteLine("Usage: wmvocplus.exe <wmvfilename> <jpg filler to append> <seconds to display filler>");
return;
}
string wmvfilename = args[0];
string jpgfillername = args[1];
string outputfilename = wmvfilename.Substring(0, wmvfilename.Length -3 );
outputfilename += "oc.wmv";
string captionfilename = wmvfilename.Substring(0, wmvfilename.Length - 3);
captionfilename += ".smi";
int timeoptions = Convert.ToInt32(args[2]);
System.Console.WriteLine("wmvfilename:\t" + wmvfilename);
System.Console.WriteLine("jpgfillername:\t" + jpgfillername);
System.Console.WriteLine("timeoptions:\t" + timeoptions);
System.Console.WriteLine("output:\t" + outputfilename);
try
{
// sets file name to media item
mediaItem = new MediaItem(wmvfilename);
// challenge... these next three lines fix aspect ratio screen clipping that occurs when
// source is also wmv. ...unfortunately it also causes the captions not to burn into the video...
// mediaItem.OutputFormat.VideoProfile = new AdvancedVC1VideoProfile();
// mediaItem.OutputFormat.VideoProfile = mediaItem.SourceVideoProfile;
// mediaItem.OutputFormat.AudioProfile = mediaItem.SourceAudioProfile;
/*
mediaItem.OutputFormat.VideoProfile.AspectRatio = mediaItem.SourceVideoProfile.AspectRatio;
mediaItem.OutputFormat.VideoProfile = new AdvancedVC1VideoProfile();
mediaItem.OutputFormat.VideoProfile.Bitrate = new ConstantBitrate(200); // VariableConstrainedBitrate(200, 1500);
mediaItem.OutputFormat.VideoProfile.Streams[0].Size = new Size(320, 240);
mediaItem.OutputFormat.VideoProfile.Size = new Size(320, 240);
mediaItem.OutputFormat.VideoProfile.FrameRate = 30;
mediaItem.OutputFormat.VideoProfile.KeyFrameDistance = new TimeSpan(0, 0, 4); */
// audio on one didn't work out so this helped but blows up on others...
// mediaItem.OutputFormat.AudioProfile = new WmaAudioProfile();
// mediaItem.OutputFormat.AudioProfile.Bitrate = new ConstantBitrate(128); // VariableConstrainedBitrate(128, 192);
// mediaItem.OutputFormat.AudioProfile.Codec = AudioCodec.WmaProfessional;
// mediaItem.OutputFormat.AudioProfile.BitsPerSample = 24;
// captions
//mediaItem.Sources[0].CaptionFiles.Add(new CaptionFile(captionfilename));
// add trailer
mediaItem.Sources.Add(new Source(@""+jpgfillername+""));
mediaItem.Sources[1].Clips[0].EndTime = mediaItem.Sources[1].MediaFile.Duration + TimeSpan.FromSeconds(timeoptions);
}
catch (InvalidMediaFileException exp)
{
// Media file was invalid and it returns an error msg
Console.WriteLine(exp.ToString());
return;
}
// verifies encoding of file
Console.WriteLine("\nEncoding: {0}", wmvfilename );
// Create a job and the media item for the video we wish
// to encode.
Job job = new Job();
job.MediaItems.Add(mediaItem);
// Set up the progress callback function
job.EncodeProgress
+= new EventHandler<EncodeProgressEventArgs>(OnProgress);
// Set the output directory and encode.
job.OutputDirectory = Environment.CurrentDirectory;
job.DefaultMediaOutputFileName = outputfilename;
job.CreateSubfolder = false;
// encodes job
job.Encode();
job.Dispose();
}