Dışarıya aktar (0) Yazdır
Tümünü Genişlet
EN
Bu içerik dilinizde bulunmamaktadır ancak İngilizce sürümüne buradan bakabilirsiniz.
Bu konu henüz değerlendirilmedi - Bu konuyu değerlendir

Creating an Encoding Job with the Media Services REST API

Updated: March 12, 2014

After ingesting Assets into Windows Azure Media Services, media can be encoded, transmuxed, watermarked, and so on, before it is delivered to clients. These activities are scheduled and run against multiple background role instances to ensure high performance and availability. These activities are called Jobs and each Job is comprised of atomic Tasks that do the actual work on the Asset file. If you plan on doing the same set of tasks across a wide range of Assets, Media Services supports JobTemplates and TaskTemplates to help you accomplish this goal.

ImportantImportant
After successfully connecting to https://media.windows.net, you will receive a 301 redirect specifying another Media Services URI. You must make subsequent calls to the new URI.

Create a Job

Each Job can have one or more Tasks depending on the type of processing that you want to accomplish. Through the REST API, you can create Jobs and their related Tasks in one of two ways: Tasks can be defined inline through the Tasks navigation property on Job entities, or through OData batch processing. The Media Services SDK uses batch processing; however, for the readability of the code examples in this topic, tasks are defined inline. For information on batch processing, see Open Data Protocol (OData) Batch Processing.

The following example shows you how to create and post a Job with one Task set to encode a video at a specific resolution and quality. Valid task configuration presets are specified in Media Services Encoder System Presets.

POST https://media.windows.net/API/Jobs HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.2
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336802231&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=gR%2fNaIZgolFLxBOmfSECrp16Mp0Mti3KoePVjBUCzls%3d
Host: media.windows.net
Content-Length: 476

{"Name" : "NewTestJob", "InputMediaAssets" : [{"__metadata" : {"uri" : "https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaab7f15b-3136-4ddf-9962-e9ecb28fb9d2')"}}],  "Tasks" : [{"Configuration" : "H264 Broadband 720p", "MediaProcessorId" : "nb:mpid:UUID:70bdc2c3-ebf4-42a9-8542-5afc1e55d217",  "TaskBody" : "<?xml version=\"1.0\" encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"}]}

If successful, the following response is returned:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 1017
Content-Type: application/json;odata=verbose;charset=utf-8
Location: https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3A40dc7bef-6bd9-2247-9f3d-d80bc257d715')
Server: Microsoft-IIS/7.5
x-ms-request-id: d2052a71-95b1-4a52-9420-ccca1202a5fb
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 11 May 2012 21:32:40 GMT

