All Products
Search
Document Center

Content Moderation:Video File Moderation 2.0 API

Last Updated:May 11, 2024

You can call the Video File Moderation 2.0 API to identify risky or illegal content in video files. This topic describes how to call API operations of Video File Moderation 2.0 to moderate video files.

Usage instructions

  1. Create an Alibaba Cloud account: Click Register account and follow the instructions to create an Alibaba Cloud account.

  2. Activate the pay-as-you-go billing method for Content Moderation: Make sure that the Content Moderation 2.0 service is activated. You are not charged for activating this service. After you call API operations, the billing system automatically charges you based on your usage. For more information, see Billing methods.

  3. Create an AccessKey pair: Make sure that you have created an AccessKey pair as a Resource Access Management (RAM) user. For more information, see Create an AccessKey pair. If you want to use the AccessKey pair of the RAM user, use your Alibaba Cloud account to grant the AliyunYundunGreenWebFullAccess permission to the RAM user. For more information, see Grant permissions to a RAM user.

  4. Use SDKs: We recommend that you use SDKs to call API operations. For more information, see Guide of using Video Moderation 2.0.

Submit a moderation task

Usage notes

  • Operation: VideoModeration (only for asynchronous moderation)

  • Supported regions and endpoints

    Region

    Public endpoint

    Internal endpoint

    Supported service

    Singapore

    green-cip.ap-southeast-1.aliyuncs.com

    green-cip-vpc.ap-southeast-1.aliyuncs.com

    videoDetection_global

  • Billing methods

    You are charged for calling this operation. The billing system charges you based on the image moderation policy and voice moderation policy that you set for video files. If multiple moderation services are called to moderate the images in video files, fees are accumulated based on the number of captured frames multiplied by the unit price of each moderation service. If video files are moderated for voice content violations at the same time, you are also charged for the video duration multiplied by the unit price of voice moderation. For more information about the billing method, see Billing methods.

  • Moderation objects: Video files

  • Returned results: If you send asynchronous moderation requests, the moderation results are not returned in real time. To obtain moderation results, you can poll the moderation results periodically or enable callback notification. The moderation results are retained for up to 24 hours.

    • Enable callback notification to obtain moderation results: When you submit an asynchronous moderation task, you can specify a callback URL for receiving moderation results in the callback parameter of the moderation request.

    • Poll moderation results: You do not need to set the callback parameter when you submit asynchronous moderation tasks. After you submit the tasks, you can call the result query operation to query moderation results.

  • Limits on video files

    • The URLs of video files must be HTTP or HTTPS URLs.

    • The video files must be in AVI, FLV, MP4, MPG, ASF, WMV, MOV, WMA, RMVB, RM, FLASH, or TS format.

    • A video file can be up to 500 MB in size. If the video file to be moderated exceeds 500 MB, you can segment the video file. Alternatively, you can contact the technical support personnel to help you adjust the size limit.

    • The time for video moderation varies with the duration for downloading the video file. Make sure that you use a stable and reliable storage service to store the video files to be moderated. We recommend that you use Object Storage Service (OSS) provided by Alibaba Cloud.

  • Moderation rule configurations

    • Before you call the Video Moderation API for the first time, you must configure video moderation rules in the Content Moderation console.

    • If you do not configure video moderation rules, the Video Moderation 2.0 API uses the following default configurations:

      Video moderation (videoDetection_global)

      • Frequency of capturing frames: 1 second/frame

      • Image moderation service: common baseline moderation (baselineCheck_global)

      • Voice moderation: enabled

      • Voice moderation service: multi-language voice moderation (audio_multilingual_global)

      • Returned results: Only the risky content is returned.

QPS limits

You can call this operation up to 100 times per second per account. Only 50 moderation tasks can be processed at a time. If you need to increase the number of concurrent moderation tasks, consult your business manager. If the number of calls per second exceeds the limit, throttling is triggered. As a result, your business may be affected. We recommend that you take note of the limit when you call this operation.

Debugging

Before you deploy SDKs, you can use Alibaba Cloud OpenAPI Explorer to debug the VideoModeration operation online and view the sample code for the call and SDK dependencies. This way, you can understand how to call the operation and how to set related parameters.

