这篇文章是介绍 Azure 媒体服务编程系列之一。以前的主题是如何: 获得媒体处理器.

为服务器上的媒体内容,可以对内容与大量的媒体编码和格式使用 Azure Media 编码器进行编码。您还可以使用编码器提供的媒体服务的合作伙伴 ;第三方编码器可以使用通过Azure 市场。您可以指定编码任务,通过使用编码器预设的字符串,或通过使用配置文件的详细的信息。

MP4 自适应比特率集

编码,建议你到夹层文件到 MP4 自适应比特率设置,然后使用动态的包装,以提供您的内容。更多的信息,请参阅创建与媒体服务 SDK.net 编码作业动态打包交付内容.

MP4 编码

下面的方法将上载单个资产并创建作业,以编码到 MP4 使用资产"H264 宽带 720 p"预设,将创建一个单一的 MP4 使用 H264 编码在 720p 分辨率:

    static IJob CreateEncodingJob(string inputMediaFilePath, string outputFolder)
{
//Create an encrypted asset and upload to storage.
IAsset asset = CreateAssetAndUploadSingleFile(AssetCreationOptions.StorageEncrypted,
inputMediaFilePath); // Declare a new job. IJob job = _context.Jobs.Create("My encoding job"); // Get a reference to the Azure Media Encoder
IMediaProcessor processor = GetLatestMediaProcessorByName("Azure Media Encoder"); // Create a task with the encoding details, using a string preset.
ITask task = job.Tasks.AddNew("My encoding task",
processor,
"H264 Broadband 720p",
_protectedConfig); // 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 in the clear (unencrypted).
task.OutputAssets.AddNew("Output asset", AssetCreationOptions.None); // Use the following event handler to check job progress.
job.StateChanged += new EventHandler<JobStateChangedEventArgs>(StateChanged); // Launch the job.
job.Submit(); // Optionally log job details. This displays basic job details
// to the console and saves them to a JobDetails-JobId.txt file
// in your output folder.
LogJobDetails(job.Id); // Check job execution and wait for job to finish.
Task progressJobTask = job.GetExecutionProgressTask(CancellationToken.None);
progressJobTask.Wait(); // If job state is Error, the event handling
// method for job progress should log errors. Here we check
// for error state and exit if needed.
if (job.State == JobState.Error)
{
Console.WriteLine("\nExiting method due to job error.");
return job;
} // Perform other tasks. For example, access the assets that are the output of a job,
// either by creating URLs to the asset on the server, or by downloading.
return job;
} private static void StateChanged(object sender, JobStateChangedEventArgs e)
{
Console.WriteLine("Job state changed event:");
Console.WriteLine(" Previous state: " + e.PreviousState);
Console.WriteLine(" Current state: " + e.CurrentState);
switch (e.CurrentState)
{
case JobState.Finished:
Console.WriteLine();
Console.WriteLine("Job is finished. Please wait while local tasks or downloads complete...");
break;
case JobState.Canceling:
case JobState.Queued:
case JobState.Scheduled:
case JobState.Processing:
Console.WriteLine("Please wait...\n");
break;
case JobState.Canceled:
case JobState.Error: // Cast sender as a job.
IJob job = (IJob)sender; // Display or log error details as needed.
LogJobStop(job.Id);
break;
default:
break;
}
}

流媒体编码

如果你想要对某个光媒体的视频编码有两个选项:

  • 直接编码为流媒体
  • 编码为 MP4,然后转换为流媒体

直接编码为流媒体使用以上所示的代码,但使用流媒体编码器预设之一。编码器预设的完整列表,请参见任务预设字符串 Azure 媒体编码器.

若要将 MP4 转换为流媒体,请使用 Azure 媒体包。Azure 媒体包装不支持字符串预设,因此你必须在 XML 中指定的配置选项。可以在任务预设 Azure 媒体包装找到 MP4 转换为流媒体所需的 XML。复制并粘贴到您的项目中名为 MediaPackager_MP4ToSmooth.xml 的文件的 XML。下面的代码演示如何将 MP4 资产转换为流媒体。下面是一个简单示例:

private static IJob ConvertMP4toSmooth(IAsset assetToConvert, string configFilePath)
{
// Declare a new job to contain the tasks
IJob job = _context.Jobs.Create("Convert to Smooth Streaming job");
// Set up the first Task to convert from MP4 to Smooth Streaming.
// Read in task configuration XML
string configMp4ToSmooth = File.ReadAllText(Path.GetFullPath(configFilePath + @"\MediaPackager_MP4ToSmooth.xml"));
// Get a media packager reference
IMediaProcessor processor = GetLatestMediaProcessorByName("Azure Media Packager");
// Create a task with the conversion details, using the configuration data
ITask task = job.Tasks.AddNew("My Mp4 to Smooth Task",
processor,
configMp4ToSmooth,
TaskOptions.None);
// Specify the input asset to be converted.
task.InputAssets.Add(assetToConvert);
// Add an output asset to contain the results of the job.
task.OutputAssets.AddNew("Streaming output asset", AssetCreationOptions.None);
// Use the following event handler to check job progress.
// The StateChange method is the same as the one in the previous sample
job.StateChanged += new EventHandler<JobStateChangedEventArgs>(StateChanged);
// Launch the job.
job.Submit();
// Check job execution and wait for job to finish.
Task progressJobTask = job.GetExecutionProgressTask(CancellationToken.None);
progressJobTask.Wait();
// Get a refreshed job reference after waiting on a thread.
job = GetJob(job.Id);
// Check for errors
if (job.State == JobState.Error)
{
Console.WriteLine("\nExiting method due to job error.");
}
return job;
}

