本文介绍了如何使用.NET SDK视频审核接口,检测视频中是否包含风险内容。

功能描述

视频审核接口支持同步检测和异步检测两种方式。
  • 同步检测只支持传递视频的截帧图片序列。关于参数的详细介绍,请参见同步检测API文档
  • 异步检测(推荐)支持对原始视频或视频的截帧图片序列进行检测。关于参数的详细介绍,请参见异步检测API文档

前提条件

已安装.NET依赖。关于安装.NET依赖的具体操作,请参见安装.NET依赖
说明 请一定按照安装.NET依赖页面中的版本安装,否则会导致调用失败。

(推荐)提交视频异步检测任务

接口 描述 支持的地域
VideoAsyncScanRequest 提交视频异步检测任务,对视频进行多个风险场景的识别,包括色情、暴恐涉政、广告 、不良场景、Logo(商标台标)识别。
  • cn-shanghai:华东2(上海)
  • cn-beijing:华北2(北京)
  • cn-shenzhen:华南1(深圳)
  • ap-southeast-1:新加坡
示例代码
  • 提交视频URL进行检测
    using System;
    using Newtonsoft.Json;
    using Aliyun.Acs.Core;
    using Aliyun.Acs.Core.Http;
    using Aliyun.Acs.Core.Profile;
    using Aliyun.Acs.Green.Model.V20180509;
    using System.Collections.Generic;
    
    namespace csharp_sdk_sample
    {
        class Program
        {
            static void Main(string[] args)
            {
                // 请替换成您的AccessKey ID、AccessKey Secret。
                IClientProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "您的AccessKey ID",
                    "您的AccessKey Secret");
                DefaultAcsClient client = new DefaultAcsClient(profile);
    
                VideoAsyncScanRequest request = new VideoAsyncScanRequest();
                request.AcceptFormat = FormatType.JSON;
                request.ContentType = FormatType.JSON;
                request.Method = MethodType.POST;
                request.Encoding = "UTF-8";
    
                Dictionary<string, object> task1 = new Dictionary<string, object>();
                task1.Add("dataId", "检测数据ID");
                task1.Add("url", "待检测视频链接地址");
    
                // scenes:检测场景,支持指定多个场景。
                // callback、seed用于回调通知,可选参数。
                Dictionary<string, object> httpBody = new Dictionary<string, object>();
                httpBody.Add("scenes", new List<string> { "porn", "terrorism" });
                httpBody.Add("bizType", "业务场景");
                httpBody.Add("callback", "回调地址");
                httpBody.Add("seed", "随机字符串");
                httpBody.Add("tasks", new List<Dictionary<string, object>> { task1 });
    
                request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
                try
                {
                    VideoAsyncScanResponse response = client.GetAcsResponse(request);
                    if (response.HttpResponse.Status != 200)
                    {
                        Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                    }
                    Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed with error info: {0}", ex.Message);
                }
            }
        }
    }
  • 提交视频直播流进行检测
    using System;
    using Newtonsoft.Json;
    using Aliyun.Acs.Core;
    using Aliyun.Acs.Core.Http;
    using Aliyun.Acs.Core.Profile;
    using Aliyun.Acs.Green.Model.V20180509;
    using System.Collections.Generic;
    
    namespace csharp_sdk_sample
    {
        class Program
        {
            static void Main(string[] args)
            {
                // 请替换成您的AccessKey ID、AccessKey Secret。
                IClientProfile profile = DefaultProfile.GetProfile(
                     "cn-shanghai",
                     "您的AccessKey ID",
                     "您的AccessKey Secret");
                DefaultAcsClient client = new DefaultAcsClient(profile);
    
                VideoAsyncScanRequest request = new VideoAsyncScanRequest();
                request.AcceptFormat = FormatType.JSON;
                request.ContentType = FormatType.JSON;
                request.Method = MethodType.POST;
                request.Encoding = "UTF-8";
    
                Dictionary<string, object> task1 = new Dictionary<string, object>();
                task1.Add("dataId", "检测数据ID");
                // url填写直播流地址。
                task1.Add("url", "待检测视频链接地址");
    
                // scenes:检测场景,支持指定多个场景。
                // callback、seed用于回调通知,可选参数。
                Dictionary<string, object> httpBody = new Dictionary<string, object>();
                httpBody.Add("scenes", new List<string> { "porn", "terrorism" });
                httpBody.Add("live", "true");
                httpBody.Add("bizType", "业务场景");
                httpBody.Add("callback", "回调地址");
                httpBody.Add("seed", "随机字符串");
                httpBody.Add("tasks", new List<Dictionary<string, object>> { task1 });
    
                request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
                try
                {
                    VideoAsyncScanResponse response = client.GetAcsResponse(request);
                    if (response.HttpResponse.Status != 200)
                    {
                        Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                    }
                    Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed with error info: {0}", ex.Message);
                }
            }
        }
    }
  • 提交视频语音进行综合检测
    using System;
    using Newtonsoft.Json;
    using Aliyun.Acs.Core;
    using Aliyun.Acs.Core.Http;
    using Aliyun.Acs.Core.Profile;
    using Aliyun.Acs.Green.Model.V20180509;
    using System.Collections.Generic;
    
    namespace csharp_sdk_sample
    {
        class Program
        {
            static void Main(string[] args)
            {
                // 请替换成您的AccessKey ID、AccessKey Secret。
                IClientProfile profile = DefaultProfile.GetProfile(
                     "cn-shanghai",
                     "您的AccessKey ID",
                     "您的AccessKey Secret");
                DefaultAcsClient client = new DefaultAcsClient(profile);
    
                VideoAsyncScanRequest request = new VideoAsyncScanRequest();
                request.AcceptFormat = FormatType.JSON;
                request.ContentType = FormatType.JSON;
                request.Method = MethodType.POST;
                request.Encoding = "UTF-8";
    
                Dictionary<string, object> task1 = new Dictionary<string, object>();
                task1.Add("dataId", "检测数据ID");
                // url填写直播流地址。
                task1.Add("url", "待检测视频链接地址");
    
                // scenes:检测场景,支持指定多个场景。
                // callback、seed用于回调通知,可选参数。
                Dictionary<string, object> httpBody = new Dictionary<string, object>();
                httpBody.Add("scenes", new List<string> { "porn", "terrorism" });
                httpBody.Add("live", "true");
                httpBody.Add("audioScenes", new List<string> { "antispam" });
                httpBody.Add("bizType", "业务场景");
                httpBody.Add("callback", "回调地址");
                httpBody.Add("seed", "随机字符串");
                httpBody.Add("tasks", new List<Dictionary<string, object>> { task1 });
    
                request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
                try
                {
                    VideoAsyncScanResponse response = client.GetAcsResponse(request);
                    if (response.HttpResponse.Status != 200)
                    {
                        Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                    }
                    Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed with error info: {0}", ex.Message);
                }
            }
        }
    }