Important

Before you call the Content Moderation API, you must log on to the Content Moderation console by using your Alibaba Cloud account. Therefore, the fees incurred by calling the operations are billed to the account.

Request parameters

Parameter

Type

Required

Example

Description

Service

String

Yes

videoDetection_global

The type of the moderation service. Valid values:

  • videoDetection_global: video file moderation

ServiceParameters

JSONString

Yes

The parameters required by the moderation service. The value is a JSON string. For more information about the description of each string, see Table 1 ServiceParameters.

Table 1 ServiceParameters

Parameter

Type

Required

Example

Description

url

String

Yes

http://www.aliyundoc.com/a.flv

The URL of the object that you want to moderate. Make sure that the URL can be accessed over the Internet or the internal endpoint of OSS in the same region is specified.

Note

The URL cannot contain Chinese characters and cannot exceed 2,048 characters in length. Make sure that you specify only one URL in each request.

callback

String

No

http://www.aliyundoc.com

The callback URL for notifying you of asynchronous moderation results. HTTP and HTTPS URLs are supported. If you do not set this parameter, you must poll moderation results periodically.

If you set the callback parameter in the moderation request, make sure that the specified HTTP or HTTPS URL meets the following requirements: supports the POST method, uses UTF-8 to encode the transmitted data, and supports the checksum and content parameters.

To send moderation results to the specified callback URL, Content Moderation returns the checksum and content parameters in callback notifications based on the following rules and format:

  • checksum: a string in the UID + seed + content format that is generated by the Secure Hash Algorithm 256 (SHA-256) algorithm. UID indicates the ID of your Alibaba Cloud account. You can query the ID in the Alibaba Cloud Management Console. To prevent data tampering, you can use the SHA-256 algorithm to generate a string when your server receives a callback notification and verify the string against the received checksum parameter.

    Note

    UID must be the ID of your Alibaba Cloud account, but not the ID of a RAM user.

  • content: a JSON-formatted string. You can convert the string to a JSON object. For more information about the format of the content parameter, see the sample success responses of each operation that you can call to query moderation results.

Note

If your server receives a callback notification, the server sends an HTTP 200 status code to Content Moderation. If your server fails to receive a callback notification, the server sends other HTTP status codes to Content Moderation. If your server fails to receive a callback notification, Content Moderation continues to push the callback notification until your server receives it. Content Moderation can push a callback notification repeatedly up to 16 times. After 16 times, Content Moderation stops pushing the callback notification. In this case, we recommend that you check the status of the callback URL.

seed

String

No

abc****

A random string that is used to generate a signature for the callback notification request.

The string can be up to 64 characters in length and can contain letters, digits, and underscores (_). You can customize this string. It is used to verify the callback notification request when Content Moderation pushes callback notifications to your server.

Note

This parameter is required if you set the callback parameter.

cryptType

String

No

SHA256

The algorithm used to sign the callback notification content when you enable callback notification. Content Moderation signs the returned string by using the algorithm that you specify and sends the signed string to the callback URL. The returned string is in the UID + Seed + Content format. Valid values:

  • SHA256 (default): The SHA256 encryption algorithm is used.

  • SM3: The HMAC-SM3 encryption algorithm is used, and a hexadecimal string is returned. The string consists of lowercase letters and digits.

    For example, 66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0 is returned after you encrypt abc by using the HMAC-SM3 encryption algorithm.

dataId

String

No

videoId****

The ID of the moderation object.

The ID can contain letters, digits, underscores (_), hyphens (-), and periods (.). It can be up to 128 characters in length. This ID uniquely identifies your business data.

Note

If your server receives a callback notification, the server sends an HTTP 200 status code to Content Moderation. If your server fails to receive a callback notification, the server sends other HTTP status codes to Content Moderation. If your server fails to receive a callback notification, Content Moderation continues to push the callback notification until your server receives it. Content Moderation can push a callback notification repeatedly up to 16 times. After 16 times, Content Moderation stops pushing the callback notification. In this case, we recommend that you check the status of the callback URL.

