All Products
Search
Document Center

ApsaraVideo Media Processing:AddMedia

Last Updated:Sep 27, 2024

Adds a media file.

Operation description

  • You can call this operation to process videos that are uploaded to Object Storage Service (OSS) but not processed. This way, you do not need to upload the videos to OSS again. If you have configured media workflows, OSS automatically notifies ApsaraVideo Media Processing (MPS) when a media file is uploaded to OSS. MPS automatically finds the corresponding workflow in the Active state based on the specified OSS bucket and object. Therefore, in most cases, you do not need to manually call the AddMedia operation to process the media file.
  • Media information is automatically obtained only when the specified media workflow is in the Active state. If no media workflow is specified or the specified media workflow is not in the Active state, media information is not obtained.

QPS limit

You can call this operation up to 100 times per second per account. Requests that exceed this limit are dropped and you will experience service interruptions. We recommend that you take note of this limit when you call this operation. For more information, see QPS limit.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
mts:AddMediacreate
  • All Resources
    *
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
FileURLstringYes

The URL of the input file. You can obtain the URL in the MPS or OSS console. For more information, see the Triggering and matching rule for a workflow section of this topic.

  • Only OSS HTTP URLs are supported. Alibaba Cloud CDN URLs and HTTPS URLs are not supported.
  • The value can be up to 3,200 bytes in size.
  • The URL complies with RFC 2396 and is encoded in UTF-8. For more information, see URL encoding.
http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/test.mp4
TitlestringNo

The title of the media file.

  • The title can be up to 128 bytes in length.
  • The value must be encoded in UTF-8.
mytest
DescriptionstringNo

The description of the media file.

  • The description can be up to 1,024 bytes in length.
  • The value must be encoded in UTF-8.
A test video
CoverURLstringNo

The URL of the thumbnail. To obtain the URL, you can log on to the MPS console and choose Workflows > Media Buckets. Alternatively, you can log on to the OSS console and click My OSS Paths.

  • The value can be up to 3,200 bytes in length.
  • The URL complies with RFC 2396 and is encoded in UTF-8, with reserved characters being percent-encoded. For more information, see URL encoding.
http://bucket.oss-cn-hangzhou.aliyuncs.com/example/1.png
TagsstringNo

The tags that you want to add to the media file.

Note In MPS, each tag that is specified for a media file is independent. You can search for all the media files that have the same tags in the Media Library.
  • You can specify up to 16 tags for a media file. Separate multiple tags with commas (,).
  • Each tag can be up to 32 bytes in size
  • The value must be encoded in UTF-8.
tag1,tag2
MediaWorkflowIdstringNo

The ID of the media workflow that you want to run for the media file. To query the ID of a media workflow, you can log on to the MPS console or call the AddMediaWorkflow operation.

07da6c65da7f458997336e0de192****
MediaWorkflowUserDatastringNo

The custom data of the media workflow.

  • The value can be up to 1,024 bytes in length.
  • The value must be encoded in UTF-8.
test
InputUnbindbooleanNo

Specifies whether to check if the media workflow supports the specified input path. We recommend that you set this parameter to true to prevent errors that may result from invalid paths. Valid values:

  • true: checks whether the workflow supports the specified input path.
  • false: does not check whether the workflow supports the specified input path.
false
CateIdlongNo

The ID of the category to which the media file belongs. The value cannot be negative.

123
OverrideParamsstringNo

