📜 ⬆️ ⬇️

What is Windows Azure Media Services and how can they be used?


If you follow the cloud news, you probably already know that Windows Azure Media Services was used to broadcast the 2012 Olympic Games in London .

Let's see what they are and how they can be used.

If to simplify a little, then Windows Azure Media Services is technologies of the Microsoft Media Platform platform , and also our partners transferred mostly to the cloud. In other words, on the one hand, it is proven and familiar solutions, on the other hand, the ability to scale these solutions and integrate them into their own processes of encoding, broadcasting and distribution of media content.
')
Windows Azure Media Services provides the following services for building your own media services and applications:
Or, if you present all of the above in the form of a diagram, the architecture of Windows Azure Media Services will look like this:

If you take a closer look at the scheme, you can see another great feature of Windows Azure Media Services - they can be a source of media content for almost all types of devices currently on the market: from desktop computers to set-top boxes or smartphones.

And, of course, this remarkable functionality is available to the developer through the REST API, which allows you to develop solutions based on Windows Azure Media Services using any familiar, convenient or, for example, standard in the organization of technology. Developers on the .NET platform have access to the Windows Azure Media Services SDK for .NET, which conveniently wraps the provided REST API.

So now you have a general idea of ​​what Windows Azure Media Services is. Let's take a closer look at them.

Development of customer service


Mac and PC
Now you can develop for Mac and PC using Microsoft Silverlight. After some time, the SDK will be available for developing the client in Flash. Available Silverlight SDKs:
Smooth Streaming Client for Silverlight
Microsoft Media Platform: Player Framework for Silverlight

Windows 8
To develop WinRT applications under Windows 8, you can develop in HTML / JS, C # or C ++ using the following SDKs:
Smooth Streaming Client SDK for WinRT Windows 8applications
Microsoft Media Platform: Player Framework for WinRT Windows 8 Applications

Windows phone
Microsoft provides an SDK for building video applications on Windows Phone.
Smooth Streaming Client for Silverlight
Microsoft Media Platform: Player Framework for Silverlight

iOS devices
For iOS devices, including the iPhone, iPod, and iPad, Microsoft ships the Smooth Streaming SDK for iOS Devices with PlayReady.
Smooth Streaming SDK for iOS Devices with PlayReady

Android devices
Microsoft partners develop and deliver SDKs for these devices.

Xbox
Xbox supports Xbox LIVE apps with Smooth Streaming. The Xbox LIVE Application Development Kit (ADK) contains:
Smooth Streaming client for Xbox LIVE ADK
Microsoft Media Platform: Player Framework for Xbox LIVE ADK

Embedded and other devices
For embedded devices, such as TVs, set-top boxes, media players, etc., that is, for devices with their own framework to develop and work with media content, you can license packages for porting:
Smooth Streaming Client Porting Kit
Microsoft PlayReady Device Porting Kit

Work with the service part

To start working with Windows Azure Media Services, you must first create them in your Windows Azure management portal (it is currently in beta):


After the service state of the service is Active - it is ready to work.


After that, if you are a developer on .NET, and you already have Visual Studio 2010 SP1 installed, you need to install:
Now you are fully prepared to develop applications using Windows Azure Media Services.

Let's create a simple application that works with Windows Azure Media Services.

Create a project for .NET Framework 4 in Visual Studio. Add the following libraries to the project in the Reference:
Microsoft.WindowsAzure.MediaServices.Client.dll
\ Program Files (x86) \ Microsoft SDKs \ Windows Azure Media Services \ Services SDK \ v1.0 \

Microsoft.WindowsAzure.StorageClient.dll
\ Program Files \ Windows Azure SDK \ v1.6 \ bin \