Response parameters

Parameter

Type

Example

Description

Code

Integer

200

The returned HTTP status code. For more information, see Response codes.

Data

JSONObject

The moderation results.

TaskId

String

AAAAA-BBBBB

The ID of the moderation task.

Message

String

OK

The message that is returned in response to the request.

RequestId

String

ABCD1234-1234-1234-1234-123****

The request ID.

Examples

Sample requests

{
    "Service": "videoDetection_global",
    "ServiceParameters": {
        "url": "http://www.aliyundoc.com/a.flv",
        "dataId": "videoId****"
    }
}

Sample success responses

{
    "Msg": "OK",
    "Code": 200,
    "Data":
    {
        "TaskId": "AAAAA-BBBBB"
    },
    "RequestId": "ABCD1234-1234-1234-1234-123****"
}

Obtain the moderation results of a video file moderation task

Usage notes

  • Operation: VideoModerationResult, which is used to obtain the moderation results of a video file moderation task.

  • Billing: This operation is free of charge.

  • Response timeout: We recommend that you query moderation results at least 30s after you send an asynchronous moderation request. Content Moderation retains moderation results for up to 24 hours. After 24 hours, the results are deleted.

QPS limits

You can call this operation up to 100 times per second per account. If the number of calls per second exceeds the limit, throttling is triggered. As a result, your business may be affected. We recommend that you take note of the limit when you call this operation.

Debugging

Before you deploy SDKs, you can use Alibaba Cloud OpenAPI Explorer to debug the VideoModerationResult operation online and view the sample code for the call and SDK dependencies. This way, you can understand how to call the operation and how to set related parameters.

Request parameters

Parameter

Type

Required

Example

Description

Service

String

Yes

videoDetection_global

The type of the moderation service. It must be the same as the type of the moderation service for the submitted moderation task.

ServiceParameters

JSONString

Yes

The parameters required by the moderation service. The value is a JSON string. For more information about the description of each string, see Table 1 ServiceParameters.

Table 1 ServiceParameters

Parameter

Type

Required

Example

Description

taskId

string

Yes

abcd****

The ID of the moderation task that you want to query. You can enter one task ID at a time.

Note

After you submit a moderation task, you can obtain the ID of the task from the response.

Response parameters

Parameter

Type

Example

Description

RequestId

String

ABCD1234-1234-1234-1234-123****

The request ID, which is used to locate and troubleshoot issues.

Data

Object

The video moderation results. For more information, see Table 2 Data.

Code

String

200

The returned HTTP status code. For more information, see Response codes.

Message

String

OK

The message that is returned in the response.

Table 2 Data

Parameter

Type

Example

Description

DataId

String

videoId****

The ID of the moderated object.

Note

If you specify the DataId parameter in the request, the value of the DataId parameter is returned in the response.

FrameResult

JSONObject

The image moderation results. If the call is successful, the HTTP status code 200 and moderation results are returned. The moderation results contain a structure. For more information about the structure, see Table 3 FrameResult.

Note

In the scenario of moderating a video stream, the HTTP status code 280 indicates that the moderation task is in progress, and the HTTP status code 200 indicates that the moderation task is complete. If the moderation task is in progress, the returned moderation results contain all the issues that Content Moderation has detected in the task.

AudioResult

JSONObject

The voice moderation results. The moderation results contain a structure. For more information about the structure, see Table 8 audioResult.

Table 3 FrameResult

Parameter

Type

Example

Description

FrameNum

Integer

200

The number of captured frames that are returned for the video file.

FrameSummarys

JSONArray

The summary of the labels against which captured frames are matched. For more information about the structure, see Table 4 FrameSummary.

Frames

JSONArray

The information about the frames that match the labels. For more information about the structure, see Table 5 Frame.

Table 4 FrameSummary

Parameter

Type

Example

Description

Label

String

violent_armedForces

The label against which a captured frame is matched.

LabelSum

Integer

8

The number of times that the label is matched.

Table 5 Frame

Parameter

Type

Example

Description

TempUrl

String

http://www.aliyundoc.com/test.jpg