The subtitle settings that are used to overwrite the original settings.

  • Example 1: Use {"WebVTTSubtitleOverrides",[{"RefActivityName":"subtitleNode","WebVTTSubtitleURL":"http://test.oss-cn-hangzhou.aliyuncs.com/example1.vtt"}]} to overwrite the original subtitle settings during HTTP Live Streaming (HLS) packaging.
  • Example 2: Use {"subtitleTransNodeName":{"InputConfig":{"Format":"stl","InputFile":{"URL":"http://subtitleBucket.oss-cn-hangzhou.aliyuncs.com/package/example/CENG.stl"}}}} to overwrite the original subtitle settings during Dynamic Adaptive Streaming over HTTP (DASH) packaging.
{“subtitleTransNodeName”:{“InputConfig”:{“Format”:”stl”,”InputFile”:{“URL”:”http://exampleBucket.oss-cn-hangzhou.aliyuncs.com/package/example/CENG.stl"}}}}

Triggering and matching rule for a workflow

MPS checks whether the URL of the input file contains the URL to which the workflow is bound. If yes, the workflow matches the input file and runs. Otherwise, the workflow does not match the input file and does not run. Example: The URL of the input file is http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/test1.flv.

1. When a media file is added to http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/, the workflow is triggered.
2. When a media file is added to http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/, the workflow is triggered.
3.When a media file is added to http://bucket.oss-cn-hangzhou.aliyuncs.com/A/, the workflow is triggered.
4. When a media file is added to http://bucket.oss-cn-hangzhou.aliyuncs.com/, the workflow is triggered.
5. When test.flv is added to http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/, the workflow is triggered.
6. When a media file is added to http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/CC/, the workflow is not triggered.
7. When a media file is added to http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B2/, the workflow is not triggered.
8. When a media file is added to http://bucket.oss-cn-hangzhou.aliyuncs.com/A2/B/C/, the workflow is not triggered.

NoteWhen you create a media workflow, do not configure the input URL of a workflow to be the same as the prefix of the input URL of another workflow. Otherwise, two workflow execution instances will be triggered for adding one media file. For example, if you specify the test folder for the first workflow triggering rule and the test1 folder for the second workflow triggering rule, the two workflows are triggered when a media file is added to the test1 folder.

File name extension matching

Only multimedia files can trigger workflows. MPS determines whether to trigger a workflow by checking the file name extensions. A workflow is matched for a file that does not have a file name extension or a file with the name extension described in the following table. A file that does not have a file name extension has no separator dot in the file name.

NoteFor SWF files, the snapshot and transcoding features may not deliver optimal performance.

TypeFile name extension
Video3gp, asf, avi, dat, dv, flv, f4v, gif, m2t, m3u8, m4v, mj2, mjpeg, mkv, mov, mp4, mpe, mpg, mpeg, mts, ogg, qt, rm, rmvb, swf, ts, vob, wmv, webm
Audioaac, ac3, acm, amr, ape, caf, flac, m4a, mp3, ra, wav, wma, aiff

Media workflow message

Media workflows use Alibaba Cloud Message Service (MNS) to send messages to MPS service users. A media workflow sends a message when the Start or Report activity is complete. To receive the message, you must set the queue or notification name on the Start activity. The message generated by the media workflow is stored in the queue or notification. You can use MNS SDK to obtain the message. The following table describes the message specifications.

ParameterTypeDescription
RunIdStringThe ID of the workflow execution instance.
NameStringThe name of the activity.
TypeStringThe type of the activity. Valid values: Report and Start.
StateStringThe status of the activity. Valid values: Fail and Success.
CodeStringThe error code returned if the activity fails. The specific error code appears if the activity status is Fail.
MessageStringThe error message returned if the activity fails. The detailed error message is returned if the activity status is Fail.
MediaWorkflowExecutionMediaWorkflowExecutionThe detailed information about the workflow execution instance.

Response parameters

ParameterTypeDescriptionExample
object

The response parameters.

RequestIdstring

The ID of the request.

05F8B913-E9F3-4A6F-9922-48CADA0FFAAD
Mediaobject

The detailed information about the media file.

CreationTimestring

The time when the media file was created.

2016-09-20T03:02:40Z
CateIdlong

The ID of the category to which the media file belongs.

1
Heightstring

The height of the media file.

1280
CensorStatestring

The review status of the media file. Valid values:

  • Initiated: The media file is uploaded but not reviewed.
  • Pass: The media file is uploaded and passes the review.
Initiated
Tagsarray

The tags of the media file.

Tagstring

The tags that are added to the media file.

tag,tag2
Bitratestring

The bitrate.

1148.77
MediaIdstring

The ID of the media file.

3e6149d5a8c944c09b1a8d2dc3e4****
Fileobject

The information about the input file.

Statestring

The status of the file. The default value is Normal.

Normal
URLstring

The URL of the media file.

http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/test.mp4
PublishStatestring

The publishing status of the media file. Valid values:

  • Initiated: The media file is in the initial state.
  • UnPublish: The media file has not been published, and the playback permission on the OSS object is Private.
  • Published: The media file has been published, and the playback permission on the OSS object is Default.
Published
Descriptionstring

The description of the media file. The description can be up to 1,024 bytes in length.

A test video
Widthstring

The width of the media file.

1280
Sizestring

The size of the media file.

379860
CoverURLstring

The URL of the thumbnail.

http://bucket.oss-cn-hangzhou.aliyuncs.com/example/1.png
RunIdListarray

The IDs of the media workflow execution instances.

RunIdstring

The IDs of the executed workflow execution instances. The IDs are separated by commas (,).

{"RunId":["cbad98d35629470fa05ff393d347****"]}
Durationstring

The duration of the media file.

2.645333
Fpsstring

The frame rate of the media file.

25.0
Titlestring

The title of the media file. The title can be up to 128 bytes in length.

mytest.mp4
Formatstring

The format of the media file. Valid values: mov, mp4, m4a, 3gp, 3g2, and mj2.

mp4

Examples

Sample success responses

JSONformat

{
  "RequestId": "05F8B913-E9F3-4A6F-9922-48CADA0FFAAD",
  "Media": {
    "CreationTime": "2016-09-20T03:02:40Z",
    "CateId": 1,
    "Height": "1280",
    "CensorState": "Initiated",
    "Tags": {
      "Tag": [
        "tag,tag2"
      ]
    },
    "Bitrate": "1148.77",
    "MediaId": "3e6149d5a8c944c09b1a8d2dc3e4****",
    "File": {
      "State": "Normal",
      "URL": "http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/test.mp4"
    },
    "PublishState": "Published",
    "Description": "A test video",
    "Width": "1280",
    "Size": "379860",
    "CoverURL": "http://bucket.oss-cn-hangzhou.aliyuncs.com/example/1.png",
    "RunIdList": {
      "RunId": [
        "{\"RunId\":[\"cbad98d35629470fa05ff393d347****\"]}"
      ]
    },
    "Duration": "2.645333",
    "Fps": "25.0",
    "Title": "mytest.mp4",
    "Format": "mp4"
  }
}

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
No change history