查询视频异步检测结果

接口 描述 支持的地域
VideoAsyncScanResultsRequest 查询视频异步检测任务的结果。
说明 该方法需要轮询结果,建议使用callback的方式获取结果。
  • cn-shanghai:华东2(上海)
  • cn-beijing:华北2(北京)
  • cn-shenzhen:华南1(深圳)
  • ap-southeast-1:新加坡
示例代码
using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // 请替换成您的AccessKey ID、AccessKey Secret。
            IClientProfile profile = DefaultProfile.GetProfile(
                "cn-shanghai",
                "您的AccessKey ID",
                "您的AccessKey Secret");
            DefaultAcsClient client = new DefaultAcsClient(profile);

            VideoAsyncScanResultsRequest request = new VideoAsyncScanResultsRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            List<string> taskIdList = new List<string> { "视频异步检测任务ID" };

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(taskIdList)), "utf-8", FormatType.JSON);
            try
            {
                VideoAsyncScanResultsResponse response = client.GetAcsResponse(request);


                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}

视频截帧同步检测

接口 描述 支持的地域
VideoSyncScanRequest 提交视频同步检测任务,同步检测视频中的风险内容。
说明 同步检测只支持传递视频帧序列,不支持检测视频文件,推荐使用异步检测接口。
  • cn-shanghai:华东2(上海)
  • cn-beijing:华北2(北京)
  • cn-shenzhen:华南1(深圳)
  • ap-southeast-1:新加坡