The temporary URL of a captured frame. This URL is valid for 30 minutes.

Note

If the feature of storing video evidence in OSS buckets is enabled, this parameter returns the OSS URL of the captured frame.

Offset

Float

50.5

The interval between the start of the video file and the captured frame. Unit: seconds.

Results

JSONArray

The results of frame moderation parameters such as the label parameter and the confidence parameter. For more information, see Table 6 Results.

Table 6 Results

Parameter

Type

Example

Description

Service

String

baselineCheck_global

The moderation service that is called.

Result

Array

The results of frame moderation parameters such as the label parameter and the confidence parameter. For more information, see Table 7 Result.

Table 7 Result

Parameter

Type

Example

Description

Label

String

violent_explosion

The label returned after a frame is moderated. Multiple risk labels and the corresponding scores of confidence levels may be returned for a frame. Valid values:

Confidence

Float

81.22

The score of the confidence level. Valid values: 0 to 100. The value is accurate to two decimal places.

Table 8 audioResult

Parameter

Type

Example

Description

AudioSummarys

JSONArray

Summary of voice labels. For more information about the structure, see Table 9 AudioSummarys.

SliceDetails

JSONArray

The details about the text in the moderated voice. The value is a JSON array that contains one or more elements. Each element corresponds to a text entry. For more information about the structure, see Table 10 SliceDetails.

Table 9 AudioSummarys

Parameter

Type

Example

Description

Label

String

profanity

Voice label.

LabelSum

Integer

8

The number of times that the label is matched.

Table 10 SliceDetails

Parameter

Type

Example

Description

StartTime

Integer

0

The start time of the text after voice-to-text conversion. Unit: seconds.

EndTime

Integer

4065

The end time of the text after voice-to-text conversion. Unit: seconds.

StartTimestamp

Integer

1678854649720

The start timestamp of the segment. Unit: milliseconds.

EndTimestamp

Integer

1678854649720

The end timestamp of the segment. Unit: milliseconds.

Text

String

Disgusting

The text converted from voice.

Url

String

https://aliyundoc.com/test.wav

If the moderation object is a voice stream, this parameter indicates the temporary access URL of the voice stream to which the text entry corresponds. The validity period of the URL is 30 minutes. You must prepare another URL to store the audio stream at the earliest opportunity.

Labels

String

political_content,xxxx

