Questions? Feedback? powered by Olark live chat software
Hopp over navigasjon

How to Use Premium Encoding in Azure Media Services

Posted on 6 mars, 2015

Senior Program Manager, Azure Media Services
Premium encoding is an exciting new technology in Azure Media Services that can solve your most complicated encoding workflows. I have provided you an overview of the new premium encoding capabilities in Azure Media Services in a companion blog. In this blog I will provide a few technical details about the premium encoder, and sample code for using this new feature.
Note: You can use the premium encoder irrespective of the type of encoding reserved unit (RU) you have in your account. Using the premium encoder does not require you to have a Premium RU.

Supported Formats

You should refer to our documentation center for up-to-date information about the file formats and codecs supported by the premium encoder. In the initial release, the premium encoder includes support for the following formats.

Ingest Formats

  • Input Container/File Formats: F4V, MXF, GXF, MPEG transport streams and program streams, MP4, ASF, and AVI
  • Input Video Codecs: AVC/AVCIntra, DNxHD, DVCPro/DVCProHD, MPEG-2, MPEG-1 and VC-1
  • Input Audio Codecs: AES, Dolby® E, Dolby® Digital (AC3), AAC, MPEG Layer 2, MP3, WMA, and WAV/PCM

Output Formats

  • Output Container/File Formats: F4V, MXF, DPP, GXF,  MP4, MPEG TS, ASF, and AVI
  • Output Video Codecs: AVC/AVCIntra, DNxHD, DVCPro/DVCProHD, JPEG2000, MPEG-2, MPEG-1 and VC-1
  • Output Audio Codecs: AES, Dolby® Digital (AC3), Dolby® Digital Plus (E-AC3), AAC, MPEG Layer 2, MP3, and WMA

Support for Closed Captioning

In the initial release, the premium encoder supports closed captioning when it is interleaved into the source or input media file: essentially, CEA-608/CEA-708 carried as user data (SEI messages of H.264 elementary streams, ATSC/53, SCTE20) or carried as ancillary data in MXF/GXF files. On output, the following options are available for repackaging CEA 608/708 in the input:
  • CEA-608 to CEA-708 translation
  • CEA-608/CEA-708 pass through (embedded in SEI messages of H.264 elementary streams, or carried as ancillary data in MXF files)
  • SCC
  • SMPTE Timed Text (from source CEA-608 per SMPTE RP2052; including DFXP file creation)
  • SRT Subtitle file
  • DVB subtitle streams
Note: not all of the above output formats are supported for delivery via streaming in Azure Media Services.

Using AMS Explorer to submit Tasks

By far, the easiest way to submit encoding Tasks to the premium encoder is to use the Azure Media Services Explorer  – you can read more about this easy to use tool in this blog. You begin by selecting the video Asset that you want to encode in the Assets tab:
Pick the video Asset you want to encode Pick the video Asset you want to encode
  Select the asset, right click and select “Encode asset(s) with Media Encoder Premium Workflow…”  
Encode with Premium Encoder Encode with Premium Encoder
  The dialog box for Premium Encoding opens. You need to select a workflow. The dialog box displays the workflows that have been already uploaded to your Media Services account as assets.  
Pick a previously uploaded workflow Pick a previously uploaded workflow
  You can also upload a new workflow (sample workflows are provided with the tool).
Upload a new workflow Upload a new workflow
  Click on “Launch encoding”. Explorer submits an encoding task, encapsulated in a job, to Azure Media Services.
Running a premium encoder job Running a premium encoder job
  You can change the type of the Encoding Reserved Unit(s) in the Processors tab, in order to change the performances of subsequent encoding tasks.
Scale the encoding reserved unit Scale the encoding reserved unit
   

Sample code for submitting Tasks

In this section, I will discuss how you would use our .NET SDK to submit encoding Tasks. The first thing you should note is that the premium encoder is accessible via the "Media Encoder Premium Workflow" media processor. The next thing to note about the premium encoder is that the so-called encoding preset is encapsulated in an XML-formatted file, called a Workflow file. The next section describes a set of default workflow files that you have access to. These large files need to be uploaded to your Media Services account as an Asset, and this Asset should be passed in to the encoding Task. The example should make this clear, and the steps are:
  1.  Create an asset and upload a workflow file. Workflow files have the “.workflow” extension.  The default workflow files are located here: Media Encoder Premium Workflow presets
  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
  5. Add two input assets to the task:  1st - the workflow asset, and 2nd - the video asset. The order is important
  6. Submit the encoding job
Following is the relevant code snippet (see here for the full example):
            // Declare a new job.
            IJob job = _context.Jobs.Create("Premium Encoder 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
            ITask task = job.Tasks.AddNew("Premium Workflow encoding task",
                processor,
                "",
                TaskOptions.None);

            // Specify the input asset to be encoded.
            task.InputAssets.Add(workflowAsset); // first add the Workflow
            task.InputAssets.Add(videoAsset); // Then add the video 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);

            // Use the following event handler to check job progress.  
            job.StateChanged += new
                    EventHandler<JobStateChangedEventArgs>(StateChanged);

            // Launch the job.
            job.Submit();

Description of the default workflows

A set of default workflow files are located here: Media Encoder Premium Workflow presets. In this section, I will describe what these workflows accomplish.
Note: Since the default workflows include fairly complex decision logic elements, it can be sensitive to how the input media file provides metadata about resolution, frame rate, progressive vs. interlace coding, etc. These workflows may not always work with source files produced by open-source encoders like ffmpeg.

 H264 Progressive Download MP4

The intent here is to produce an audio-video interleaved MP4 that can be delivered via progressive download to playback devices. This workflow is intended to:
  1. Support all allowed input container formats
  2. Perform the following Input video processing: detect and apply de-interlacing automatically
  3. Encode video with H.264 codec, 1-pass CBR, fixed 2 second GOPs, at source resolution. Bitrate is chosen based on input resolution (higher resolution implies higher bitrate)
  4. Encode audio with AAC-LC codec, 1-pass CBR, stereo. Bitrate is chosen based on input video resolution (higher resolution implies higher audio bitrate)
  5. Process CEA 608/708 captions, embed into the H.264 elementary stream and also output a side-car SMPTE TTML file

H.264 Progressive Download MP4 SD

This workflow is intended to be the same as the “H264 Progressive Download MP4.workflow”, except that the output is kept to standard definition irrespective of input resolution. This workflow can be used to generate a standard definition proxy video. If source is SD (image width is less than 640), then the frame size of the output is left unchanged. Otherwise, if source is HD (image width is 640 or greater), output frame size is set to 640x360 (16:9 sources) or 640x480 (4:3 sources).