All Products
Search
Document Center

Content Moderation:Video moderation

Last Updated:Dec 29, 2025

This topic describes how to use Content Moderation SDK for PHP to moderate videos for risky content.

Description

The video moderation API provides synchronous and asynchronous detection.

  • If you use synchronous video moderation, you can submit only a sequence of frames captured from a video for moderation. For more information about the related parameters, see /green/video/syncscan.

  • (Recommended) Asynchronous detection can analyze original videos or sequences of captured frames from videos. For a detailed description of the parameters, see Asynchronous detection.

Note
  • This SDK supports only public video URLs. It does not support local files or binary data.

  • You can use public HTTP or HTTPS URLs up to 2048 characters in length.

Prerequisites

The dependencies for Content Moderation SDK for PHP are installed. For more information, see Installation.

Note

You must use the required PHP version described in the Installation topic to install the dependencies. Otherwise, subsequent operation calls fail.

(Recommended) Submit asynchronous video moderation tasks

Operation

Description

Supported region

VideoAsyncScanRequest

Sends asynchronous requests to moderate videos for risky content across multiple moderation scenarios, including pornography, terrorist content, ad, undesirable scene, and logo detection.

  • cn-shanghai: China (Shanghai)

  • cn-beijing: China (Beijing)

  • cn-shenzhen: China (Shenzhen)

  • ap-southeast-1: Singapore

Sample code

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;

try {
    /**
     * Note: Reuse the instantiated client to improve detection performance and avoid repeated connections.
     * Common ways to obtain environment variables:
     * Obtain the AccessKey ID of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
     * Obtain the AccessKey secret of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
     */
    AlibabaCloud::accessKeyClient('Obtain the AccessKey ID of the RAM user from an environment variable', 'Obtain the AccessKey secret of the RAM user from an environment variable')
        ->timeout(10) // The timeout period is 10 seconds. This setting applies to all requests that use this client and do not have a separate timeout setting.
        ->connectTimeout(3) // The connection timeout period is 3 seconds. If the value is less than 1, the unit is automatically converted to milliseconds. This setting applies to all requests that use this client and do not have a separate connection timeout setting.
        ->regionId('cn-shanghai')
        ->asDefaultClient();
    
    $task1 = array('dataId' => 'Business data ID',
        'url' => 'URL of the video to moderate',
    );

    // scenes: The moderation scenarios. You can specify multiple scenarios.
    // callback and seed: Optional parameters for callback notifications.
    $result = Green::v20180509()->videoAsyncScan()
        ->timeout(10) // The timeout period is 10 seconds. This setting applies only to the current request.
        ->connectTimeout(3) // The connection timeout period is 3 seconds. If the value is less than 1, the unit is automatically converted to milliseconds. This setting applies only to the current request.
        ->body(json_encode(array("tasks" => array($task1),
            "scenes" => array("porn", "terrorism"),
            'callback' => 'Webhook address',
            'seed' => 'Random string')))
        ->request();
    print_r($result->toArray());
} catch (ClientException $exception) {
    echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
    echo $exception->getMessage() . PHP_EOL;
    echo $exception->getErrorCode() . PHP_EOL;
    echo $exception->getRequestId() . PHP_EOL;
    echo $exception->getErrorMessage() . PHP_EOL;
}

Query the results of asynchronous video moderation

Operation

Description

Supported region

VideoAsyncScanResultsRequest

Queries the results of asynchronous video moderation.

Note

Instead of calling this operation to poll the moderation results, we recommend that you set the callback parameter when you submit asynchronous video moderation tasks to receive the moderation results.

  • cn-shanghai: China (Shanghai)

  • cn-beijing: China (Beijing)

  • cn-shenzhen: China (Shenzhen)

  • ap-southeast-1: Singapore

Sample code

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;

try {
    /**
     * Note: Reuse the instantiated client to improve detection performance and avoid repeated connections.
     * Common ways to obtain environment variables:
     * Obtain the AccessKey ID of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
     * Obtain the AccessKey secret of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
     */
    AlibabaCloud::accessKeyClient('Obtain the AccessKey ID of the RAM user from an environment variable', 'Obtain the AccessKey secret of the RAM user from an environment variable')
        ->timeout(10) // The timeout period is 10 seconds. This setting applies to all requests that use this client and do not have a separate timeout setting.
        ->connectTimeout(3) // The connection timeout period is 3 seconds. If the value is less than 1, the unit is automatically converted to milliseconds. This setting applies to all requests that use this client and do not have a separate connection timeout setting.
        ->regionId('cn-shanghai')
        ->asDefaultClient();

    $result = Green::v20180509()->videoAsyncScanResults()
        ->timeout(10) // The timeout period is 10 seconds. This setting applies only to the current request.
        ->connectTimeout(3) // The connection timeout period is 3 seconds. If the value is less than 1, the unit is automatically converted to milliseconds. This setting applies only to the current request.
        ->body(json_encode(array('Video moderation task ID')))
        ->request();
    print_r($result->toArray());
} catch (ClientException $exception) {
    echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
    echo $exception->getMessage() . PHP_EOL;
    echo $exception->getErrorCode() . PHP_EOL;
    echo $exception->getRequestId() . PHP_EOL;
    echo $exception->getErrorMessage() . PHP_EOL;
}