示例代码

以下示例代码中使用帧序列方式提交待检测的视频。

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // 请替换成您的AccessKey ID、AccessKey Secret。
            IClientProfile profile = DefaultProfile.GetProfile(
                "cn-shanghai",
                "您的AccessKey ID",
                "您的AccessKey Secret");
            DefaultAcsClient client = new DefaultAcsClient(profile);

            VideoSyncScanRequest request = new VideoSyncScanRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            Dictionary<string, object> frame1 = new Dictionary<string, object>();
            frame1.Add("offset", "0");
            frame1.Add("url", "您的视频截帧链接地址1");

            Dictionary<string, object> frame2 = new Dictionary<string, object>();
            frame2.Add("offset", "5");
            frame2.Add("url", "您的视频截帧链接地址2");

            Dictionary<string, object> frame3 = new Dictionary<string, object>();
            frame3.Add("offset", "10");
            frame3.Add("url", "您的视频截帧链接地址3");

            Dictionary<string, object> task1 = new Dictionary<string, object>();
            task1.Add("dataId", "检测数据ID");
            task1.Add("frames", new List<Dictionary<string, object>> { frame1, frame2, frame3 });

            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            // scenes:检测场景,支持指定多个场景。
            httpBody.Add("scenes", new List<string> { "porn", "terrorism" });
            httpBody.Add("bizType", "业务场景");
            httpBody.Add("tasks", new List<Dictionary<string, object>> { task1 });

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
            try
            {
                VideoSyncScanResponse response = client.GetAcsResponse(request);
                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}

视频检测结果反馈

如果您认为视频检测结果与您的预期不符,可以通过视频检测结果反馈接口,对检测结果进行纠正(系统会根据您反馈的结果,将视频截帧添加到相似图片的黑名单库或者白名单库)。当您再次提交相似的内容进行检测时,以您反馈的label返回结果。

关于接口的说明,请参见检测结果反馈

接口 描述 支持的Region
VideoFeedbackRequest 提交视频检测结果的反馈,以人工反馈的检测结果纠正算法检测结果。
  • cn-shanghai:华东2(上海)
  • cn-beijing:华北2(北京)
  • cn-shenzhen:华南1(深圳)
  • ap-southeast-1:新加坡
示例代码
using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // 请替换成您的AccessKey ID、AccessKey Secret。
            IClientProfile profile = DefaultProfile.GetProfile(
                "cn-shanghai",
                "您的AccessKey ID",
                "您的AccessKey Secret");
            DefaultAcsClient client = new DefaultAcsClient(profile);

            VideoFeedbackRequest request = new VideoFeedbackRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            Dictionary<string, object> frame1 = new Dictionary<string, object>();
            frame1.Add("offset", "0");
            frame1.Add("url", "您的视频截帧链接地址1");

            Dictionary<string, object> frame2 = new Dictionary<string, object>();
            frame2.Add("offset", "0");
            frame2.Add("url", "您的视频截帧链接地址2");

            List<Dictionary<string, object>> frames = new List<Dictionary<string, object>> { frame1, frame2 };

            // scenes:检测场景,支持指定多个场景。
            // suggestion:期望的检测结果,pass:正常;block:违规。
            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("scenes", new List<string> { "porn", "terrorism" });
            httpBody.Add("suggestion", "block");
            httpBody.Add("taskId", "视频审核任务ID");
            httpBody.Add("dataId", "检测数据ID");
            httpBody.Add("url", "视频链接地址");
            httpBody.Add("frames", frames);
            httpBody.Add("note", "备注信息");

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
            try
            {
                VideoFeedbackResponse response = client.GetAcsResponse(request);


                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}