微软Azure的多媒体编码服务示例
这篇文章是介绍 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的多媒体编码服务示例的更多相关文章
- 微软Azure虚拟机备份服务在中国发布
近期,Azure虚拟机备份服务在微软智能云上发布. 相关功能阐述: Azure IaaS虚拟机备份服务针对Windows操作系统,提供了应用一致性的备份技术:同时针对Linux操作系统,提供了文件系统 ...
- (视频) 《快速创建网站》1. 网站管理平台WordPress & 微软Azure 云计算简介
网站并不神秘,过节了,在家闲的没事的,自己建个网站玩玩吧.每段视频不超过15分钟,地铁/公交/睡前/醒来看一段,几天之后变身建站专家,找老板加薪去! 在普通人眼里,创建网站是专业开发人员和IT工程师才 ...
- 多云时代,海外微软Azure云与国内阿里云专线打通性能测试
本文地址:http://www.cnblogs.com/taosha/p/6528730.html 在云计算的大时代,大型客户都有业务全球拓展的需求,考虑到成本,时间因素,一般都是选择云计算,现在云计 ...
- 微软Azure 经典模式下创建内部负载均衡(ILB)
微软Azure 经典模式下创建内部负载均衡(ILB) 使用之前一定要注意自己的Azure的模式,老版的为cloud service模式,新版为ARM模式(资源组模式) 本文适用于cloud servi ...
- Windows Azure HandBook (2) Azure China提供的服务
<Windows Azure Platform 系列文章目录> 对于传统的自建数据中心,从底层的Network,Storage,Servers,Virtualization,中间层的OS, ...
- 走进云背后:微软Azure web 项目通过web service部署web site
探索云那不为人知的故事(一):Web Services部署web site 前奏:Windows Azure是微软基于云计算的操作系统,现在更名为“Microsoft Azure”,和Azure Se ...
- 直传文件到Azure Storage的Blob服务中
(此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:为了庆祝获得微信公众号赞赏功能,忙里抽闲分享一下最近工作的一点心得:如何直接从浏览器中上传文件到Azure ...
- 免费电子书:微软Azure基础之Azure Automation
(此文章同时发表在本人微信公众号"dotNET每日精华文章") Azure Automation是Azure内置的一项自动化运维基础功能,微软为了让大家更快上手使用这项功能,特意推 ...
- 如何使用 OneAPM 监控微软 Azure Cloud Service ?
不知不觉微软 Azure 已经进入中国市场近两年的时间.那么 Azure 平台的性能究竟如何?资源加载的延迟.虚拟机的稳定性等问题是否切实满足客户期许.这些都是大家对微软 Azure 这个国外的云服务 ...
随机推荐
- 解决php json_encode 出现的中文转码、乱码问题
// 防止json中文转码 function jsonEncodeWithCN($data) { return preg_replace("/\\\u([0-9a-f]{4})/ie&quo ...
- (转载)使用ADOConnet.BeginTrans后,出现错误提示:无法在此会话中启动更多的事务?
Q: 三层结构,在服务器端使用adoconnection连接到sqlserver2000,然后想在 datasetprovider的beforupdaterecord中使用语句: try adocon ...
- 关于JAVA面向对象基础整理以及个人的理解(适合初学者阅读)
JAVA的基础语法等都跟C有很大的相似之处,所以这里就不多啰嗦了.直接从数组开始. 数组: 1.声明 int [] a; 在声明的过程中,并没有分配空间给数组.我们可以在声明的同时,用new来分配相应 ...
- NSAssert使用摘抄
#define NSAssert(condition, desc, ...) 只有条件condition满足,才会执行下一个语句,否则输出断言错误. 例如: NSAssert(1 != 2, @&qu ...
- mysql之——存储过程 + 游标 + 事务
下面是自己曾经编写过的mysql数据库存储过程,留作存档,以后用到的时候拿来参考. 其中,涉及到了存储过程.游标(双层循环).事务. [说明]:代码中的注释只针对当时业务而言,无须理会. 代码如下: ...
- web前端开发分享-css,js进阶篇
一,css进阶篇: 等css哪些事儿看了两三遍之后,需要对看过的知识综合应用,这时候需要大量的实践 经验, 简单的想法:把qq首页全屏另存为jpg然后通过ps工具切图结合css转换成html,有无 从 ...
- codeforces 390C Inna and Candy Boxes
这个题目看似不是很好下手,不过很容易发现每次询问的时候总是会问到第r个盒子是否有糖果: 这样的话就很好办事了: 维护两个数组: 一个sum数组:累加和: 一个in数组:如果i位是1的话,in[i]=i ...
- Codeforces Round #211 (Div. 2)
难得一次比赛能够自己成功A掉四个题: A题:水题,模拟一下就行: #include <iostream> #include <cstdio> using namespace s ...
- 年度十佳 DevOps 博客文章(前篇)
如果说 15 年你还没有将 DevOps 真正应用起来,16 年再不实践也未免太落伍了.国内 ITOM 领军企业 OneAPM 工程师为您翻译整理了,2015 年十佳 DevOps 文章,究竟是不是深 ...
- 使用flask的时候遇到的问题及其解答
在网上看到了mircoblog的这个web程序,用flask框架写的,自己就在windows的环境下实现了下. 1.这个博客系统用到了一个flask插件叫flask_Login 里面涉及到编码解码的问 ...