{"d":{"__metadata":{"id":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3A40dc7bef-6bd9-2247-9f3d-d80bc257d715')","uri":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3A40dc7bef-6bd9-2247-9f3d-d80bc257d715')","type":"Microsoft.Cloud.Media.Vod.Rest.Data.Models.Job"},"Tasks":{"__deferred":{"uri":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3A40dc7bef-6bd9-2247-9f3d-d80bc257d715')/Tasks"}},"OutputMediaAssets":{"__deferred":{"uri":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3A40dc7bef-6bd9-2247-9f3d-d80bc257d715')/OutputMediaAssets"}},"InputMediaAssets":{"__deferred":{"uri":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3A40dc7bef-6bd9-2247-9f3d-d80bc257d715')/InputMediaAssets"}},"Id":"nb:jid:UUID:40dc7bef-6bd9-2247-9f3d-d80bc257d715","Name":"NewTestJob","Created":"\/Date(1336771959431)\/","LastModified":"\/Date(1336771959431)\/","EndTime":null,"Priority":0,"RunningDuration":0,"StartTime":null,"State":0,"TemplateId":null}}

There are a few of important things to note in any Job request:

  • TaskBody properties MUST use literal XML to define the number of input, or output assets that will be used by the Task. The Task topic contains the XML Schema Definition for the XML.

  • In the TaskBody definition, each inner value for <inputAsset> and <outputAsset> must be set as JobInputAsset(value) or JobOutputAsset(value).

  • A task can have multiple output assets. One JobOutputAsset(x) can only be used once as an output of a task in a job.

  • You can specify JobInputAsset or JobOutputAsset as an input asset of a task.

  • Tasks must not form a cycle.

  • The value parameter that you pass to JobInputAsset or JobOutputAsset represents the index value for an Asset. The actual Assets are defined in the InputMediaAssets and OutputMediaAssets navigation properties on the Job entity definition.

  • noteNote
    Because Media Services is built on OData v3, the individual assets in InputMediaAssets and OutputMediaAssets navigation property collections are referenced through a "__metadata : uri" name-value pair.

  • InputMediaAssets maps to one or more Assets you have created in Media Services. OutputMediaAssets are created by the system. They do not reference an existing asset.

  • OutputMediaAssets can be named using the assetName attribute. If this attribute is not present, then the name of the OutputMediaAsset will be whatever the inner text value of the <outputAsset> element is with a suffix of either the Job Name value, or the Job Id value (in the case where the Name property isn't defined). For example, if you set a value for assetName to "Sample", then the OutputMediaAsset Name property would be set to "Sample". However, if you did not set a value for assetName, but did set the job name to "NewJob", then the OutputMediaAsset Name would be "JobOutputAsset(value)_NewJob".

    The following example shows how to set the assetName attribute:

    "<?xml version=\"1.0\" encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset assetName=\"CustomOutputAssetName\">JobOutputAsset(0)</outputAsset></taskBody>"
    
  • To enable task chaining:

    • A job must have at least 2 tasks

    • There must be at least one task whose input is output of another task in the job.

For more information on Job and Task entities, see Job and Task, respectively.

Create a JobTemplate

As described in the introduction, when processing multiple Assets using a common set of Tasks, JobTemplates are useful to specify the default Task presets, order of Tasks, and so on.

The following example shows how to create a JobTemplate with a TaskTemplate defined inline. The TaskTemplate uses the Azure Media Encoder as the MediaProcessor to encode the Asset file; however, other MediaProcessors could be used as well.

POST https://media.windows.net/API/JobTemplates HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.2
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336731433&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=w%2bpnT6CW6jSzyVgJLP2cN0QyLL0peOt8PJC6XnPhvZ4%3d
Host: media.windows.net
Content-Length: 574
Expect: 100-continue

{"Name" : "NewJobTemplate25", "JobTemplateBody" : "<?xml version=\"1.0\" encoding=\"utf-8\"?><jobTemplate><taskBody taskTemplateId=\"nb:ttid:UUID:071370A3-E63E-4E81-A099-AD66BCAC3789\"><inputAsset>JobInputAsset(0)</inputAsset><outputAsset>JobOutputAsset(0)</outputAsset></taskBody></jobTemplate>", "TaskTemplates" : [{"Id" : "nb:ttid:UUID:071370A3-E63E-4E81-A099-AD66BCAC3789", "Configuration" : "H264 Smooth Streaming 720p", "MediaProcessorId" : "nb:mpid:UUID:70bdc2c3-ebf4-42a9-8542-5afc1e55d217", "Name" : "SampleTaskTemplate2", "NumberofInputAssets" : 1, "NumberofOutputAssets" : 1}] }
ImportantImportant
Unlike other Media Services entities, you must define a new GUID identifier for each TaskTemplate and place it in the taskTemplateId and Id property in your request body. The content identification scheme must follow the scheme described in Identify Azure Media Services Entities. Also, JobTemplates cannot be updated. Instead, you must create a new one with your updated changes.

If successful, the following response is returned:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 959
Content-Type: application/json;odata=verbose;charset=utf-8
Location: https://media.windows.net/api/JobTemplates('nb%3Ajtid%3AUUID%3A42da394a-bed5-1749-a541-b0d5447f60d0')
Server: Microsoft-IIS/7.5
x-ms-request-id: b57dcc60-60d8-491c-a91c-8a65fa8aa5cb
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 11 May 2012 00:17:38 GMT

{"d":{"__metadata":{"id":"https://media.windows.net/api/JobTemplates('nb%3Ajtid%3AUUID%3A42da394a-bed5-1749-a541-b0d5447f60d0')","uri":"https://media.windows.net/api/JobTemplates('nb%3Ajtid%3AUUID%3A42da394a-bed5-1749-a541-b0d5447f60d0')","type":"Microsoft.Cloud.Media.Vod.Rest.Data.Models.JobTemplate"},"TaskTemplates":{"__deferred":{"uri":"https://media.windows.net/api/JobTemplates('nb%3Ajtid%3AUUID%3A42da394a-bed5-1749-a541-b0d5447f60d0')/TaskTemplates"}},"Id":"nb:jtid:UUID:42da394a-bed5-1749-a541-b0d5447f60d0","Created":"\/Date(1336695459669)\/","JobTemplateBody":"<?xml version=\"1.0\" encoding=\"utf-8\"?><jobTemplate><taskBody taskTemplateId=\"nb:ttid:UUID:071370A3-E63E-4E81-A099-AD66BCAC3789\"><inputAsset>JobInputAsset(0)</inputAsset><outputAsset>JobOutputAsset(0)</outputAsset></taskBody></jobTemplate>","LastModified":"\/Date(1336695459669)\/","Name":"NewJobTemplate25","NumberofInputAssets":0,"TemplateType":1}}

Create a Job using a JobTemplate

The following example shows how to create a Job referencing a JobTemplate Id:

POST https://media.windows.net/API/Jobs HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.2
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336908022&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=RYXOraO6Z%2f7l9whWZQN%2bypeijgHwIk8XyikA01Kx1%2bk%3d
Host: media.windows.net
Content-Length: 249

{"Name" : "NewTestJob", "InputMediaAssets" : [{"__metadata" : {"uri" : "https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3A3f1fe4a2-68f5-4190-9557-cd45beccef92')"}}], "TemplateId" : "nb:jtid:UUID:15e6e5e6-ac85-084e-9dc2-db3645fbf0aa"}

If successful, the following response is returned:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 1064
Content-Type: application/json;odata=verbose;charset=utf-8
Location: https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3Ab21b1baf-8cee-734e-9f1a-b0f12b06e2d5')
Server: Microsoft-IIS/7.5
x-ms-request-id: 82feb593-ee74-45db-85c5-24c0a7600f2d
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sun, 13 May 2012 01:22:53 GMT

{"d":{"__metadata":{"id":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3Ab21b1baf-8cee-734e-9f1a-b0f12b06e2d5')","uri":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3Ab21b1baf-8cee-734e-9f1a-b0f12b06e2d5')","type":"Microsoft.Cloud.Media.Vod.Rest.Data.Models.Job"},"Tasks":{"__deferred":{"uri":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3Ab21b1baf-8cee-734e-9f1a-b0f12b06e2d5')/Tasks"}},"OutputMediaAssets":{"__deferred":{"uri":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3Ab21b1baf-8cee-734e-9f1a-b0f12b06e2d5')/OutputMediaAssets"}},"InputMediaAssets":{"__deferred":{"uri":"https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3Ab21b1baf-8cee-734e-9f1a-b0f12b06e2d5')/InputMediaAssets"}},"Id":"nb:jid:UUID:b21b1baf-8cee-734e-9f1a-b0f12b06e2d5","Name":"NewTestJob","Created":"\/Date(1336872171998)\/","LastModified":"\/Date(1336872171998)\/","EndTime":null,"Priority":0,"RunningDuration":0,"StartTime":null,"State":0,"TemplateId":"nb:jtid:UUID:15e6e5e6-ac85-084e-9dc2-db3645fbf0aa"}}
noteNote
This response is the same as the create Job example shown previously, except the TemplateId property is set.

Monitor Processing Progress

You can retrieve the Job status by using the State property, as shown in the following example. For more information on retrieving property values, see Managing Assets with the Media Services REST API. For more information on the State property, see Job Entity Properties.

GET https://media.windows.net/api/Jobs('nb%3Ajid%3AUUID%3A0f7d4b0e-ea6c-9748-ad34-09575bdfbd21')/State HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.2
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336908022&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=RYXOraO6Z%2f7l9whWZQN%2bypeijgHwIk8XyikA01Kx1%2bk%3d
Host: media.windows.net
Content-Length: 0

If successful, the following response is returned:

HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 17
Content-Type: application/json;odata=verbose;charset=utf-8
Server: Microsoft-IIS/7.5
x-ms-request-id: 01324d81-18e2-4493-a3e5-c6186209f0c8
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sun, 13 May 2012 05:16:53 GMT

{"d":{"State":2}}

Cancel a Job

Media Services allows you to cancel running jobs through the CancelJob function. This call will return a 400 error code if you try to cancel a Job when its state is canceled, canceling, error, or finished.

The following example shows how to call CancelJob.

GET https://media.windows.net/API/CancelJob?jobid='nb%3ajid%3aUUID%3a9e9533ba-2b9b-fa4c-a33d-73eebd49039b' HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.2
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336908753&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=kolAgnFfbQIeRv4lWxKSFa4USyjWXRm15Kd%2bNd5g8eA%3d
Host: media.windows.net

If successful, a 204 response code is returned with no message body.

noteNote
You must URL-encode the job id (normally nb:jid:UUID: somevalue)when passing it in as a parameter to CancelJob.

See Also


Build Date:

2014-04-10

Topluluk İçeriği

Ekle
Show:
© 2014 Microsoft. Tüm hakları saklıdır.