您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 .NET 的 Azure 媒体服务库Azure Media Services libraries for .NET

概述Overview

Microsoft Azure 媒体服务是一个可扩展的基于云的平台,使开发人员能够生成可缩放的媒体管理和传送应用程序。Microsoft Azure Media Services is an extensible cloud-based platform that enables developers to build scalable media management and delivery applications. 媒体服务基于 REST API,你可以使用这些 API 安全地上传、存储、编码和打包视频或音频内容,以供点播以及以实时流形式传送到各种客户端(例如,电视、电脑和移动设备)。Media Services is based on REST APIs that enable you to securely upload, store, encode, and package video or audio content for both on-demand and live streaming delivery to various clients (for example, TV, PC, and mobile devices).

有关详细信息,请参阅概述.NET 入门To learn more, see Overview and Getting started with .NET.

客户端库Client library

借助 Azure 媒体服务 .NET SDK 库可以使用 .NET 针对媒体服务编程。The Azure Media Services .NET SDK library enables you to program against Media Services using .NET. 使用 Azure 媒体服务客户端库可以针对媒体服务 API 进行连接、身份验证和开发。Use the Azure Media Services client library to connect, authenticate, and develop against Media Services APIs.

有关详细信息,请参阅使用 .NET SDK 开始传送点播内容For more information, see Get started with delivering content on demand using .NET SDK.

直接从 Visual Studio 包管理器控制台或使用 .NET Core CLI 安装 NuGet 包Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio 包管理器Visual Studio Package Manager

Install-Package windowsazure.mediaservices

代码示例Code Example

以下代码示例使用媒体服务 .NET SDK 执行下列任务:The following code example uses Media Services .NET SDK to perform the following tasks:

  • 创建编码作业。Create an encoding job.
  • 获取对 Media Encoder Standard 编码器的引用。Get a reference to the Media Encoder Standard encoder.
  • 指定使用自适应流式处理预设。Specify to use the Adaptive Streaming preset.
  • 将一个编码任务添加到该作业。Add a single encoding task to the job.
  • 指定要编码的输入资产。Specify the input asset to be encoded.
  • 创建一个输出资产用于接收编码的资产。Create an output asset to receive the encoded asset.
  • 提交作业。Submit the job.
/* Include this 'using' directive:
using Microsoft.WindowsAzure.MediaServices.Client;
*/

CloudMediaContext context = new CloudMediaContext(new Uri(mediaServiceRESTAPIEndpoint), tokenProvider);

// Get an uploaded asset.
IAsset asset = context.Assets.FirstOrDefault();

// Encode and generate the output using the "Adaptive Streaming" preset.
// 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 = context.MediaProcessors.Where(p => p.Name == mediaProcessorName)
    .ToList().OrderBy(p => new Version(p.Version)).LastOrDefault();
if (processor == null) 
{
    throw new ArgumentException(string.Format("Unknown media processor", mediaProcessorName));
}

// 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.Submit();
job.GetExecutionProgressTask(CancellationToken.None).Wait();

示例Samples

查看 Azure 媒体服务示例的完整列表View the complete list of Azure Media Services samples.