Asynchronous detection

更新时间:
复制 MD 格式

This topic describes how to call the asynchronous video quality detection operation (/green/video/asyncscan) to detect video quality. This information helps you construct HTTP requests.

Usage notes

API operation: /green/video/asyncscan

This operation asynchronously detects quality issues in video files, such as blur, splicing, low brightness, black screens, and static frames. For more information about how to construct an HTTP request, see Request structure. To use a pre-built HTTP request, see SDK overview.

  • Billing information

    You are charged for calling this operation. For more information about the billing methods, see

  • Detection scenarios

    This scenario supports only standalone video quality detection and cannot be used with other scenarios. Audio content detection is not supported.

  • Response

    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 1 hour.

    • callback parameter: To automatically receive detection results, include the callback parameter in the request when you submit an asynchronous detection task. For more information, see Request parameters.
    • Retrieve detection results by polling: If you do not include the callback parameter when you submit the task, you must poll for the results. After the task is submitted, call the result query operation to retrieve the detection results. For more information, see Usage notes (Query asynchronous video detection results).
  • Video requirements
    The video to be detected must meet the following requirements:
    • The URLs of videos must be HTTP or HTTPS URLs.

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

    • A video can be up to 200 MB in size.

      If the video to be moderated exceeds 200 MB, the video must be segmented. You can join the DingTalk Group (DingTalk Group number: 35573806) and contact the technical support personnel to help you adjust the size limit.

    • The duration of a video moderation task varies based on the duration for downloading the video. Make sure that you use a stable and reliable storage service to store the videos to be moderated. We recommend that you use Object Storage Service (OSS).

QPS limits

You can call this operation up to 50 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.

Request parameters

NameTypeRequiredExampleDescription
bizTypeStringNodefault

The business scenario. You can create a business scenario in the

Content Moderation console. For more information, see Customize policies for machine-assisted moderation.

scenesStringArrayYes["quality"]The scenarios for video detection. The only valid value is quality, which indicates video quality detection.
callbackStringNohttp://www.aliyundoc.com/xx.json

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: the 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 an Alibaba Cloud account, but not the ID of a RAM user.

  • content: the JSON-formatted string to be parsed to the callback data in the JSON format. For more information about the format of the content parameter, see the sample success responses of each operation that you can call to query asynchronous moderation results.

Note

If your server successfully 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.

seedStringNoaabbcc123This value is used for the signature in the callback notification request. This parameter is required when you use the callback parameter.
cryptType
String
No
SHA256
The encryption algorithm used to encrypt the callback notification content when you enable callback notification. Content Moderation encrypts the returned string by using the encryption algorithm that you specify and sends the encrypted string to the callback URL. The returned string is in the UID + Seed + Content format. Valid values:
  • SHA256: The HMAC-SHA256 encryption algorithm is used. This is the default value.
  • 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.

tasksJSONArrayYesThe detection objects. Each element in the JSON array is a detection task struct. You can specify up to 100 elements, which means you can submit 100 pieces of content for detection at a time. To support 100 elements, you must adjust the number of concurrent tasks to 100 or more. For more information about the structure of each element, see task.
Table 1. task
NameTypeRequiredExampleDescription
clientInfoJSON objectNo{"userId":"120234234","userNick":"Mike","userType":"others"}

The information about the client. For more information, see the "Common request parameters" section of Common parameters.

The server determines whether to use the global clientInfo parameter or the clientInfo parameter that is described in this table.

Note

The clientInfo parameter in this table takes priority over the global one.

