Current Location: Home> Latest Articles> How to Use PHP to Integrate Baidu Video Content Review API and Perform Video Audits

How to Use PHP to Integrate Baidu Video Content Review API and Perform Video Audits

M66 2025-06-12

How to Integrate Baidu Video Content Review API with PHP

With the rapid development of the internet, an increasing amount of video content is being uploaded to various platforms. However, some videos may contain harmful, illegal, or inappropriate information. To protect users' rights, platforms need efficient video content review tools. Baidu provides a powerful video content review API, and in this article, we will guide you step-by-step on how to integrate it with PHP.

Step 1: Apply for Baidu Video Content Review API

  1. First, you need to register an account on Baidu AI Open Platform and create a new application.
  2. When creating the application, select the "Content Review" service.
  3. After successful creation, you will receive an API Key and Secret Key, which are essential for calling the Baidu Video Content Review API.

Step 2: Install PHP SDK

  1. Download and extract the PHP SDK provided by Baidu AI Open Platform into your project directory.
  2. Create a file named config.php in your project directory to store your API Key and Secret Key. Add the following code to the file:
<?php
// Replace with your own API Key and Secret Key
define('API_KEY', 'your_api_key');
define('SECRET_KEY', 'your_secret_key');

Step 3: Call the Video Review API

Now, we can begin using the Baidu Video Content Review API to review videos.

  1. Create a new PHP file in the directory where the video to be reviewed is located. The example code is as follows:
<?php
require_once 'path_to_sdk/AipContentCensor/AipContentCensor.php';
require_once 'config.php';

// Create SDK object
$client = new AipContentCensor(API_KEY, SECRET_KEY);

// Perform video review
$response = $client->videoCensorUserDefined('path_to_video_file');

// Output review result
var_dump($response);

In the code above, we use the videoCensorUserDefined method to review the video. Be sure to replace "path_to_sdk" with the actual path of your SDK, and "path_to_video_file" with the path of the video file you want to review.

Step 4: Parse the Review Results

Once the PHP file is executed, you will receive a JSON string containing the review result. You can analyze the fields to determine whether the video is compliant. Below is an example of a response:

Array
(
    [conclusion] => Not Compliant
    [log_id] => 2021081800000001
    [data] => Array
    (
        [0] => Array
        (
            [subType] => ocr Sampling Check
            [conclusion] => Not Compliant
            [msg] => 【Sampling Check】Textual Pornographic Content
        )
        [1] => Array
        (
            [subType] => porn Pornographic
            [conclusion] => Not Compliant
            [msg] => 【Porn】【Pornographic】
        )
    )
)

In this example, the "conclusion" field indicates the review result of the video. If it says "Not Compliant," the video may contain issues. The "log_id" is a unique ID for this review, useful for tracking the audit records.

Summary

By following the steps above, we successfully integrated Baidu's Video Content Review API with PHP and implemented video content review functionality. With Baidu's powerful content review technology, we can more efficiently filter out inappropriate content and ensure that the platform’s content complies with relevant regulations. We hope this article helps you in the video review process, making it easier to manage content on your platform.