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

Background information

Content Moderation SDK for Java supports both synchronous and asynchronous video moderation.

Moderation method Moderation object Method for obtaining moderation results
Submit synchronous video moderation tasks.

VideoSyncScanRequest

You can submit only a sequence of frames that are captured from a video for video moderation. You can obtain moderation results in real time.
Recommended: Submit asynchronous video moderation tasks.

VideoAsyncScanRequest

You can submit the URL of an online video, the URL of an on-premises video, a binary video stream, or a sequence of frames that are captured from a video for video moderation. You can use one of the following methods to obtain moderation results:
  • When you submit asynchronous video moderation tasks, specify the callback URL by setting the callback parameter. After the tasks are processed, Content Moderation sends the moderation results to the specified callback URL.
  • After you submit asynchronous video moderation tasks, you can call the VideoAsyncScanResultsRequest operation to poll the moderation results.

Before you begin

Before you call operations, make the following preparations:
  • Create an AccessKey pair for your Alibaba Cloud account. For more information, see Create an AccessKey pair.
  • Install Java dependencies. For more information, see Installation.
  • Optional:Download and import the Extension.Uploader utility class into your project if you submit an on-premises image or a binary image stream for image moderation.

Recommended: Submit asynchronous video moderation tasks

Operation Description Supported region
VideoAsyncScanRequest Sends asynchronous requests to moderate videos for risky content in 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 (Singapore)
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.*;
    
    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", "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 is accessible from the Internet.");
    
            tasks.add(task);
            /**
             * Specify the moderation scenario. The system charges you based on the moderation scenario that you specify. 
             * By default, a 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 that are captured from the video and the moderation scenarios for each frame. 
             * For example, if 60 frames are captured from a 1-minute 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. 
             */
            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);
    
            /**
             * Specify 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 an on-premises 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", "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 an on-premises video, use the following code snippet to generate a URL based on the storage path of the video. Then, submit the generated URL of the video to the server. 
             */
            String url = null;
            ClientUploader uploader = ClientUploader.getVideoClientUploader(profile, false);
            try{
                url = uploader.uploadFile("The absolute path of the on-premises video");
            }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);
    
            tasks.add(task);
            /**
             * Specify the moderation scenario. The system charges you based on the moderation scenario that you specify. 
             * By default, a 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 that are captured from the video and the moderation scenarios for each frame. 
             * For example, if 60 frames are captured from a 1-minute 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. 
             */
            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);
    
            /**
             * Specify 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", "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 an on-premises video, use the following code snippet to generate a URL based on the storage path of the video. Then, submit the generated URL of the video to the server. 
             */
            ClientUploader uploader = ClientUploader.getVideoClientUploader(profile, false);
            byte[] videoBytes = null;
            String url = null;
            try{
                // Read and convert an on-premises 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.mp4"));
                // 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, a 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 that are captured from the video and the moderation scenarios for each frame. 
             * For example, if 60 frames are captured from a 1-minute 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. 
             */
            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);
    
            /**
             * Specify 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", "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, a 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 that are captured from the video and the moderation scenarios for each frame. 
             * For example, if 60 frames are captured from a 1-minute 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. 
             */
            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);
    
            /**
             * Specify 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", "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, a 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 that are captured from the video and the moderation scenarios for each frame. 
             * For example, if 60 frames are captured from a 1-minute 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. 
             */
            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, set the audioScenes parameter to antispam. 
             * The expense of 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);
    
            /**
             * Specify 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 asynchronous video moderation results

Operation Description Supported region
VideoAsyncScanResultsRequest Queries asynchronous video moderation results.
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 (Singapore)
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.*;

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", "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 ID of the asynchronous video moderation task that you want to query. Save the task ID that is returned after you submit a task. 
        taskList.add("vi3pnWxOlikyx6KJNtY7Naza-1pZ$MN");

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

        /**
         * Specify 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 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 (Singapore)
Sample code
Note In this example, a sequence of frames that are captured from a video is to be moderated.
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", "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, a 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 that are captured from the video and the moderation scenarios for each frame. 
         * For example, if 60 frames are captured from a 1-minute 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. 
         */
        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);

        /**
         * Specify 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();
        }
    }
}