C#-使用Azure Media Services异步编码视频并处理任务完成
我有一个ASP.NET MVC web应用程序,我想使用Azure Media Services对视频进行编码 由于此过程持续时间太长,我需要以异步方式运行它,这样用户就不会一直等待此操作的处理。此外,我还需要在任务结束时以某种方式处理该任务的执行 Azure Media Services文档提供了实现此功能的代码框架:C#-使用Azure Media Services异步编码视频并处理任务完成,c#,asynchronous,azure-media-services,C#,Asynchronous,Azure Media Services,我有一个ASP.NET MVC web应用程序,我想使用Azure Media Services对视频进行编码 由于此过程持续时间太长,我需要以异步方式运行它,这样用户就不会一直等待此操作的处理。此外,我还需要在任务结束时以某种方式处理该任务的执行 Azure Media Services文档提供了实现此功能的代码框架: static public IAsset EncodeToAdaptiveBitrateMP4Set(IAsset asset) { // Declare a new
static public IAsset EncodeToAdaptiveBitrateMP4Set(IAsset asset)
{
// Declare a new job.
IJob job = _context.Jobs.Create("Media Encoder Standard Job");
// Get a media processor reference, and pass to it the name of the
// processor to use for the specific task.
IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Standard");
// Create a task with the encoding details, using a string preset.
// In this case "Adaptive Streaming" preset is used.
ITask task = job.Tasks.AddNew("My encoding task",
processor,
"Adaptive Streaming",
TaskOptions.None);
// Specify the input asset to be encoded.
task.InputAssets.Add(asset);
// Add an output asset to contain the results of the job.
// This output is specified as AssetCreationOptions.None, which
// means the output asset is not encrypted.
task.OutputAssets.AddNew("Output asset",
AssetCreationOptions.None);
job.StateChanged += new EventHandler<JobStateChangedEventArgs>(JobStateChanged);
job.Submit();
job.GetExecutionProgressTask(CancellationToken.None).Wait();
return job.OutputMediaAssets[0];
}
private static void JobStateChanged(object sender, JobStateChangedEventArgs e)
{
// do something when job state changes
}
,我需要一些东西使作业在Azure Media Services中异步运行,并能够处理任务的结束(在编码结束时运行特定代码)
你能帮我吗?如果你需要更多信息,请大喊一声 我们建议您注册通知-有关更多信息,请参阅。只需:
await job.GetExecutionProgressTask(CancellationToken.None);
任务。继续执行
是一个起点。您必须在某个地方保留对任务的引用,以便它不会被收集(我不知道,这有点像货物崇拜,但我敢打赌它会起作用)。完成后,您必须使用浏览器中的信号器或轮询之类的工具来更新用户。
await job.GetExecutionProgressTask(CancellationToken.None);