本文由簡體中文內容自動轉碼而成。阿里雲不保證此自動轉碼的準確性、完整性及時效性。本文内容請以簡體中文版本為準。

視頻審核

更新時間:2024-07-06 00:11

本文介紹了如何使用.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)
            {
                /**
                 * 常見擷取環境變數方式:
                 *     擷取RAM使用者AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
                 *     擷取RAM使用者AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
                 */
                DefaultProfile profile = DefaultProfile.GetProfile(
                        "cn-shanghai",
                        "建議從環境變數中擷取RAM使用者AccessKey ID",
                        "建議從環境變數中擷取RAM使用者AccessKey Secret");
                // 注意:此處執行個體化的client儘可能重複使用,提升檢測效能。避免重複建立串連。
                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);
                }
            }
        }
    }
  • 提交ApsaraVideo for Live流進行檢測

    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)
            {
                /**
                 * 常見擷取環境變數方式:
                 *     擷取RAM使用者AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
                 *     擷取RAM使用者AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
                 */
                DefaultProfile profile = DefaultProfile.GetProfile(
                        "cn-shanghai",
                        "建議從環境變數中擷取RAM使用者AccessKey ID",
                        "建議從環境變數中擷取RAM使用者AccessKey Secret");
                // 注意:此處執行個體化的client儘可能重複使用,提升檢測效能。避免重複建立串連。
                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)
            {
                /**
                 * 常見擷取環境變數方式:
                 *     擷取RAM使用者AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
                 *     擷取RAM使用者AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
                 */
                DefaultProfile profile = DefaultProfile.GetProfile(
                        "cn-shanghai",
                        "建議從環境變數中擷取RAM使用者AccessKey ID",
                        "建議從環境變數中擷取RAM使用者AccessKey Secret");
                // 注意:此處執行個體化的client儘可能重複使用,提升檢測效能。避免重複建立串連。
                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)
        {
            /**
             * 常見擷取環境變數方式:
             *     擷取RAM使用者AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     擷取RAM使用者AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "建議從環境變數中擷取RAM使用者AccessKey ID",
                    "建議從環境變數中擷取RAM使用者AccessKey Secret");
            // 注意:此處執行個體化的client儘可能重複使用,提升檢測效能。避免重複建立串連。
            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)
        {
            /**
             * 常見擷取環境變數方式:
             *     擷取RAM使用者AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     擷取RAM使用者AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "建議從環境變數中擷取RAM使用者AccessKey ID",
                    "建議從環境變數中擷取RAM使用者AccessKey Secret");
            // 注意:此處執行個體化的client儘可能重複使用,提升檢測效能。避免重複建立串連。
            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

介面

描述

支援的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)
        {
            /**
             * 常見擷取環境變數方式:
             *     擷取RAM使用者AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     擷取RAM使用者AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "建議從環境變數中擷取RAM使用者AccessKey ID",
                    "建議從環境變數中擷取RAM使用者AccessKey Secret");
            // 注意:此處執行個體化的client儘可能重複使用,提升檢測效能。避免重複建立串連。
            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);
            }
        }
    }
}
  • 本頁導讀 (0, M)
  • 功能描述
  • 前提條件
  • (推薦)提交視頻非同步檢測任務
  • 查詢視頻非同步檢測結果
  • 視頻截幀同步檢測
  • 視頻檢測結果反饋
文檔反饋
phone 聯絡我們

立即和Alibaba Cloud在線服務人員進行交談,獲取您想了解的產品信息以及最新折扣。

alicare alicarealicarealicare