Azure视频流:使用REST API自定义编码格式?

时间:2015-08-12 10:04:43

标签: azure azure-media-services

我使用以下REST调用对上传的视频进行编码,

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>"
      }
   ]
}

但是H264自适应比特率的内置编码格式是 - H264自适应比特率MP4设置720p,H264自适应比特率MP4设置1080p,H264自适应比特率MP4 SD 16 * 9,H264自适应比特率MP4设置SD 4 * 3,这4个格式将上传的视频编码为各种输出格式,这导致更大的编码数据并花费更多时间来完成单个编码任务。因此,我尝试将上传的视频文件编码为较低分辨率格式,以降低成本和时间。有没有办法实现它?

1 个答案:

答案 0 :(得分:3)

好的,所以这有点hackish,但希望它会让你知道你需要为你的工作提供什么样的配置。

我启动Azure Media Services Explorer并在运行fiddler并使用提供的编码预设xml文件之一时创建了一个编码作业。这是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>

“配置”部分包含您可以找到的预设中的XML here on GitHub。希望这会引导您在POST中提供您需要的确切配置来创建您的工作。