Advanced encoding with Media Encoder Premium Workflow

media services logo


Media Encoder Premium Workflow media processor discussed in this article is not available in China.


Microsoft Azure Media Services is introducing the Media Encoder Premium Workflow media processor. This processor offers advance encoding capabilities for your premium on-demand workflows.

The following topics outline details related to Media Encoder Premium Workflow:

This article demonstrates how to encode with Media Encoder Premium Workflow using .NET.

Encoding tasks for the Media Encoder Premium Workflow require a separate configuration file, called a Workflow file. These files have a .workflow extension and are created using the Workflow Designer tool.

You can also get the default workflow files here. The folder also contains the description of these files.

The workflow files need to be uploaded to your Media Services account as an Asset, and this Asset should be passed in to the encoding Task.

Create and configure a Visual Studio project

Set up your development environment and populate the app.config file with connection information, as described in Media Services development with .NET.

Encoding example

The following example demonstrates how to encode with Media Encoder Premium Workflow.

The following steps are performed:

  1. Create an asset and upload a workflow file.

  2. Create an asset and upload a source media file.

  3. Get the "Media Encoder Premium Workflow" media processor.

  4. Create a job and a task.

    In most cases, the configuration string for the task is empty (like in the following example). There are some advanced scenarios (that require you to set runtime properties dynamically) in which case you would provide an XML string to the encoding task. Examples of such scenarios are: creating an overlay, parallel or sequential media stitching, subtitling.

  5. Add two input assets to the task.

    1. 1st – the workflow asset.

    2. 2nd – the video asset.


      The workflow asset must be added to the task before the media asset. The configuration string for this task should be empty.

  6. Submit the encoding job.

using System;
using System.Linq;
using System.Configuration;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.MediaServices.Client;

namespace MediaEncoderPremiumWorkflowSample
    class Program
        private static readonly string _AADTenantDomain =
        private static readonly string _RESTAPIEndpoint =
        private static readonly string _AMSClientId =
        private static readonly string _AMSClientSecret =

        // Field for service context.
        private static CloudMediaContext _context = null;

        private static readonly string _supportFiles =

        private static readonly string _workflowFilePath =
            Path.GetFullPath(_supportFiles + @"\H264 Progressive Download MP4.workflow");

        private static readonly string _singleMP4InputFilePath =
            Path.GetFullPath(_supportFiles + @"\BigBuckBunny.mp4");

        static void Main(string[] args)

            AzureAdTokenCredentials tokenCredentials =
                new AzureAdTokenCredentials(_AADTenantDomain,
                    new AzureAdClientSymmetricKey(_AMSClientId, _AMSClientSecret),

            var tokenProvider = new AzureAdTokenProvider(tokenCredentials);

            _context = new CloudMediaContext(new Uri(_RESTAPIEndpoint), tokenProvider);

            var workflowAsset = CreateAssetAndUploadSingleFile(_workflowFilePath);
            var videoAsset = CreateAssetAndUploadSingleFile(_singleMP4InputFilePath);
            IAsset outputAsset = CreateEncodingJob(workflowAsset, videoAsset);


        static public IAsset CreateAssetAndUploadSingleFile(string singleFilePath)
            var assetName = "UploadSingleFile_" + DateTime.UtcNow.ToString();
            var asset = _context.Assets.Create(assetName, AssetCreationOptions.None);

            var fileName = Path.GetFileName(singleFilePath);

            var assetFile = asset.AssetFiles.Create(fileName);

            Console.WriteLine("Created assetFile {0}", assetFile.Name);

            Console.WriteLine("Upload {0}", assetFile.Name);

            Console.WriteLine("Done uploading {0}", assetFile.Name);

            return asset;

        static public IAsset CreateEncodingJob(IAsset workflow, IAsset video)
            // Declare a new job.
            IJob job = _context.Jobs.Create("Premium Workflow encoding job");
            // Get a media processor reference, and pass to it the name of the
            // processor to use for the specific task.
            IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Premium Workflow");

            // Create a task with the encoding details, using a string preset.
            ITask task = job.Tasks.AddNew("Premium Workflow encoding task",

            // Specify the input asset to be encoded.
            task.InputAssets.Add(video); // we add one 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",

            // Use the following event handler to check job progress.  
            job.StateChanged += new

            // Launch the job.

            // Check job execution and wait for job to finish.
            Task progressJobTask = job.GetExecutionProgressTask(CancellationToken.None);

            // 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)
                throw new Exception("\nExiting method due to job error.");

            return job.OutputMediaAssets[0];

        static private 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("Job is finished.");
                case JobState.Canceling:
                case JobState.Queued:
                case JobState.Scheduled:
                case JobState.Processing:
                    Console.WriteLine("Please wait...\n");
                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);
        private static IMediaProcessor GetLatestMediaProcessorByName(string mediaProcessorName)
            var 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));

            return processor;

Need help?

You can open a support ticket by navigating to New support request

Media Services learning paths

Media Services v3 (latest)

Check out the latest version of Azure Media Services!

Media Services v2 (legacy)

Provide feedback

Use the User Voice forum to provide feedback and make suggestions on how to improve Azure Media Services. You also can go directly to one of the following categories: