Video moderation

Updated at:

Moderate recorded videos and live streams for risky content using the AI Guardrails SDK for Java. Submit a video URL or binary data to start an asynchronous moderation task, receive results via a callback URL, and act on the suggestion field (pass, review, or block) in the response.

How it works

  1. Create a DefaultAcsClient with your region and credentials.

  2. Submit a moderation task with VideoAsyncScanRequest. The API returns a taskId for each video.

  3. When moderation completes, AI Guardrails sends results to your callback URL as a POST request.

  4. Alternatively, poll for results using VideoAsyncScanResultsRequest with the taskId.

Choose a detection mode

ModeInputUse when
Asynchronous (recommended)Online video URL, local file, binary data, or live stream URLModerating full videos or live streams where results can be delivered asynchronously
SynchronousFrame image sequence onlyYou already have extracted frames and need immediate results inline
Note

The SDK accepts only public HTTP or HTTPS video URLs up to 2,048 characters. It does not accept local file paths or binary data directly — use ClientUploader to upload local content and get a temporary URL first.

Prerequisites

Before you begin, ensure that you have:

  • Installed Java dependencies using the version specified in Installation. Using a different Java version causes operation calls to fail.

  • Downloaded and imported the Extension.Uploader utility class if you plan to submit local files or binary data.

  • An AccessKey ID and AccessKey secret for a RAM user. Store these as environment variables (ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET). Avoid using root account credentials for API calls.

Submit asynchronous video moderation tasks

VideoAsyncScanRequest sends asynchronous requests to moderate videos across multiple scenarios, including pornography, terrorist content, advertisements, undesirable scenes, and logo detection.

Supported regions: cn-shanghai (China (Shanghai)), cn-beijing (China (Beijing)), cn-shenzhen (China (Shenzhen)), ap-southeast-1 (Singapore)

Frame sampling and billing

By default, the API captures one frame per second. You can customize the capture frequency using the interval parameter.

Billing is based on the number of frames captured multiplied by the number of moderation scenarios. For example, a 1-minute video that produces 60 frames, moderated for both pornography (porn) and terrorist content (terrorism), is billed as 120 frame-moderation units (60 frames x 2 scenarios).

Online video URL

Submit a publicly accessible HTTP or HTTPS video URL for asynchronous moderation.

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.VideoAsyncScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Main {

    public static void main(String[] args) throws Exception {
        // Load credentials from environment variables.
        // Use a RAM user instead of the root account to reduce security risk.
        // Method 1: System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
        // Method 2: System.getProperty("ALIBABA_CLOUD_ACCESS_KEY_ID")
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");

        // Reuse the client across requests to improve performance and avoid repeated connections.
        IAcsClient client = new DefaultAcsClient(profile);

        VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
        videoAsyncScanRequest.setAcceptFormat(FormatType.JSON);
        videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST);

        List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
        Map<String, Object> task = new LinkedHashMap<String, Object>();
        task.put("dataId", UUID.randomUUID().toString());
        task.put("url", "<online-video-url>");   // Public HTTP or HTTPS URL, up to 2,048 characters

        tasks.add(task);

        JSONObject data = new JSONObject();
        data.put("scenes", Arrays.asList("porn", "terrorism")); // Moderation scenarios — billing is per frame per scenario
        data.put("tasks", tasks);
        data.put("callback", "<your-callback-url>");  // AI Guardrails POSTs results here when moderation completes
        data.put("seed", "<your-seed>");              // Included in the callback payload for signature verification

        videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
        videoAsyncScanRequest.setConnectTimeout(3000);
        videoAsyncScanRequest.setReadTimeout(6000);

        try {
            HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);

            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
                int requestCode = scrResponse.getIntValue("code");
                JSONArray taskResults = scrResponse.getJSONArray("data");
                if (200 == requestCode) {
                    for (Object taskResult : taskResults) {
                        int taskCode = ((JSONObject) taskResult).getIntValue("code");
                        if (200 == taskCode) {
                            // Save the taskId — use it to poll results with VideoAsyncScanResultsRequest.
                            System.out.println(((JSONObject) taskResult).getString("taskId"));
                        } else {
                            System.out.println("task process fail. task response:" + JSON.toJSONString(taskResult));
                        }
                    }
                } else {
                    System.out.println("the whole scan request failed. response:" + JSON.toJSONString(scrResponse));
                }
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Replace the following placeholders:

PlaceholderDescriptionExample
<online-video-url>Publicly accessible HTTP or HTTPS video URLhttps://example.com/video.mp4
<your-callback-url>Endpoint that receives moderation resultshttps://yourapp.com/callback
<your-seed>Token included in the callback payload for verificationmyPersonalSeed

Local video file

Use ClientUploader to upload a local video file and get a temporary URL, then submit that URL for moderation.

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.extension.uploader.ClientUploader;
import com.aliyuncs.green.model.v20180509.VideoAsyncScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Main {

    public static void main(String[] args) throws Exception {
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        // Upload the local video file to get a temporary URL, then submit that URL for moderation.
        String url = null;
        ClientUploader uploader = ClientUploader.getVideoClientUploader(profile, false);
        try {
            url = uploader.uploadFile("<absolute-path-to-local-video>");
        } catch (Exception e) {
            e.printStackTrace();
        }

        VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
        videoAsyncScanRequest.setAcceptFormat(FormatType.JSON);
        videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST);

        List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
        Map<String, Object> task = new LinkedHashMap<String, Object>();
        task.put("dataId", UUID.randomUUID().toString());
        task.put("url", url);

        tasks.add(task);

        JSONObject data = new JSONObject();
        data.put("scenes", Arrays.asList("porn", "terrorism"));
        data.put("tasks", tasks);
        data.put("callback", "<your-callback-url>");
        data.put("seed", "<your-seed>");

        videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
        videoAsyncScanRequest.setConnectTimeout(3000);
        videoAsyncScanRequest.setReadTimeout(10000);

        try {
            HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);

            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
                int requestCode = scrResponse.getIntValue("code");
                JSONArray taskResults = scrResponse.getJSONArray("data");
                if (200 == requestCode) {
                    for (Object taskResult : taskResults) {
                        int taskCode = ((JSONObject) taskResult).getIntValue("code");
                        if (200 == taskCode) {
                            System.out.println(((JSONObject) taskResult).getString("taskId"));
                        } else {
                            System.out.println("task process fail. task response:" + JSON.toJSONString(taskResult));
                        }
                    }
                } else {
                    System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scrResponse));
                }
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Binary video data

