• WindowsAzure.MediaServices.Extensions NuGet package 2.0.0 released!

    Published by on December 18th, 2013 1:19 am under Media, NuGet, Windows Azure Media Services

    No Comments

    Windows Azure Media ServicesLast week, the Windows Azure Media Services (WAMS) team published a new release of the WindowsAzure.MediaServices.Extensions NuGet package (2.0.0). Starting from this new version, the WAMS team will be taking ownership of the NuGet package and the Extensions source code to make sure that they are aligned and consistent with the Windows Azure Media Services .NET SDK. The Extensions source code was moved to a new GitHub repository under the WindowsAzure organization: https://github.com/WindowsAzure/azure-sdk-for-media-services-extensions (the previous GitHub repository is already deprecated).

    The following are some of the highlights for this new NuGet package release:

    • It targets the WindowsAzure.MediaServices NuGet package 3.0.0 (or higher). This is latest version of the Windows Azure Media Services .NET SDK.
    • It does not add source code files to your project anymore. Now, the extensions are shipped in the Microsoft.WindowsAzure.MediaServices.Client.Extensions assembly that is added as a reference to your project.
    • It contains several breaking changes with the previous extensions (1.0.6). Most of them are related to a different organization of the extension methods (to avoid defining all of them for CloudMediaContext class) and renaming.
    • It contains new extensions for creating assets by automatically selecting one of the Storage accounts attached to the Media Services account based on different strategies.

    Breaking Changes

    The following are the breaking changes with the previous Nuget package version (1.0.6). For more information, you can check the README documentation.

    Create Asset from single local file

    // Original extension (there are additional overloads)

    public static IAsset CreateAssetFromFile(

      this CloudMediaContext context, string filePath, AssetCreationOptions options)

     

    // New extension (there are additional overloads)

    public static IAsset CreateFromFile(

      this AssetBaseCollection assets, string filePath, AssetCreationOptions options)

    Create Asset from local folder

    // Original extension (there are additional overloads)

    public static IAsset CreateAssetFromFolder(

      this CloudMediaContext context, string folderPath, AssetCreationOptions options)

     

    // New extension (there are additional overloads)

    public static IAsset CreateFromFolder(

      this AssetBaseCollection assets, string folderPath, AssetCreationOptions options)

    Generate Asset Files from Blob storage

    // Original extension

    public static void CreateAssetFiles(this CloudMediaContext context, IAsset asset)

     

    // New extension

    public static void GenerateFromStorage(this IAsset asset)

    Download Asset Files to local folder

    // Original extension (there are additional overloads)

    public static void DownloadAssetFilesToFolder(this CloudMediaContext context, IAsset asset, string folderPath)

     

    // New extension (there are additional overloads)

    public static void DownloadToFolder(this IAsset asset, string folderPath)

    Create Locator

    // Original extension (there are additional overloads)

    public static ILocator CreateLocator(

      this CloudMediaContext context, IAsset asset, LocatorType locatorType, AccessPermissions permissions, TimeSpan duration)

     

    // New extension (there are additional overloads)

    public static ILocator Create(

      this LocatorBaseCollection locators, LocatorType locatorType, IAsset asset, AccessPermissions permissions, TimeSpan duration)

    Create a Job with a single Task

    // Original extension (there is an additional overload)

    public static IJob PrepareJobWithSingleTask(

      this MediaContextBase context, string mediaProcessorName, string taskConfiguration, IAsset inputAsset, string outputAssetName, AssetCreationOptions outputAssetOptions)

     

    // New extension (there is an additional overload)

    public static IJob CreateWithSingleTask(

      this JobBaseCollection jobs, string mediaProcessorName, string taskConfiguration, IAsset inputAsset, string outputAssetName, AssetCreationOptions outputAssetOptions)

    Start Job execution progress task

    // Original extension (there is an additional overload)

    public static Task<IJob> StartExecutionProgressTask(

      this MediaContextBase context, IJob job, Action<IJob> executionProgressChangedCallback, CancellationToken cancellationToken)

     

    // New extension (there is an additional overload)

    public static Task<IJob> StartExecutionProgressTask(

      this IJob job, Action<IJob> executionProgressChangedCallback, CancellationToken cancellationToken)

    Removed extensions

    // These extensions were removed because they were not related to Media Services.

    public static void Save(this Uri uri, string filePath)

    public static void Save(this string url, string filePath)

    Sample Workflow using the Extensions

    The following sample code shows a basic media workflow that uses the new Windows Azure Media Services .NET SDK Extensions NuGet package.

    try

    {

        MediaServicesCredentials credentials = new MediaServicesCredentials("%accountName%", "%accountKey%");

        CloudMediaContext context = new CloudMediaContext(credentials);

     

        Console.WriteLine("Creating new asset from local file...");

     

        // 1. Create a new asset by uploading a mezzanine file from a local path.

        IAsset inputAsset = context.Assets.CreateFromFile(

            "smallwmv1.wmv",

            AssetCreationOptions.None,

            (af, p) =>

            {

                Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress);

            });

     

        Console.WriteLine("Asset created.");

     

        // 2. Prepare a job with a single task to transcode the previous mezzanine asset

        //    into a multi-bitrate asset.

        IJob job = context.Jobs.CreateWithSingleTask(

            MediaProcessorNames.WindowsAzureMediaEncoder,

            MediaEncoderTaskPresetStrings.H264AdaptiveBitrateMP4Set720p,

            inputAsset,

            "Sample Adaptive Bitrate MP4",

            AssetCreationOptions.None);

     

        Console.WriteLine("Submitting transcoding job...");

     

        // 3. Submit the job and wait until it is completed.

        job.Submit();

        job = job.StartExecutionProgressTask(

            j =>

            {

                Console.WriteLine("Job state: {0}", j.State);

                Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress());

            },

            CancellationToken.None).Result;

     

        Console.WriteLine("Transcoding job finished.");

     

        IAsset outputAsset = job.OutputMediaAssets[0];

     

        Console.WriteLine("Publishing output asset...");

     

        // 4. Publish the output asset by creating an Origin locator for adaptive streaming, 

        // and a SAS locator for progressive download.

        context.Locators.Create(

            LocatorType.OnDemandOrigin,

            outputAsset,

            AccessPermissions.Read,

            TimeSpan.FromDays(30));

        context.Locators.Create(

            LocatorType.Sas,

            outputAsset,

            AccessPermissions.Read,

            TimeSpan.FromDays(30));

     

        IEnumerable<IAssetFile> mp4AssetFiles = outputAsset

                .AssetFiles

                .ToList()

                .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase));

     

        // 5. Generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming, 

        // and the Progressive Download URL.

        Uri smoothStreamingUri = outputAsset.GetSmoothStreamingUri();

        Uri hlsUri = outputAsset.GetHlsUri();

        Uri mpegDashUri = outputAsset.GetMpegDashUri();

        List<Uri> mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).ToList();

     

        // 6. Get the asset URLs.

        Console.WriteLine(smoothStreamingUri);

        Console.WriteLine(hlsUri);

        Console.WriteLine(mpegDashUri);

        mp4ProgressiveDownloadUris.ForEach(uri => Console.WriteLine(uri));

     

        Console.WriteLine("Output asset available for adaptive streaming and progressive download.");

     

        string outputFolder = "job-output";

        if (!Directory.Exists(outputFolder))

        {

            Directory.CreateDirectory(outputFolder);

        }

     

        Console.WriteLine("Downloading output asset files to local folder...");

     

        // 7. Download the output asset to a local folder.

        outputAsset.DownloadToFolder(

            outputFolder,

            (af, p) =>

            {

                Console.WriteLine("Downloading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress);

            });

     

        Console.WriteLine("Output asset files available at '{0}'.", Path.GetFullPath(outputFolder));

     

        Console.WriteLine("VOD workflow finished.");

    }

    catch (Exception exception)

    {

        // Parse the XML error message in the Media Services response and create a new 

        // exception with its content.

        exception = MediaServicesExceptionParser.Parse(exception);

     

        Console.Error.WriteLine(exception.Message);

    }

    finally

    {

        Console.ReadLine();

    }

    As usual, if you want to report a bug, send feedback or propose new extensions, you can open a new issue in the azure-sdk-for-media-services-extensions GitHub repository.

    Enjoy!

    Tags: , , , ,

About

Mariano Converti Profile Picture
Mariano Converti

Map