微软Azure的多媒体编码服务示例的更多相关文章

  1. 微软Azure虚拟机备份服务在中国发布

    近期,Azure虚拟机备份服务在微软智能云上发布. 相关功能阐述: Azure IaaS虚拟机备份服务针对Windows操作系统,提供了应用一致性的备份技术:同时针对Linux操作系统,提供了文件系统 ...

  2. (视频) 《快速创建网站》1. 网站管理平台WordPress & 微软Azure 云计算简介

    网站并不神秘,过节了,在家闲的没事的,自己建个网站玩玩吧.每段视频不超过15分钟,地铁/公交/睡前/醒来看一段,几天之后变身建站专家,找老板加薪去! 在普通人眼里,创建网站是专业开发人员和IT工程师才 ...

  3. 多云时代,海外微软Azure云与国内阿里云专线打通性能测试

    本文地址:http://www.cnblogs.com/taosha/p/6528730.html 在云计算的大时代,大型客户都有业务全球拓展的需求,考虑到成本,时间因素,一般都是选择云计算,现在云计 ...

  4. 微软Azure 经典模式下创建内部负载均衡(ILB)

    微软Azure 经典模式下创建内部负载均衡(ILB) 使用之前一定要注意自己的Azure的模式,老版的为cloud service模式,新版为ARM模式(资源组模式) 本文适用于cloud servi ...

  5. Windows Azure HandBook (2) Azure China提供的服务

    <Windows Azure Platform 系列文章目录> 对于传统的自建数据中心,从底层的Network,Storage,Servers,Virtualization,中间层的OS, ...

  6. 走进云背后:微软Azure web 项目通过web service部署web site

    探索云那不为人知的故事(一):Web Services部署web site 前奏:Windows Azure是微软基于云计算的操作系统,现在更名为“Microsoft Azure”,和Azure Se ...

  7. 直传文件到Azure Storage的Blob服务中

    (此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:为了庆祝获得微信公众号赞赏功能,忙里抽闲分享一下最近工作的一点心得:如何直接从浏览器中上传文件到Azure ...

  8. 免费电子书:微软Azure基础之Azure Automation

    (此文章同时发表在本人微信公众号"dotNET每日精华文章") Azure Automation是Azure内置的一项自动化运维基础功能,微软为了让大家更快上手使用这项功能,特意推 ...

  9. 如何使用 OneAPM 监控微软 Azure Cloud Service ?

    不知不觉微软 Azure 已经进入中国市场近两年的时间.那么 Azure 平台的性能究竟如何?资源加载的延迟.虚拟机的稳定性等问题是否切实满足客户期许.这些都是大家对微软 Azure 这个国外的云服务 ...

随机推荐

  1. eclipse:java.lang.OutOfMemoryError: PermGen space 最简单的解决方式

    我使用的工具是STS, Eclipse同理: 打开如下界面: 左则选择项目启动使用的Tomcat-->在右侧面板Tab项中选择" Arguments":在VM argumen ...

  2. java枚举类型enum的使用

    2015-10-24 java达人 Java 中 的枚举类型采用关键字enum 来定义,从jdk1.5才有的新类型,所有的枚举类型都是继承自Enum 类型.要了解枚举类型,建议大家先打开jdk 中的E ...

  3. MVC5 ModelBinder

    MVC5 ModelBinder 什么是ModelBinding ASP.NET MVC中,所有的请求最终都会到达某个Controller中的某个Action并由该Action负责具体的处理和响应.为 ...

  4. 利用Multipeer Connectivity框架进行WiFi传输-b

    什么是Multipeer Connectivity? 在iOS7中,引入了一个全新的框架——Multipeer Connectivity(多点连接).利用Multipeer Connectivity框 ...

  5. Memcached(六)Memcached的并发实例

    package com.sinosuperman.memcached; import java.io.IOException; import java.net.InetSocketAddress; i ...

  6. 通过 SignalR 类库,实现 ASP.NET MVC 的实时通信

    在本文中,您将学到在现有 ASP.NET MVC 框架的 CRUD 项目中,如何使用 SignalR 类库,显示来自数据库的实时更新.在这一主题中,我们将重点放在在现有 ASP.NET MVC 框架的 ...

  7. MySQL JDBC的setFetchSize

    MySQL JDBC的setFetchSize http://uuhorse.iteye.com/blog/2163582 http://blog.sina.com.cn/s/blog_6706203 ...

  8. Ubuntu 14.04远程登录服务器--ssh的安装和配置

    ssh是一种安全协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全,现在介绍一下如何在Ubuntu 14.04上安装和配置ssh 1.更新源列表 打开"终端窗口",输入& ...

  9. easyui表单提交,后台获取不到值

    J2ee开发,使用easyui表单提交,在ie中可以正常将参数传递到后台,但使用firefox,chrome都无法将easyui的combobox值传递到后台,使用alert($('#form').s ...

  10. AD设计中,三种大面积覆铜的区别

    在AD设计中,主要有三种大面积覆铜方式,分别是Fill(铜皮) Polygon Pour(灌铜)和Plane(平面层),这三种方式刚开始的时候没有细细区分,现在分别应用了一下, 总结如下,欢迎指正 F ...