This topic describes how to use the Java SDK to moderate videos for risky content. You can moderate both images and audio in videos.

Overview

  • The Java SDK supports both synchronous and asynchronous video moderation. If you use synchronous video moderation, you can only submit a sequence of image frames captured from a video for moderation. If you use asynchronous video moderation, you can submit either a video or a sequence of image frames captured from the video for moderation. We recommend that you use asynchronous video moderation.
  • You can submit the URL of an online video, the URL of a local video, a binary video stream, or a video live stream for video moderation.

Preparations

Before calling operations, make the following preparations:
  1. Create an AccessKey ID and AccessKey secret of your Alibaba Cloud account. For more information, see Create an AccessKey.
  2. Install Java dependencies. For more information, see Installation.
  3. Download and import the Extension.Uploader utility class into your project if you submit a local image or a binary image stream for image moderation.

(Recommended) Submit asynchronous video moderation tasks

Operation description
Operation Feature Region Description
VideoAsyncScanRequest Sends asynchronous requests to moderate videos for risky content.
  • cn-shanghai: China (Shanghai)
  • cn-beijing: China (Beijing)
  • cn-shenzhen: China (Shenzhen)
  • ap-southeast-1: Singapore
  • us-west-1: US (Silicon Valley)
This operation moderates videos for risky content in multiple moderation scenarios, including pornography, terrorist content, ad, undesirable scene, and logo detection.
Sample code
  • Submit the URL of an online video for video moderation
    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.VideoAsyncScanRequest;
    import com.aliyuncs.http.FormatType;
    import com.aliyuncs.http.HttpResponse;
    import com.aliyuncs.profile.DefaultProfile;
    import com.aliyuncs.profile.IClientProfile;
    
    import java.util. *;
    
    /**
     * TODO Add class description here
     *
     * @author jialun.wjl
     * @create 2018/12/24 19:20
     */
    public class Main {
    
        public static void main(String[] args) throws Exception {
            IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
            DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
            IAcsClient client = new DefaultAcsClient(profile);
    
            VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
            videoAsyncScanRequest.setAcceptFormat(FormatType.JSON); // Specify the response format of the operation.
            videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // Specify the request method.
    
            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", "Enter the HTTP or HTTPS URL of the online video that can be accessed over a public network.");
    
            tasks.add(task);
            /**
             * Specify the moderation scenario. The system charges you based on the moderation scenario that you specify.
             * By default, one frame is captured from the video per second. You can specify the frequency at which sequential frames are captured. The system charges you based on the number of frames captured from the video and the number of moderation scenarios for each frame.
             * For example, if 60 frames are captured from a 1-minute-long video and you want to moderate the video for both pornography and terrorist content, you are charged for moderating 60 frames for pornography and 60 frames for terrorist content.
             * In the scenes parameter, porn indicates that the server detects pornography, and terrorism indicates that the server detects terrorist content.
             */
            JSONObject data = new JSONObject();
            data.put("scenes", Arrays.asList("porn", "terrorism"));
            data.put("tasks", tasks);
            data.put("callback", "http://xxx.xxx.xx/xxx.json");
            data.put("seed", "yourPersonalSeed");
    
            videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
    
            /**
             * You must set the connection timeout and read timeout.
             */
            videoAsyncScanRequest.setConnectTimeout(3000);
            videoAsyncScanRequest.setReadTimeout(6000);
            try {
                HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);
    
                if(httpResponse.isSuccess()){
                    JSONObject jsonObject = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                    System.out.println(JSON.toJSONString(jsonObject, true));
                }else{
                    System.out.println("response not success. status:" + httpResponse.getStatus());
                }
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }
    }
  • Submit the URL of a local video for video moderation
    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.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.*;
    
    public class Main {
    
        public static void main(String[] args) throws Exception {
            IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
            DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
            IAcsClient client = new DefaultAcsClient(profile);
    
            VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
            videoAsyncScanRequest.setAcceptFormat(FormatType.JSON); // Specify the response format of the operation.
            videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // Specify the request method.
    
            /**
             * If you want to moderate a video stored on the local server, use the following code snippet to generate a URL based on the storage path of the video.
             * Then, submit the URL as the video address to the server.
             */
            String url = null;
            ClientUploader uploader = ClientUploader.getVideoClientUploader(profile, false);
            try{
                url = uploader.uploadFile("d:/test.mp4");
            }catch (Exception e){
                e.printStackTrace();
            }
    
            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);
            data.put("callback", "http://xxx.xxx.xx/xxx.json");
            data.put("seed", "yourPersonalSeed");
    
            tasks.add(task);
            /**
             * Specify the moderation scenario. The system charges you based on the moderation scenario that you specify.
             * By default, one frame is captured from the video per second. You can specify the frequency at which sequential frames are captured. The system charges you based on the number of frames captured from the video and the number of moderation scenarios for each frame.
             * For example, if 60 frames are captured from a 1-minute-long video and you want to moderate the video for both pornography and terrorist content, you are charged for moderating 60 frames for pornography and 60 frames for terrorist content.
             * In the scenes parameter, porn indicates that the server detects pornography, and terrorism indicates that the server detects terrorist content.
             */
            JSONObject data = new JSONObject();
            data.put("scenes", Arrays.asList("porn", "terrorism"));
            data.put("tasks", tasks);
    
            videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
    
            /**
             * You must set the connection timeout and read timeout.
             */
            videoAsyncScanRequest.setConnectTimeout(3000);
            videoAsyncScanRequest.setReadTimeout(10000);
            try {
                HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);
    
                if(httpResponse.isSuccess()){
                    JSONObject jsonObject = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                    System.out.println(JSON.toJSONString(jsonObject, true));
                }else{
                    System.out.println("response not success. status:" + httpResponse.getStatus());
                }
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }
    }
  • Submit a binary video stream for video moderation
    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.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.*;
    
    public class Main {
    
        public static void main(String[] args) throws Exception {
            IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
            DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
            IAcsClient client = new DefaultAcsClient(profile);
    
            VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
            videoAsyncScanRequest.setAcceptFormat(FormatType.JSON); // Specify the response format of the operation.
            videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // Specify the request method.
    
            /**
             * If you want to moderate a video stored on the local server, use the following code snippet to generate a URL based on the storage path of the video.
             * Then, submit the URL as the video address to the server.
             */
            ClientUploader uploader = ClientUploader.getVideoClientUploader(profile, false);
            byte[] videoBytes = null;
            String url = null;
            try{
                // Read and convert a local video to binary data and submit the binary data for moderation. In the actual code, directly use the binary data of your video.
                videoBytes = FileUtils.readFileToByteArray(new File("/Users/01fb4ab6420b5f34623e13b82b51ef87.jpg"));
                // Upload the binary stream to the server.
                url = uploader.uploadBytes(videoBytes);
            }catch (Exception e){
                System.out.println("upload file to server fail.", e);
            }
    
            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);
            /**
             * Specify the moderation scenario. The system charges you based on the moderation scenario that you specify.
             * By default, one frame is captured from the video per second. You can specify the frequency at which sequential frames are captured. The system charges you based on the number of frames captured from the video and the number of moderation scenarios for each frame.
             * For example, if 60 frames are captured from a 1-minute-long video and you want to moderate the video for both pornography and terrorist content, you are charged for moderating 60 frames for pornography and 60 frames for terrorist content.
             * In the scenes parameter, porn indicates that the server detects pornography, and terrorism indicates that the server detects terrorist content.
             */
            JSONObject data = new JSONObject();
            data.put("scenes", Arrays.asList("porn", "terrorism"));
            data.put("tasks", tasks);
            data.put("callback", "http://xxx.xxx.xx/xxx.json");
            data.put("seed", "yourPersonalSeed");
    
            videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
    
            /**
             * You must set the connection timeout and read timeout.
             */
            videoAsyncScanRequest.setConnectTimeout(3000);
            videoAsyncScanRequest.setReadTimeout(10000);
            try {
                HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);
    
                if(httpResponse.isSuccess()){
                    JSONObject jsonObject = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                    System.out.println(JSON.toJSONString(jsonObject, true));
                }else{
                    System.out.println("response not success. status:" + httpResponse.getStatus());
                }
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }
    }
  • Submit a video live stream for video moderation
    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.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.*;
    
    public class Main {
    
        public static void main(String[] args) throws Exception {
            IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
            DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
            IAcsClient client = new DefaultAcsClient(profile);
    
            VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
            videoAsyncScanRequest.setAcceptFormat(FormatType.JSON); // Specify the response format of the operation.
            videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // Specify the request method.
    
            List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
            Map<String, Object> task = new LinkedHashMap<String, Object>();
            task.put("dataId", UUID.randomUUID().toString());
            // Set the url parameter to the URL of your live stream.
            task.put("url", "http://xxxx/test.mp4");
    
            tasks.add(task);
            /**
             * Specify the moderation scenario. The system charges you based on the moderation scenario that you specify.
             * By default, one frame is captured from the video per second. You can specify the frequency at which sequential frames are captured. The system charges you based on the number of frames captured from the video and the number of moderation scenarios for each frame.
             * For example, if 60 frames are captured from a 1-minute-long video and you want to moderate the video for both pornography and terrorist content, you are charged for moderating 60 frames for pornography and 60 frames for terrorist content.
             * In the scenes parameter, porn indicates that the server detects pornography, and terrorism indicates that the server detects terrorist content.
             */
            JSONObject data = new JSONObject();
            data.put("scenes", Arrays.asList("porn", "terrorism"));
            data.put("live", true);
            data.put("tasks", tasks);
            data.put("callback", "http://xxx.xxx.xx/xxx.json");
            data.put("seed", "yourPersonalSeed");
    
            videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
    
            /**
             * You must set the connection timeout and read timeout.
             */
            videoAsyncScanRequest.setConnectTimeout(3000);
            videoAsyncScanRequest.setReadTimeout(10000);
            try {
                HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);
    
                if(httpResponse.isSuccess()){
                    JSONObject jsonObject = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                    System.out.println(JSON.toJSONString(jsonObject, true));
                }else{
                    System.out.println("response not success. status:" + httpResponse.getStatus());
                }
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }
    }
  • Submit a video live stream to moderate both the video images and audio
    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.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.*;
    
    public class Main {
    
        public static void main(String[] args) throws Exception {
            IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
            DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
            IAcsClient client = new DefaultAcsClient(profile);
    
            VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest();
            videoAsyncScanRequest.setAcceptFormat(FormatType.JSON); // Specify the response format of the operation.
            videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // Specify the request method.
    
            List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
            Map<String, Object> task = new LinkedHashMap<String, Object>();
            task.put("dataId", UUID.randomUUID().toString());
            // Set the url parameter to the URL of your live stream.
            task.put("url", "http://xxxx/test.mp4");
    
            tasks.add(task);
            /**
             * Specify the moderation scenario. The system charges you based on the moderation scenario that you specify.
             * By default, one frame is captured from the video per second. You can specify the frequency at which sequential frames are captured. The system charges you based on the number of frames captured from the video and the number of moderation scenarios for each frame.
             * For example, if 60 frames are captured from a 1-minute-long video and you want to moderate the video for both pornography and terrorist content, you are charged for moderating 60 frames for pornography and 60 frames for terrorist content.
             * In the scenes parameter, porn indicates that the server detects pornography, and terrorism indicates that the server detects terrorist content.
             */
            JSONObject data = new JSONObject();
            data.put("scenes", Arrays.asList("porn", "terrorism"));
            data.put("live", true);
            data.put("tasks", tasks);
            data.put("callback", "http://xxx.xxx.xx/xxx.json");
            data.put("seed", "yourPersonalSeed");
    
            /**
             * In addition to moderating video images, if you want to moderate the audio in the video for risky content, specify antispam in the audioScenes parameter.
             * The expense for audio moderation equals the product of the video duration and the unit price of audio anti-spam.
             */
            data.put("audioScenes", Arrays.asList("antispam"));
    
            videoAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
    
            /**
             * You must set the connection timeout and read timeout.
             */
            videoAsyncScanRequest.setConnectTimeout(3000);
            videoAsyncScanRequest.setReadTimeout(10000);
            try {
                HttpResponse httpResponse = client.doAction(videoAsyncScanRequest);
    
                if(httpResponse.isSuccess()){
                    JSONObject jsonObject = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                    System.out.println(JSON.toJSONString(jsonObject, true));
                }else{
                    System.out.println("response not success. status:" + httpResponse.getStatus());
                }
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }
    }

Query the results of asynchronous video moderation

Operation description
Operation Feature Region Description
VideoAsyncScanResultsRequest Queries the results of asynchronous video moderation tasks.
  • cn-shanghai: China (Shanghai)
  • cn-beijing: China (Beijing)
  • cn-shenzhen: China (Shenzhen)
  • ap-southeast-1: Singapore
  • us-west-1: US (Silicon Valley)
This operation queries the video moderation results through polling. We recommend that you configure a callback notification to receive the moderation results.
Sample code
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.VideoAsyncScanResultsRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util. *;

/**
 * TODO Add class description here
 *
 * @author jialun.wjl
 * @create 2018/12/24 19:22
 */
public class Main {

    public static void main(String[] args) throws Exception {
        IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
        DefaultProfile.addEndpoint("cn-shanghai", "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>();
        // Specify the task ID to query the results of an asynchronous video moderation task that you submit by calling the VideoAsyncScanRequest operation. The task ID is returned by the VideoAsyncScanRequest operation after you submit the task.
        taskList.add("vi3pnWxOlikyx6KJNtY7Naza-1pZ$MN");

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

        /**
         * You must set the connection timeout and read timeout.
         */
        videoAsyncScanResultsRequest.setConnectTimeout(3000);
        videoAsyncScanResultsRequest.setReadTimeout(6000);
        try {
            HttpResponse httpResponse = client.doAction(videoAsyncScanResultsRequest);
            if(httpResponse.isSuccess()){
                JSONObject jsonObject = JSON
                    .parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(jsonObject, true));
            }else{
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Submit synchronous video moderation tasks

Operation description
Operation Feature Region Description
VideoSyncScanRequest Sends synchronous requests to moderate videos for risky content.
  • cn-shanghai: China (Shanghai)
  • cn-beijing: China (Beijing)
  • cn-shenzhen: China (Shenzhen)
  • ap-southeast-1: Singapore
  • us-west-1: US (Silicon Valley)
If you use synchronous video moderation, you can only submit a sequence of image frames captured from a video for moderation. We recommend that you use asynchronous video moderation.
Sample code
Note The following sample code submits a sequence of image frames captured from a video for moderation.
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.VideoSyncScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.*;

public class Main3 {

    public static void main(String[] args) throws Exception {
        IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
        DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        VideoSyncScanRequest videoSyncScanRequest = new VideoSyncScanRequest();
        videoSyncScanRequest.setAcceptFormat(FormatType.JSON); // Specify the response format of the operation.
        videoSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // Specify the request method.

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

        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", "https://img.alicdn.com/tfs/TB1k_g9l26H8KJjSspmXXb2WXXa-600-600.jpg");

        Map<String, Object> frame2 = new LinkedHashMap<String, Object>();
        frame2.put("offset", 5);
        frame2.put("url", "http://pic12.nipic.com/20110221/6727421_210944911000_2.jpg");

        Map<String, Object> frame3 = new LinkedHashMap<String, Object>();
        frame3.put("offset", 10);
        frame3.put("url", "http://rifleman-share.oss-cn-hangzhou.aliyuncs.com/test/%E6%AD%A3%E5%B8%B8/68d5883924c9e8cc88806a73bd7a8995.jpg");
        frames.addAll(Arrays.asList(frame1, frame2, frame3));

        task.put("frames", frames);
        tasks.add(task);
        /**
         * Specify the moderation scenario. The system charges you based on the moderation scenario that you specify.
         * By default, one frame is captured from the video per second. You can specify the frequency at which sequential frames are captured. The system charges you based on the number of frames captured from the video and the number of moderation scenarios for each frame.
         * For example, if 60 frames are captured from a 1-minute-long video and you want to moderate the video for both pornography and terrorist content, you are charged for moderating 60 frames for pornography and 60 frames for terrorist content.
         * In the scenes parameter, porn indicates that the server detects pornography, and terrorism indicates that the server detects terrorist content.
         */
        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);

        /**
         * You must set the connection timeout and read timeout.
         */
        videoSyncScanRequest.setConnectTimeout(3000);
        videoSyncScanRequest.setReadTimeout(10000);
        try {
            HttpResponse httpResponse = client.doAction(videoSyncScanRequest);

            if(httpResponse.isSuccess()){
                JSONObject jsonObject = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(jsonObject, true));
            }else{
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}