这篇文章是介绍 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. 总结源码编译安装mysql

    最近在学习源码编译安装LAMP.LNMP时,一直遇到一个难题,就是就是mysql无论怎么源码编译安装,到最后启动服务都提示"Starting MySQL.The server quit wi ...

  2. 简单的powershell 批量生成身份证复印件

    用Powshell 脚本批量完成,代码比较简单,出生日期,图片我都没有改,图片用于测试,附件. cls; $path = Split-Path -Parent $MyInvocation.MyComm ...

  3. Python设计模式——建造者模式

    需求,画人物,要求画一个人的头,左手,右手,左脚,右脚和身体,画一个瘦子,一个胖子 不使用设计模式 #encoding=utf-8 __author__ = 'kevinlu1010@qq.com' ...

  4. Quartz Sheduler 入门

    Quartz Sheduler 入门 原文地址:http://www.quartz-scheduler.org/generated/2.2.2/html/qtz-all/ 下载地址:http://qu ...

  5. .net 访问远程的MSSQL报System.AccessViolationException错误的解决方法

    访问远程的数据库时 报错,本地数据库正常 netsh winsock reset   --运行此命令,解决. netsh winsock reset命令,作用是重置 Winsock 目录.如果一台机器 ...

  6. 网站开启Gzip压缩-apache

    找到并打开apache/conf目录中的httpd.conf文件 httpd.conf中打开deflate_Module和headers_Module模块,具体做法为将 如下两句前面的#去掉: Loa ...

  7. webpack打包sass

    首先,需要支持sass,不管是有ruby环境的sass,还是node-sass,用npm装的sass模块,bootstrap-sass,gulp-sass..总归要有一个吧!(这里采用node-sas ...

  8. Memcached总结三:Memcached常用命令及使用说明

    一.存储命令 存储命令的格式: 1 2 <command name> <key> <flags> <exptime> <bytes> < ...

  9. easyui源码翻译1.32--Pagination(分页)

    前言 使用$.fn.pagination.defaults重写默认值对象下载该插件翻译源码 该分页控件允许用户导航页面的数据.它支持页面导航和页面长度选择的选项设置.用户可以在分页控件上添加自定义按钮 ...

  10. *[codility]Number-of-disc-intersections

    http://codility.com/demo/take-sample-test/beta2010/ 这题以前做的时候是先排序再二分,现在觉得没有必要.首先圆可以看成线段,把线段的进入作为一个事件, ...