Read a local video file as a byte array, upload the binary data using ClientUploader, and submit the resulting URL for moderation.

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.extension.uploader.ClientUploader;
import com.aliyuncs.green.model.v20180509.VideoAsyncScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Main {

    public static void main(String[] args) throws Exception {
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        // Read the video file as binary data, upload it, and get a temporary URL.
        // In production, pass the binary data directly instead of reading from a file.
        ClientUploader uploader = ClientUploader.getVideoClientUploader(profile, false);
        byte[] videoBytes = null;
        String url = null;
        try {
            videoBytes = FileUtils.readFileToByteArray(new File("<path-to-local-video>"));
            url = uploader.uploadBytes(videoBytes);
        } catch (Exception e) {
            System.out.println("upload file to server fail." + e.toString());
        }

        VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
        videoAsyncScanRequest.setAcceptFormat(FormatType.JSON);
        videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST);

        List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
        Map<String, Object> task = new LinkedHashMap<String, Object>();
        task.put("dataId", UUID.randomUUID().toString());
        task.put("url", url);

        tasks.add(task);

        JSONObject data = new JSONObject();
        data.put("scenes", Arrays.asList("porn", "terrorism"));
        data.put("tasks", tasks);
        data.put("callback", "<your-callback-url>");
        data.put("seed", "<your-seed>");

        videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
        videoAsyncScanRequest.setConnectTimeout(3000);
        videoAsyncScanRequest.setReadTimeout(10000);

        try {
            HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);

            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
                int requestCode = scrResponse.getIntValue("code");
                JSONArray taskResults = scrResponse.getJSONArray("data");
                if (200 == requestCode) {
                    for (Object taskResult : taskResults) {
                        int taskCode = ((JSONObject) taskResult).getIntValue("code");
                        if (200 == taskCode) {
                            System.out.println(((JSONObject) taskResult).getString("taskId"));
                        } else {
                            System.out.println("task process fail. task response:" + JSON.toJSONString(taskResult));
                        }
                    }
                } else {
                    System.out.println("the whole scan request failed. response:" + JSON.toJSONString(scrResponse));
                }
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Live stream

Set live to true and provide the live stream URL as the url parameter.

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.VideoAsyncScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Main {

    public static void main(String[] args) throws Exception {
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
        videoAsyncScanRequest.setAcceptFormat(FormatType.JSON);
        videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST);

        List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
        Map<String, Object> task = new LinkedHashMap<String, Object>();
        task.put("dataId", "<live-stream-id>");
        task.put("url", "<live-stream-url>");

        tasks.add(task);

        JSONObject data = new JSONObject();
        data.put("scenes", Arrays.asList("porn", "terrorism"));
        data.put("live", true);               // Set to true for live stream moderation
        data.put("tasks", tasks);
        data.put("callback", "<your-callback-url>");
        data.put("seed", "<your-seed>");

        videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
        videoAsyncScanRequest.setConnectTimeout(3000);
        videoAsyncScanRequest.setReadTimeout(10000);

        try {
            HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);

            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
                int requestCode = scrResponse.getIntValue("code");
                JSONArray taskResults = scrResponse.getJSONArray("data");
                if (200 == requestCode) {
                    for (Object taskResult : taskResults) {
                        int taskCode = ((JSONObject) taskResult).getIntValue("code");
                        if (200 == taskCode) {
                            System.out.println(((JSONObject) taskResult).getString("taskId"));
                        } else {
                            System.out.println("task process fail. task response:" + JSON.toJSONString(taskResult));
                        }
                    }
                } else {
                    System.out.println("the whole scan request failed. response:" + JSON.toJSONString(scrResponse));
                }
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Live stream with audio moderation

To moderate both the video frames and audio track of a live stream, add audioScenes set to ["antispam"]. Audio moderation is billed separately based on video duration multiplied by the unit price of audio anti-spam.

JSONObject data = new JSONObject();
data.put("scenes", Arrays.asList("porn", "terrorism")); // Video frame scenarios
data.put("live", true);
data.put("tasks", tasks);
data.put("callback", "<your-callback-url>");
data.put("seed", "<your-seed>");
data.put("audioScenes", Arrays.asList("antispam"));     // Audio moderation scenario

Query asynchronous moderation results

VideoAsyncScanResultsRequest retrieves results for submitted asynchronous tasks by taskId.

Note

Set a callback URL when submitting tasks instead of polling. Polling with VideoAsyncScanResultsRequest should be a fallback only.

Supported regions: cn-shanghai, cn-beijing, cn-shenzhen, ap-southeast-1

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.VideoAsyncScanResultsRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        VideoAsyncScanResultsRequest videoAsyncScanResultsRequest = new VideoAsyncScanResultsRequest();
        videoAsyncScanResultsRequest.setAcceptFormat(FormatType.JSON);

        List<String> taskList = new ArrayList<String>();
        taskList.add("<task-id>");  // The taskId returned when you submitted the moderation task

        videoAsyncScanResultsRequest.setHttpContent(JSON.toJSONString(taskList).getBytes("UTF-8"), "UTF-8", FormatType.JSON);
        videoAsyncScanResultsRequest.setConnectTimeout(3000);
        videoAsyncScanResultsRequest.setReadTimeout(6000);

        try {
            HttpResponse httpResponse = client.doAction(videoAsyncScanResultsRequest);
            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
                int requestCode = scrResponse.getIntValue("code");
                JSONArray taskResults = scrResponse.getJSONArray("data");
                if (200 == requestCode) {
                    for (Object taskResult : taskResults) {
                        int taskCode = ((JSONObject) taskResult).getIntValue("code");
                        if (280 == taskCode) {
                            // Still moderating — check again later.
                            System.out.println(((JSONObject) taskResult).getString("taskId"));
                        } else if (200 == taskCode) {
                            System.out.println(((JSONObject) taskResult).getString("taskId"));
                            JSONArray results = ((JSONObject) taskResult).getJSONArray("results");
                            for (Object result : results) {
                                System.out.println(((JSONObject) result).getString("label"));      // Moderation category
                                System.out.println(((JSONObject) result).getString("rate"));       // Confidence score, 0-100
                                System.out.println(((JSONObject) result).getString("scene"));      // Scenario from the request
                                System.out.println(((JSONObject) result).getString("suggestion")); // Recommended action: pass, review, or block
                            }
                        } else {
                            System.out.println("task process fail. task response:" + JSON.toJSONString(taskResult));
                        }
                    }
                } else {
                    System.out.println("the whole scan request failed. response:" + JSON.toJSONString(scrResponse));
                }
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Understand the response

The results array in a completed task contains one entry per moderation scenario.

FieldTypeDescription
sceneStringThe moderation scenario specified in the request, such as porn or terrorism
labelStringThe detected content category within that scenario
rateNumberConfidence score from 0 to 100. A higher value means higher confidence.
suggestionStringThe recommended action: pass (no action needed), review (manual review required), or block (content violates policy — remove or block it)

Sample response:

{
  "code": 200,
  "data": [
    {
      "code": 200,
      "taskId": "vi_xxxxxxxxxxxxxxxxxx",
      "results": [
        {
          "scene": "porn",
          "label": "normal",
          "rate": 99.1,
          "suggestion": "pass"
        },
        {
          "scene": "terrorism",
          "label": "normal",
          "rate": 98.5,
          "suggestion": "pass"
        }
      ]
    }
  ]
}

Submit synchronous video moderation tasks

VideoSyncScanRequest accepts a sequence of pre-extracted video frames, not a full video file. For full videos or live streams, use VideoAsyncScanRequest instead.

Supported regions: cn-shanghai, cn-beijing, cn-shenzhen, ap-southeast-1

The following example submits three frames extracted at offsets 0, 5, and 10 seconds.

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.VideoSyncScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Main {

    public static void main(String[] args) throws Exception {
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        VideoSyncScanRequest videoSyncScanRequest = new VideoSyncScanRequest();
        videoSyncScanRequest.setAcceptFormat(FormatType.JSON);
        videoSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST);

        List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
        Map<String, Object> task = new LinkedHashMap<String, Object>();
        task.put("dataId", UUID.randomUUID().toString());

        // Provide an array of frame objects. Each frame has an offset (in seconds) and a URL.
        List<Map<String, Object>> frames = new ArrayList<Map<String, Object>>();
        Map<String, Object> frame1 = new LinkedHashMap<String, Object>();
        frame1.put("offset", 0);
        frame1.put("url", "<url-of-frame-at-0s>");

        Map<String, Object> frame2 = new LinkedHashMap<String, Object>();
        frame2.put("offset", 5);
        frame2.put("url", "<url-of-frame-at-5s>");

        Map<String, Object> frame3 = new LinkedHashMap<String, Object>();
        frame3.put("offset", 10);
        frame3.put("url", "<url-of-frame-at-10s>");

        frames.addAll(Arrays.asList(frame1, frame2, frame3));
        task.put("frames", frames);
        tasks.add(task);

        JSONObject data = new JSONObject();
        data.put("scenes", Arrays.asList("porn", "terrorism"));
        data.put("tasks", tasks);

        videoSyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
        videoSyncScanRequest.setConnectTimeout(3000);
        videoSyncScanRequest.setReadTimeout(10000);

        try {
            HttpResponse httpResponse = client.doAction(videoSyncScanRequest);

            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
                int requestCode = scrResponse.getIntValue("code");
                JSONArray taskResults = scrResponse.getJSONArray("data");
                if (200 == requestCode) {
                    for (Object taskResult : taskResults) {
                        int taskCode = ((JSONObject) taskResult).getIntValue("code");
                        if (200 == taskCode) {
                            System.out.println(((JSONObject) taskResult).getString("taskId"));
                            JSONArray results = scrResponse.getJSONArray("results");
                            for (Object result : results) {
                                System.out.println(((JSONObject) result).getString("label"));
                                System.out.println(((JSONObject) result).getString("rate"));
                                System.out.println(((JSONObject) result).getString("scene"));
                                System.out.println(((JSONObject) result).getString("suggestion"));
                            }
                        } else {
                            System.out.println("task process fail. task response:" + JSON.toJSONString(taskResult));
                        }
                    }
                } else {
                    System.out.println("the whole scan request failed. response:" + JSON.toJSONString(scrResponse));
                }
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Provide feedback on moderation results

VideoFeedbackRequest lets you correct moderation results that do not match your expectations. AI Guardrails adds the affected video frames to the similar image blacklist or whitelist based on your feedback. Future submissions of similar frames return results consistent with your feedback label.

For parameter details, see /green/video/feedback.

Supported regions: cn-shanghai, cn-beijing, cn-shenzhen, ap-southeast-1

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.VideoFeedbackRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class VideoFeedbackSample {

    public static void main(String[] args) throws Exception {
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        VideoFeedbackRequest videoFeedbackRequest = new VideoFeedbackRequest();
        videoFeedbackRequest.setAcceptFormat(FormatType.JSON);
        videoFeedbackRequest.setMethod(MethodType.POST);
        videoFeedbackRequest.setEncoding("utf-8");
        videoFeedbackRequest.setProtocol(ProtocolType.HTTP);

        List<JSONObject> framesList = new ArrayList();
        JSONObject frame1 = new JSONObject();
        frame1.put("url", "<url-of-video-frame>");
        frame1.put("offset", 100);
        framesList.add(frame1);

        // suggestion: the label you want applied to this content.
        //   pass  — the frame is normal and should not be flagged.
        //   block — the frame contains a violation and should be blocked.
        JSONObject httpBody = new JSONObject();
        httpBody.put("dataId", "<moderated-data-id>");
        httpBody.put("taskId", "<video-moderation-task-id>");
        httpBody.put("url", "<url-of-moderated-video>");
        httpBody.put("suggestion", "block");
        httpBody.put("frames", framesList);
        httpBody.put("scenes", Arrays.asList("ad", "terrorism"));
        httpBody.put("note", "<remarks>");

        videoFeedbackRequest.setHttpContent(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(httpBody.toJSONString()),
                "UTF-8", FormatType.JSON);

        videoFeedbackRequest.setConnectTimeout(3000);
        videoFeedbackRequest.setReadTimeout(10000);
        try {
            HttpResponse httpResponse = client.doAction(videoFeedbackRequest);

            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
                int requestCode = scrResponse.getIntValue("code");
                if (200 == requestCode) {
                    // Feedback submitted successfully.
                } else {
                    System.out.println("the whole request failed. response:" + JSON.toJSONString(scrResponse));
                }
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

What's next