dataIdStringNovideoId xxxThe data ID. Make sure that all IDs in a single request are unique.
urlStringNohttp://www.aliyundoc.com/a.mp4The public URL of the video. The URL must be accessible from the Internet.
intervalIntegerNo1The interval for video snapshots, in seconds. Valid values: 1 to 600. Default value: 1.
maxFramesIntegerNo200The maximum number of frames that the system can capture from the video for this detection. Valid values: 5 to 3600. Default value: 200. To increase the limit, contact your account manager.
Note If you use an OSS URL (starting with oss://) as the video source and authorize Content Moderation to access Alibaba Cloud ApsaraVideo Media Processing (MTS), you can capture up to 20,000 frames. This does not incur additional fees. For more information about how to authorize Content Moderation to access MTS, see Authorize access to MTS.
Example of the result content
{
    "code": 200,
    "msg": "OK",
    "dataId": "videoId xxx",
    "taskId": "taskId xxx",
    "results": [
        {
            "label": "normal",
            "rate": 99.2,
            "scene": "quality",
            "suggestion": "pass"
        }
    ]
}

Response data

NameTypeExampleDescription
taskIdStringtaskId xxxThe ID of the detection task.
dataIdStringvideoId xxx

The ID of the moderation object.

Note

If you set the dataId parameter in the moderation request, the value of the dataId request parameter is returned here.

Examples

Request example
http(s)://[Endpoint]/green/video/asyncscan
&<Common request parameters>
{
    "scenes": [
        "quality"
    ],
    "tasks": [
        {
            "dataId": "videoId xxx",
            "url": "http://www.aliyundoc.com/a.mp4",
            "interval": 1,
            "maxFrames": 200
        }
    ]
}
Response example
{
    "code": 200,
    "msg": "OK",
    "requestId": "requestID xxx",
    "data": [
        {
            "dataId": "videoId xxx",
            "taskId": "taskId xxx"
        }
    ]
}

Usage notes (Query asynchronous video detection results)

API operation: /green/video/results

This operation queries the results of an asynchronous detection task. The recommended query interval is 30 seconds. The maximum interval is 4 hours. If you query for results after this period, the results might be lost.

Note

This operation is free of charge.

QPS limits

You can call this operation up to 50 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.

Request parameters

NameTypeRequiredExampleDescription
bodyJSONArrayYes["taskId xxx","taskId bbb"]A list of taskId values to query. The maximum length is 100.

Response data

NameTypeExampleDescription
codeInteger200

The returned HTTP status code.

For more information, see Common error codes.

msgStringOKThe response message for the request.
dataIdStringvideoId xxx

The ID of the moderation object.

Note

If you set the dataId parameter in the moderation request, the value of the dataId request parameter is returned here.

taskIdStringtaskId xxxThe ID of the detection task.
resultsJSONArrayThe returned results. When the call is successful (code=200), the response contains one or more elements. Each element is a struct. For more information about the structure, see result.
Note In stream pulling detection scenarios, a `code` of 280 indicates that the detection is in progress, and 200 indicates that the detection is complete. When the detection is in progress, the results include issues detected from the start of the detection to the current time.
Table 2. result
NameTypeExampleDescription
sceneStringqualityThe video detection scenario. This corresponds to the scenario in the request.
labelStringstaticThe classification of the detection result, which corresponds to the specific scene. Valid values:
  • normal: The video is normal.
  • blur: The video is blurry.
  • black_screen: The video contains black screens.
  • low_luminance: The video has low brightness.
  • split: The video contains spliced frames.
  • static: The video contains static frames.
suggestionStringblockThe recommended action. Valid values:
  • pass: The video is normal. No further action is required, or the target object was not identified.
  • review: The detection result is uncertain. Manual review is required, or the target object was identified.
  • block: The video is non-compliant. Take further action, such as deleting it or applying restrictions.
rateFloat99.2The probability that the result belongs to this classification. Valid values: 0 to 100. A higher value indicates a higher probability.
framesJSONArrayThe detection results for some frames that are classified into this category (FrameScanResult). Each element is a struct. For more information about the structure, see frame.
Table 3. frame
NameTypeExampleDescription
urlStringhttp://www.aliyundoc.comThe URL of the snapshot. If content with quality issues is found in the video, the URL of the snapshot is returned.
offsetInteger2The timestamp of this snapshot relative to the beginning of the video, in seconds.
labelStringstaticThe threat classification of this video snapshot. Valid values:
  • blur: The video is blurry.
  • black_screen: The video contains black screens.
  • low_luminance: The video has low brightness.
  • split: The video contains spliced frames.
  • static: The video contains static frames.
rateFloat99.2The probability that this video snapshot result belongs to the classification specified by label. Valid values: 0 to 100. A higher value indicates a higher probability.

Examples

Request example
http(s)://[Endpoint]/green/video/results
&<Common request parameters>
[
    "taskId xxx",
    "taskId bbb"
]
Response example
{
    "code": 200,
    "msg": "OK",
    "requestId": "requestID xxx",
    "data": [
        {
            "code": 200,
            "msg": "OK",
            "dataId": "videoId xxx",
            "taskId": "taskId xxx",
            "results": [
                {
                    "label": "static",
                    "rate": 99.2,
                    "scene": "quality",
                    "suggestion": "block"
                }
            ]
        }
    ]
}