The details of the labels. Multiple labels are separated by commas (,). Valid values:

    RiskWords

    String

    AAA,BBB,CCC

    The risk words that are hit. Multiple words are separated by commas (,).

    RiskTips

    String

    Pornography_vulgar words, pornography_description

    Subcategory labels. Multiple labels are separated by commas (,).

    Extend

    String

    {"riskTips":"Pornography_vulgar words","riskWords":"Pornography service"}

    A reserved parameter.

    Examples

    Sample requests

    {
        "Service": "videoDetection_global",
        "ServiceParameters": {
            "taskId": "abcd****"
        }
    }

    Sample success responses

    • Moderate only images in a video file

    {
        "Code": 200,
        "RequestId": "25106421-XXXX-XXXX-XXXX-15DA5AAAC546",
        "Message": "success finished",
        "Data": {
            "DataId": "dc16c28f-xxxx-xxxx-xxxx-51efe0131080",
            "FrameResult": {
                "FrameNum": 2,
                "FrameSummarys": [
                    {
                        "Label": "violent_explosion",
                        "LabelSum": 8
                    },
                    {
                        "Label": "sexual_cleavage",
                        "LabelSum": 5
                    }
                ],
                "Frames": [
                    {
                        "Offset": 1,
                        "Results": [
                            {
                                "Result": [
                                    {
                                        "Label": "nonLabel"
                                    }
                                ],
                                "Service": "baselineCheck_global"
                            }
                        ],
                        "TempUrl": "http://abc.oss-ap-southeast-1.aliyuncs.com/test1.jpg"
                    },
                    {
                        "Offset": 2,
                        "Results": [
                            {
                                "Result": [
                                    {
                                        "Confidence": 1,
                                        "Label": "sexual_cleavage"
                                    },
                                    {
                                        "Confidence": 74.1,
                                        "Label": "violent_explosion"
                                    }
                                ],
                                "Service": "baselineCheck_global"
                            }
                        ],
                        "TempUrl": "http://abc.oss-ap-southeast-1.aliyuncs.com/test2.jpg"
                    }
                ]
            }
        }
    }

    • Moderate both images and voices in a video file

    {
        "Code": 200,
        "RequestId": "25106421-XXXX-XXXX-XXXX-15DA5AAAC546",
        "Message": "success finished",
        "Data": {
            "AudioResult": {
                "AudioSummarys": [
                    {
                        "Label": "sexual_sounds",
                        "LabelSum": 3
                    }
                ],
                "SliceDetails": [
                    {
                        "EndTime": 60,
                        "EndTimestamp": 1698912813192,
                        "Labels": "",
                        "StartTime": 30,
                        "StartTimestamp": 1698912783192,
                        "Text": "Content Moderation",
                        "Url": "http://abc.oss-ap-southeast-1.aliyuncs.com/test.wav"
                    },
                    {
                        "EndTime": 30,
                        "EndTimestamp": 1698912813192,
                        "Extend": "{\"customizedWords\":\"Service\",\"customizedLibs\":\"test\"}",
                        "Labels": "C_customized",
                        "StartTime": 0,
                        "StartTimestamp": 1698912783192,
                        "Text": "Welcome to the Alibaba Cloud Content Moderation service",
                        "Url": "http://abc.oss-ap-southeast-1.aliyuncs.com/test.wav"
                    }
                ]
            },
            "DataId": "dc16c28f-xxxx-xxxx-xxxx-51efe0131080",
            "FrameResult": {
                "FrameNum": 2,
                "FrameSummarys": [
                    {
                        "Label": "violent_explosion",
                        "LabelSum": 8
                    },
                    {
                        "Label": "sexual_cleavage",
                        "LabelSum": 8
                    }
                ],
                "Frames": [
                    {
                        "Offset": 1,
                        "Results": [
                            {
                                "Result": [
                                    {
                                        "Label": "nonLabel"
                                    }
                                ],
                                "Service": "baselineCheck_global"
                            }
                        ],
                        "TempUrl": "http://abc.oss-ap-southeast-1.aliyuncs.com/test1.jpg"
                    },
                    {
                        "Offset": 2,
                        "Results": [
                            {
                                "Result": [
                                    {
                                        "Confidence": 1,
                                        "Label": "sexual_cleavage"
                                    },
                                    {
                                        "Confidence": 74.1,
                                        "Label": "violent_explosion"
                                    }
                                ],
                                "Service": "baselineCheck_global"
                            }
                        ],
                        "TempUrl": "http://abc.oss-ap-southeast-1.aliyuncs.com/test2.jpg"
                    }
                ]
            }
        }
    }

    Response codes

    The following table describes the response codes for calling Video File Moderation 2.0 API operations. You are charged by using the pay-as-you-go billing method only for requests whose response codes are 200 and 280.

    Code

    Description

    200

    The request is normal or the moderation is complete.

    280

    The moderation is in progress.

    400

    Not all request parameters are configured.

    401

    The values specified for one or more request parameters are invalid.

    402

    Invalid value length of request parameters. Check and modify them and try again.

    403

    The QPS of requests exceeds the upper limit. Check and modify the number of requests that are sent at a time.

    404

    The specified video file failed to be downloaded. Check the URL of the video file or try again.

    405

    Downloading the specified video file timed out. The possible cause is that the video file cannot be accessed. Check and adjust the video file and try again.

    406

    The specified video file is excessively large. Check and change the video file size and try again.

    407

    The format of the specified video file is not supported. Check and change the video file format and try again.

    408

    You do not have the required permissions. The possible cause is that this account is not activated, has overdue payments, or is not authorized to call this API.

    409

    The specified task ID does not exist. The possible cause is that the moderation results have exceeded the 24-hour validity period.

    480

    The number of concurrent moderation tasks exceeds the upper limit. Check and change the number of concurrent moderation tasks.

    500

    A system exception occurred.