Search code examples
azureazure-media-services

Azure video streaming: Custom encode format using REST API?


i'm using below REST call to encode the video uploaded,

POST https://wamsbayclus001rest-hs.cloudapp.net/api/Jobs HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json
Accept: application/json;odata=verbose
Accept-Charset: UTF-8
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=amstestaccount001&urn%3aSubscriptionId=z7f09258-2233-4ca2-b1ae-193798e2c9d8&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1421675491&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=9hUudHYnATpi5hN3cvTfgw%2bL4N3tL0fdsRnQnm6ZYIU%3d
x-ms-version: 2.8
Host: wamsbayclus001rest-hs.cloudapp.net
Content-Length: 482

{  
   "Name":"NewTestJob",
   "InputMediaAssets":[  
      {  
         "__metadata":{  
            "uri":"https://wamsbayclus001rest-hs.net/api/Assets('nb%3Acid%3AUUID%3A9bc8ff20-24fb-4fdb-9d7c-b04c7ee573a1')"
         }
      }
   ],
   "Tasks":[  
      {  
         "Configuration":"H264 Adaptive Bitrate MP4 Set 720p",
         "MediaProcessorId":"nb:mpid:UUID:1b1da727-93ae-4e46-a8a1-268828765609",
         "TaskBody":"<?xml version=\"1.0\" encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset>
            <outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"
      }
   ]
}

But the built in encode formats of H264 Adaptive Bitrate are - H264 Adaptive Bitrate MP4 Set 720p,H264 Adaptive Bitrate MP4 Set 1080p,H264 Adaptive Bitrate MP4 SD 16*9,H264 Adaptive Bitrate MP4 Set SD 4*3 , these 4 formats encode the uploaded video into various output format, which results in larger encode data and takes more time to complete single encoding task. So i'm trying to encode the uploaded video file to only lower resolution formats, to reduce cost and time. Is there a way to implement it ?