Video snapshot synchronization check

Operation

Description

Supported region

VideoSyncScanRequest

Sends synchronous requests to moderate videos for risky content.

Note

You can submit only a sequence of frames that are captured from a video for video moderation. To submit other types of videos, we recommend that you use the VideoAsyncScanRequest operation.

  • cn-shanghai: China (Shanghai)

  • cn-beijing: China (Beijing)

  • cn-shenzhen: China (Shenzhen)

  • ap-southeast-1: Singapore

Sample code

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;

try {
    /**
     * Note: Reuse the instantiated client to improve detection performance and avoid repeated connections.
     * Common ways to obtain environment variables:
     * Obtain the AccessKey ID of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
     * Obtain the AccessKey secret of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
     */
    AlibabaCloud::accessKeyClient('Obtain the AccessKey ID of the RAM user from an environment variable', 'Obtain the AccessKey secret of the RAM user from an environment variable')
        ->timeout(10) // The timeout period is 10 seconds. This setting applies to all requests that use this client and do not have a separate timeout setting.
        ->connectTimeout(3) // The connection timeout period is 3 seconds. If the value is less than 1, the unit is automatically converted to milliseconds. This setting applies to all requests that use this client and do not have a separate connection timeout setting.
        ->regionId('cn-shanghai')
        ->asDefaultClient();


    $task1 = array('frames' => array(['offset' => '0', 'url' => 'URL of video snapshot 1'],
        ['offset' => '1', 'url' => 'URL of video snapshot 2'],
        ['offset' => '2', 'url' => 'URL of video snapshot 3']));

    // scenes: The moderation scenarios. You can specify multiple scenarios.
    $result = Green::v20180509()->videoSyncScan()
        ->timeout(10) // The timeout period is 10 seconds. This setting applies only to the current request.
        ->connectTimeout(3) // The connection timeout period is 3 seconds. If the value is less than 1, the unit is automatically converted to milliseconds. This setting applies only to the current request.
        ->body(json_encode(array('tasks' => array($task1),
            'scenes' => array('porn', 'terrorism'),
            'bizType' => 'Business scenario')))
        ->request();
    print_r($result->toArray());
} catch (ClientException $exception) {
    echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
    echo $exception->getMessage() . PHP_EOL;
    echo $exception->getErrorCode() . PHP_EOL;
    echo $exception->getRequestId() . PHP_EOL;
    echo $exception->getErrorMessage() . PHP_EOL;
}

Feedback on video detection results

If the moderation results do not meet your expectations, you can call the VideoFeedbackRequest operation to modify the results. Content Moderation adds the moderated video frames to the similar image blacklist or whitelist based on your feedback. When you submit a similar video frame for moderation, Content Moderation returns moderation results based on the label in your feedback.

For more information about the API, see Detection Result Feedback.

Interface

Description

Supported region

VideoFeedbackRequest

You can submit feedback to manually correct the algorithm's detection results.

  • cn-shanghai: China (Shanghai)

  • cn-beijing: China (Beijing)

  • cn-shenzhen: China (Shenzhen)

  • ap-southeast-1: Singapore

Sample code

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;

try {
    /**
     * Note: Reuse the instantiated client to improve detection performance and avoid repeated connections.
     * Common ways to obtain environment variables:
     * Obtain the AccessKey ID of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
     * Obtain the AccessKey secret of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
     */
    AlibabaCloud::accessKeyClient('Obtain the AccessKey ID of the RAM user from an environment variable', 'Obtain the AccessKey secret of the RAM user from an environment variable')
        ->timeout(10) // The timeout period is 10 seconds. This setting applies to all requests that use this client and do not have a separate timeout setting.
        ->connectTimeout(3) // The connection timeout period is 3 seconds. If the value is less than 1, the unit is automatically converted to milliseconds. This setting applies to all requests that use this client and do not have a separate connection timeout setting.
        ->regionId('cn-shanghai')
        ->asDefaultClient();

    // scenes: The moderation scenarios. You can specify multiple scenarios.
    // suggestion: The expected detection result. pass: normal. block: violation.
    $task1 = array("taskId" => 'Video moderation task ID',
        "dataId" => "Business data ID",
        "url" => "URL of the video",
        "frames" => array(array("url" => "URL of video snapshot 1", "offset" => "100"), array("url" => "URL of video snapshot 2", "offset" => "200")),
        "suggestion" => 'block',
        "scenes" => array("ad", "terrorism"),
        "note" => "Notes");

    $result = Green::v20180509()->videoFeedback()
        ->timeout(10) // The timeout period is 10 seconds. This setting applies only to the current request.
        ->connectTimeout(3) // The connection timeout period is 3 seconds. If the value is less than 1, the unit is automatically converted to milliseconds. This setting applies only to the current request.
        ->body(json_encode($task1))
        ->request();
    print_r($result->toArray());
} catch (ClientException $exception) {
    echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
    echo $exception->getMessage() . PHP_EOL;
    echo $exception->getErrorCode() . PHP_EOL;
    echo $exception->getRequestId() . PHP_EOL;
    echo $exception->getErrorMessage() . PHP_EOL;
}