Microsoft.Data.Edm.dll
(\ Program Files (x86) \ Microsoft WCF Data Services \ 5.0 \ bin \ .NETFramework \

Microsoft.Data.OData.dll
(\ Program Files (x86) \ Microsoft WCF Data Services \ 5.0 \ bin \ .NETFramework \

Microsoft.Data.Services.Client.dll
(\ Program Files (x86) \ Microsoft WCF Data Services \ 5.0 \ bin \ .NETFramework \

Microsoft.Data.Services.dll
(\ Program Files (x86) \ Microsoft WCF Data Services \ 5.0 \ bin \ .NETFramework \

System.Spatial.dll
(\ Program Files (x86) \ Microsoft WCF Data Services \ 5.0 \ bin \ .NETFramework \

System.Configuration

Add to the app.config of your Media Services account setup application:
<?xml version="1.0"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> </startup> <appSettings> <add key="accountName" value="Add-Media-Services-Account-Name" /> <add key="accountKey" value="Add-Media-Services-Account-Key" /> </appSettings> </configuration> 


Add variables to the code that point to the local video file and the existing folder for the results:
 private static readonly string _singleInputFilePath = Path.GetFullPath(@"C:\mediaFiles\interview.wmv"); private static readonly string _outputFilesFolder = Path.GetFullPath(@"C:\outputfiles"); 


Replace the using block in the file with the following:
 using System.Linq; using System; using System.Configuration; using System.IO; using System.Threading; using System.Collections.Generic; using Microsoft.WindowsAzure.MediaServices.Client; 


Determine the variables that will contain your account data:
 private static readonly string _accountKey = ConfigurationManager.AppSettings["accountKey"]; private static readonly string _accountName = ConfigurationManager.AppSettings["accountName"]; 


Define variables to reference the server context and the result of the work:
 private static CloudMediaContext _context = null; static string _outputAssetID = null; 


In the Main method, add the creation of the service context:
 _context = new CloudMediaContext(_accountName, _accountKey); 


Now you need to create and upload media data to the service:
 static IAsset CreateAndUploadAsset(string inputMediaFilePath) { IAsset theAsset = _context.Assets.Create(inputMediaFilePath, AssetCreationOptions.StorageEncrypted); Console.WriteLine("Asset name: " + theAsset.Name); Console.WriteLine("Asset ID: " + theAsset.Id); Console.WriteLine("Time created: " + theAsset.Created.Date.ToString()); Console.WriteLine("Encrypted status: " + theAsset.Options.ToString()); return theAsset; } IAsset asset = CreateAndUploadAsset(_singleInputFilePath); 


For transcoding tasks on the server, we will create several auxiliary functions:
 //   static void CreateEncodingJob(IAsset asset, string outputFolder) { IJob job = _context.Jobs.Create("My Encoding Job"); //  - IMediaProcessor processor = GetMediaProcessor("Windows Azure Media Encoder"); //    ITask task = job.Tasks.AddNew("My encoding task", processor, "H.264 256k DSL CBR", TaskCreationOptions.None); // ,   task.InputMediaAssets.Add(asset); //  Asset    task.OutputMediaAssets.AddNew("Output asset", true, AssetCreationOptions.None); //  . job.Submit(); //        CheckJobProgress(job.Id); //    Job job = GetJob(job.Id); //     IAsset outputAsset = job.OutputMediaAssets[0]; //     _outputAssetID = outputAsset.Id; //  SAS URL      string sasUrl = GetAssetSasUrl(outputAsset, TimeSpan.FromMinutes(30)); //  URL    string outFilePath = Path.GetFullPath(outputFolder + @"\" + "SasUrl.txt"); WriteToFile(outFilePath, sasUrl); } 


Secondary functions.

We are waiting for the end of work and display the status in the console:
 private static void CheckJobProgress(string jobId) { //    bool jobCompleted = false; //   const int JobProgressInterval = 20000; while (!jobCompleted) { //     Job IJob theJob = GetJob(jobId); //       switch (theJob.State) { case JobState.Finished: jobCompleted = true; Console.WriteLine(""); Console.WriteLine("********************"); Console.WriteLine("Job state: " + theJob.State + "."); Console.WriteLine("Please wait while local tasks complete..."); Console.WriteLine(); break; case JobState.Queued: case JobState.Scheduled: case JobState.Processing: Console.WriteLine("Job state: " + theJob.State + "."); Console.WriteLine("Please wait..."); Console.WriteLine(); break; case JobState.Error: break; default: Console.WriteLine(theJob.State.ToString()); break; } // ,      Thread.Sleep(JobProgressInterval); } } 


We are requesting a media processor:
 private static IMediaProcessor GetMediaProcessor(string mediaProcessor) { //         // MP4 to Smooth Streams Task // Windows Azure Media Encoder // PlayReady Protection Task // Smooth Streams to HLS Task // Storage Decryption // ,       var theProcessor = from p in _context.MediaProcessors where p.Name == mediaProcessor select p; //   IMediaprocessor. IMediaProcessor processor = theProcessor.First(); if (processor == null) throw new ArgumentException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unknown processor", mediaProcessor)); return processor; } 


Getting a Job Link:
 static IJob GetJob(string jobId) { //  Job  Id var job = from j in _context.Jobs where j.Id == jobId select j; //     IJob theJob = job.FirstOrDefault(); // ,  Job  :) if (theJob != null) return theJob; else Console.WriteLine("Job does not exist."); return null; } 


Getting SAS URL for encoding results:
 static String GetAssetSasUrl(IAsset asset, TimeSpan accessPolicyTimeout) { //   IAccessPolicy readPolicy = _context.AccessPolicies.Create("My Test Policy", accessPolicyTimeout, AccessPermissions.Read); //  locator,     asset    ILocator locator = _context.Locators.CreateSasLocator(asset, readPolicy, DateTime.UtcNow.AddMinutes(-5)); Console.WriteLine("Locator path: "); Console.WriteLine(locator.Path); Console.WriteLine(); //    mp4  -     - xml var theOutputFile = from f in asset.Files where f.Name.EndsWith(".mp4") select f; //  IQueryable  IFileInfo. IFileInfo theFile = theOutputFile.FirstOrDefault(); string fileName = theFile.Name; //   SAS URL var uriBuilder = new UriBuilder(locator.Path); uriBuilder.Path += "/" + fileName; Console.WriteLine("Full URL to file: "); Console.WriteLine(uriBuilder.Uri.AbsoluteUri); Console.WriteLine(); return uriBuilder.Uri.AbsoluteUri; } 


Auxiliary method of writing to the file:

 static void WriteToFile(string outFilePath, string fileContent) { StreamWriter sr = File.CreateText(outFilePath); sr.Write(fileContent); sr.Close(); 


It remains to add to Main:
 CreateEncodingJob(asset, _outputFilesFolder); 


And you can run our program.
Sample program results
 Asset name: interview Asset ID: nb:cid:UUID:xyzxyza-318a-4a47-b996-27353b23abc3 Time created: 5/24/2012 12:00:00 AM Encrypted status: StorageEncrypted Job state: Queued. Please wait... Job state: Processing. Please wait... Job state: Processing. Please wait... ******************** Job state: Finished. Please wait while local tasks complete... Locator path: https://MediaServicesServer.blob.core.windows.net/asset-zzzz374-1234-4c60-9da8-3daf 7a6dabcd?st=2012-05-24T21%3A59%3A55Z&se=2012-05-24T22%3A29%3A55Z&sr=c&si=b1a0cf8 f-45bf-4f77-a84a-a38c3f8a002d&sig=tWmPLPpNuQpEXvCd2Ik8rCfY5AqjII3gnWgi9ustBI4%3D Full URL to file: https:// MediaServicesServer.blob.core.windows.net/asset- zzzz374-1234-4c60-9da8-3daf 7a6dabcd/interview.mp4?st=2012-05-24T21%3A59%3A55Z&se=2012-05-24T22%3A29%3A55Z&s r=c&si=b1a0cf8f-45bf-4f77-a84a-a38c3f8a002d&sig=tWmPLPpNuQpEXvCd2Ik8rCfY5AqjII3g nWgi9ustBI4%3D 



So, we got acquainted with the services of Windows Azure Media Services and even tried to write a simple program that uses the simplest features provided by the services. More information about the services can be found at the following link: www.windowsazure.com/en-us/develop/net/how-to-guides/media-services

Source: https://habr.com/ru/post/150593/


All Articles