Solution

  • Ok, so this is a little hackish, but hopefully it will give you an idea of what sort of configuration you'll need to provide to your job.

    I fired up Azure Media Services Explorer and created an encoding job while running fiddler and using one of the encoding preset xml file provided. This is the body of the POST:

    <?xml version="1.0" encoding="utf-8"?>
        <entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
            <id />
            <title />
            <updated>2015-08-12T20:46:59Z</updated>
            <author>
                <name />
            </author>
            <content type="application/xml">
                <m:properties>
                <d:Configuration>
                    &lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;!--Created for Azure Media Encoder, July 30 2014 --&gt;&#xD;
    &lt;Presets&gt;&#xD;
      &lt;Preset Version="5.0"&gt;&#xD;
        &lt;Job /&gt;&#xD;
        &lt;MediaFile DeinterlaceMode="AutoPixelAdaptive" ResizeQuality="Super" AudioGainLevel="1" VideoResizeMode="Stretch"&gt;&#xD;
          &lt;Metadata MergeCollection="True"&gt;&#xD;
            &lt;Item Name="WM/EncodedBy" Value="Azure Media Encoder 4 - H264 Adaptive Bitrate MP4 Set 720p, 07/30/2014 " /&gt;&#xD;
          &lt;/Metadata&gt;&#xD;
          &lt;OutputFormat&gt;&#xD;
            &lt;MP4OutputFormat StreamCompatibility="Standard"&gt;&#xD;
              &lt;VideoProfile&gt;&#xD;
                &lt;MainH264VideoProfile BFrameCount="3" EntropyMode="Cabac" RDOptimizationMode="Speed" HadamardTransform="False" SubBlockMotionSearchMode="Speed" MultiReferenceMotionSearchMode="Balanced" ReferenceBFrames="False" AdaptiveBFrames="False" SceneChangeDetector="False" FastIntraDecisions="False" FastInterDecisions="False" SubPixelMode="Quarter" SliceCount="0" KeyFrameDistance="00:00:02" InLoopFilter="True" MEPartitionLevel="EightByEight" ReferenceFrames="4" SearchRange="64" AutoFit="True" Force16Pixels="False" FrameRate="0" SeparateFilesPerStream="True" SmoothStreaming="False" NumberOfEncoderThreads="0"&gt;&#xD;
                  &lt;Streams AutoSize="False" FreezeSort="False"&gt;&#xD;
                    &lt;StreamInfo Size="1280, 720"&gt;&#xD;
                      &lt;Bitrate&gt;&#xD;
                        &lt;ConstantBitrate Bitrate="3400" IsTwoPass="False" BufferWindow="00:00:05" /&gt;&#xD;
                      &lt;/Bitrate&gt;&#xD;
                    &lt;/StreamInfo&gt;&#xD;
                    &lt;StreamInfo Size="960, 540"&gt;&#xD;
                      &lt;Bitrate&gt;&#xD;
                        &lt;ConstantBitrate Bitrate="2250" IsTwoPass="False" BufferWindow="00:00:05" /&gt;&#xD;
                      &lt;/Bitrate&gt;&#xD;
                    &lt;/StreamInfo&gt;&#xD;
                    &lt;StreamInfo Size="960, 540"&gt;&#xD;
                      &lt;Bitrate&gt;&#xD;
                        &lt;ConstantBitrate Bitrate="1500" IsTwoPass="False" BufferWindow="00:00:05" /&gt;&#xD;
                      &lt;/Bitrate&gt;&#xD;
                    &lt;/StreamInfo&gt;&#xD;
                    &lt;StreamInfo Size="640, 360"&gt;&#xD;
                      &lt;Bitrate&gt;&#xD;
                        &lt;ConstantBitrate Bitrate="1000" IsTwoPass="False" BufferWindow="00:00:05" /&gt;&#xD;
                      &lt;/Bitrate&gt;&#xD;
                    &lt;/StreamInfo&gt;&#xD;
                    &lt;StreamInfo Size="640, 360"&gt;&#xD;
                      &lt;Bitrate&gt;&#xD;
                        &lt;ConstantBitrate Bitrate="650" IsTwoPass="False" BufferWindow="00:00:05" /&gt;&#xD;
                      &lt;/Bitrate&gt;&#xD;
                    &lt;/StreamInfo&gt;&#xD;
                    &lt;StreamInfo Size="320, 180"&gt;&#xD;
                      &lt;Bitrate&gt;&#xD;
                        &lt;ConstantBitrate Bitrate="400" IsTwoPass="False" BufferWindow="00:00:05" /&gt;&#xD;
                      &lt;/Bitrate&gt;&#xD;
                    &lt;/StreamInfo&gt;&#xD;
                  &lt;/Streams&gt;&#xD;
                &lt;/MainH264VideoProfile&gt;&#xD;
              &lt;/VideoProfile&gt;&#xD;
              &lt;AudioProfile&gt;&#xD;
                &lt;AacAudioProfile Codec="AAC" Channels="2" BitsPerSample="16" SamplesPerSecond="44100"&gt;&#xD;
                  &lt;Bitrate&gt;&#xD;
                    &lt;ConstantBitrate Bitrate="96" IsTwoPass="False" BufferWindow="00:00:00" /&gt;&#xD;
                  &lt;/Bitrate&gt;&#xD;
                &lt;/AacAudioProfile&gt;&#xD;
              &lt;/AudioProfile&gt;&#xD;
            &lt;/MP4OutputFormat&gt;&#xD;
          &lt;/OutputFormat&gt;&#xD;
        &lt;/MediaFile&gt;&#xD;
      &lt;/Preset&gt;&#xD;
      &lt;Preset Version="5.0"&gt;&#xD;
        &lt;Job /&gt;&#xD;
        &lt;MediaFile AudioGainLevel="1"&gt;&#xD;
          &lt;Metadata MergeCollection="True"&gt;&#xD;
            &lt;Item Name="WM/EncodedBy" Value="Azure Media Encoder 3 - H264 Adaptive Bitrate MP4 Set 720p, 07/30/2014 " /&gt;&#xD;
          &lt;/Metadata&gt;&#xD;
          &lt;OutputFormat&gt;&#xD;
            &lt;MP4OutputFormat StreamCompatibility="Standard"&gt;&#xD;
              &lt;AudioProfile&gt;&#xD;
                &lt;AacAudioProfile Codec="AAC" Channels="2" BitsPerSample="16" SamplesPerSecond="44100"&gt;&#xD;
                  &lt;Bitrate&gt;&#xD;
                    &lt;ConstantBitrate Bitrate="96" IsTwoPass="False" BufferWindow="00:00:00" /&gt;&#xD;
                  &lt;/Bitrate&gt;&#xD;
                &lt;/AacAudioProfile&gt;&#xD;
              &lt;/AudioProfile&gt;&#xD;
            &lt;/MP4OutputFormat&gt;&#xD;
          &lt;/OutputFormat&gt;&#xD;
        &lt;/MediaFile&gt;&#xD;
      &lt;/Preset&gt;&#xD;
      &lt;Preset Version="5.0"&gt;&#xD;
        &lt;Job /&gt;&#xD;
        &lt;MediaFile AudioGainLevel="1"&gt;&#xD;
          &lt;Metadata MergeCollection="True"&gt;&#xD;
            &lt;Item Name="WM/EncodedBy" Value="Azure Media Encoder 3 - H264 Adaptive Bitrate MP4 Set 720p, 07/30/2014 " /&gt;&#xD;
          &lt;/Metadata&gt;&#xD;
          &lt;OutputFormat&gt;&#xD;
            &lt;MP4OutputFormat StreamCompatibility="Standard"&gt;&#xD;
              &lt;AudioProfile&gt;&#xD;
                &lt;AacAudioProfile Codec="AAC" Channels="2" BitsPerSample="16" SamplesPerSecond="44100"&gt;&#xD;
                  &lt;Bitrate&gt;&#xD;
                    &lt;ConstantBitrate Bitrate="56" IsTwoPass="False" BufferWindow="00:00:00" /&gt;&#xD;
                  &lt;/Bitrate&gt;&#xD;
                &lt;/AacAudioProfile&gt;&#xD;
              &lt;/AudioProfile&gt;&#xD;
            &lt;/MP4OutputFormat&gt;&#xD;
          &lt;/OutputFormat&gt;&#xD;
        &lt;/MediaFile&gt;&#xD;
      &lt;/Preset&gt;&#xD;
    &lt;/Presets&gt;
                </d:Configuration>
                <d:EncryptionKeyId m:null="true" />
                <d:EncryptionScheme m:null="true" />
                <d:EncryptionVersion m:null="true" />
                <d:EndTime m:null="true" />
                <d:ErrorDetails />
                <d:HistoricalEvents />
                <d:Id></d:Id>
                <d:InitializationVector m:null="true" />
                <d:MediaProcessorId>nb:mpid:UUID:1b1da727-93ae-4e46-a8a1-268828765609</d:MediaProcessorId>
                <d:Name>AME (adv) Encoding of Jenkins_Under_Two_Min.mp4 with Azure Media Encoder v4.7</d:Name>
                <d:Options m:type="Edm.Int32">0</d:Options>
                <d:PerfMessage m:null="true" />
                <d:Priority m:type="Edm.Int32">0</d:Priority>
                <d:Progress m:type="Edm.Double">0</d:Progress>
                <d:RunningDuration m:type="Edm.Double">0</d:RunningDuration>
                <d:StartTime m:null="true" />
                <d:State m:type="Edm.Int32">0</d:State>
                <d:TaskBody>&lt;?xml version="1.0" encoding="utf-16"?&gt;&#xD;
    &lt;taskBody&gt;&#xD;
      &lt;inputAsset&gt;JobInputAsset(0)&lt;/inputAsset&gt;&#xD;
      &lt;outputAsset assetCreationOptions="0" assetName="Jenkins_Under_Two_Min.mp4-AME (adv) encoded" storageAccountName="ianphil"&gt;JobOutputAsset(0)&lt;/outputAsset&gt;&#xD;
    &lt;/taskBody&gt;</d:TaskBody>
                </m:properties>
            </content>
        </entry>
    

    The "configuration" section contains the XML from the preset you can find here on GitHub. Hope this will lead you to the exact configuration you need to provide in the POST to create your job.