使用 Azure 媒体内容审查器检测可能的成人和猥亵内容Use Azure Media Content Moderator to detect possible adult and racy content

Note

“Azure 媒体内容审查器” 媒体处理器将停用。The Azure Media Content Moderator media processor will be retired. 有关停用日期,请参阅此旧组件主题。For the retirement date, see the legacy components topic.

概述Overview

借助 Azure 媒体内容审查器媒体处理器 (MP),你可以对视频使用机器辅助审查。The Azure Media Content Moderator media processor (MP) enables you to use machine-assisted moderation for your videos. 例如,你可能希望检测视频中可能存在的成人和猥亵内容,以及复查由人工审查团队标记出的内容。For example, you might want to detect possible adult and racy content in videos and review the flagged content by your human moderation teams.

Azure 媒体内容审查器 MP 目前为预览版。The Azure Media Content Moderator MP is currently in Preview.

本文提供了有关 Azure 媒体内容审查器的详细信息,并展示了如何通过适用于 .NET 的媒体服务 SDK 使用它。This article gives details about Azure Media Content Moderator and shows how to use it with Media Services SDK for .NET.

内容审查器输入文件Content Moderator input files

视频文件。Video files. 目前支持以下格式:MP4、MOV 和 WMV。Currently, the following formats are supported: MP4, MOV, and WMV.

内容审查器输出文件Content Moderator output files

采用 JSON 格式的审查输出包括自动检测到的快照和关键帧。The moderated output in the JSON format includes auto-detected shots and keyframes. 关键帧将返回,并且将带有可信度分数以指明是成人或猥亵内容的可能性。The keyframes are returned with confidence scores for possible adult or racy content. 它们还包括一个布尔值标志,指明是否建议进行复查。They also include a boolean flag indicating whether a review is recommended. 复查建议标志是基于针对成人和猥亵分数的内部阈值分配的值。The review recommendation flag is assigned values based on the internal thresholds for adult and racy scores.

输出 JSON 文件中的元素Elements of the output JSON file

作业将生成一个 JSON 输出文件,其中包含有关检测到的快照以及它们是否包含成人或猥亵内容的元数据。The job produces a JSON output file that contains metadata about detected shots and keyframes and whether they contain adult or racy content.

输出 JSON 包含以下元素:The output JSON includes the following elements:

根 JSON 元素Root JSON elements

元素Element 说明Description
版本version 内容审查器的版本。The version of Content Moderator.
时间刻度timescale 视频每秒的“刻度”数。"Ticks" per second of the video.
offsetoffset 时间戳的时间偏移量。The time offset for timestamps. 在版本 1.0 的视频 API 中,此值将始终为 0。In version 1.0 of Video APIs, this value will always be 0. 此值在将来可能会更改。This value may change in the future.
帧速率framerate 视频的每秒帧数。Frames per second of the video.
widthwidth 输出视频帧的宽度,以像素为单位。The width of the output video frame, in pixels.
heightheight 输出视频帧的高度,以像素为单位。The height of the output video frame, in pixels.
totalDurationtotalDuration 输入视频的持续时间,以“时钟周期”为单位。The duration of the input video, in "ticks."
片段fragments 元数据划分成称为“片段”的不同段。The metadata is chunked up into different segments called fragments. 每个片段是一个自动检测到的快照,包含开始时间、持续时间、间隔数字和事件。Each fragment is an auto-detected shot with a start, duration, interval number, and event(s).

片段 JSON 元素Fragments JSON elements

元素Element 说明Description
startstart 第一个事件的开始时间(以“刻度”为单位)。The start time of the first event in "ticks."
durationduration 片段的长度(以“刻度”为单位)。The length of the fragment, in “ticks.”
intervalinterval 片段中每个事件条目的间隔(以“刻度”为单位)。The interval of each event entry within the fragment, in “ticks.”
eventsevents 每个事件都代表一个剪辑,每个剪辑包含在该持续时间内检测到和跟踪的关键帧。Each event represents a clip and each clip contains keyframes detected and tracked within that time duration. 它是事件的数组。It is an array of events. 外部数组代表一个时间间隔。The outer array represents one interval of time. 内部数组包含在该时间点发生的 0 个或多个事件。The inner array consists of 0 or more events that happened at that point in time.

事件 JSON 元素Events JSON elements

元素Element 说明Description
reviewRecommendedreviewRecommended truefalse,具体取决于 adultScoreracyScore 是否超出了内部阈值。true or false depending on whether the adultScore or racyScore exceed the internal thresholds.
adultScoreadultScore 可能的成人内容的可信度分数,范围为 0.00 到 0.99。Confidence score for possible adult content, on a scale of 0.00 to 0.99.
racyScoreracyScore 可能的猥亵内容的可信度分数,范围为 0.00 到 0.99。Confidence score for possible racy content, on a scale of 0.00 to 0.99.
索引index 帧的索引,处于从第一个帧索引到最后一个帧索引这一范围内。index of the frame on a scale from the first frame index to the last frame index.
timestamptimestamp 帧的位置,以“刻度”为单位。The location of the frame in "ticks."
shotIndexshotIndex 父快照的索引。The index of the parent shot.

内容审查快速入门和示例输出Content Moderation quickstart and sample output

任务配置(预设)Task configuration (preset)

在使用 Azure 媒体内容审查器创建任务时,必须指定配置预设。When creating a task with Azure Media Content Moderator, you must specify a configuration preset. 以下配置预设仅适用于内容审查。The following configuration preset is just for content moderation.

{
  "version":"2.0"
}

.NET 代码示例.NET code sample

以下 .NET 代码示例使用媒体服务 .NET SDK 运行内容审查器作业。The following .NET code sample uses the Media Services .NET SDK to run a Content Moderator job. 它采用媒体服务资产作为输入,其中包含要审查的视频。It takes a media services Asset as the input that contains the video to be moderated. 有关完整的源代码和 Visual Studio 项目,请参阅内容审查器视频快速入门See the Content Moderator video quickstart for the full source code and the Visual Studio project.

    /// <summary>
    /// Run the Content Moderator job on the designated Asset from local file or blob storage
    /// </summary>
    /// <param name="asset"></param>
    static void RunContentModeratorJob(IAsset asset)
    {
        // Grab the presets
        string configuration = File.ReadAllText(CONTENT_MODERATOR_PRESET_FILE);

        // grab instance of Azure Media Content Moderator MP
        IMediaProcessor mp = _context.MediaProcessors.GetLatestMediaProcessorByName(MEDIA_PROCESSOR);

        // create Job with Content Moderator task
        IJob job = _context.Jobs.Create(String.Format("Content Moderator {0}",
                asset.AssetFiles.First() + "_" + Guid.NewGuid()));

        ITask contentModeratorTask = job.Tasks.AddNew("Adult and racy classifier task",
                mp, configuration,
                TaskOptions.None);
        contentModeratorTask.InputAssets.Add(asset);
        contentModeratorTask.OutputAssets.AddNew("Adult and racy classifier output",
            AssetCreationOptions.None);

        job.Submit();


        // Create progress printing and querying tasks
        Task progressPrintTask = new Task(() =>
        {
            IJob jobQuery = null;
            do
            {
                var progressContext = _context;
                jobQuery = progressContext.Jobs
                .Where(j => j.Id == job.Id)
                    .First();
                    Console.WriteLine(string.Format("{0}\t{1}",
                    DateTime.Now,
                    jobQuery.State));
                    Thread.Sleep(10000);
             }
             while (jobQuery.State != JobState.Finished &&
             jobQuery.State != JobState.Error &&
             jobQuery.State != JobState.Canceled);
        });
        progressPrintTask.Start();

        Task progressJobTask = job.GetExecutionProgressTask(
        CancellationToken.None);
        progressJobTask.Wait();

        // If job state is Error, the event handling 
        // method for job progress should log errors.  Here we check 
        // for error state and exit if needed.
        if (job.State == JobState.Error)
        {
            ErrorDetail error = job.Tasks.First().ErrorDetails.First();
            Console.WriteLine(string.Format("Error: {0}. {1}",
            error.Code,
            error.Message));
        }

        DownloadAsset(job.OutputMediaAssets.First(), OUTPUT_FOLDER);
    }

有关完整的源代码和 Visual Studio 项目,请查看内容审查器视频快速入门For the full source code and the Visual Studio project, check out the Content Moderator video quickstart.

JSON 输出JSON output

以下内容审查器 JSON 输出示例已被截断。The following example of a Content Moderator JSON output was truncated.

Note

以秒数表示的关键帧位置 = 时间戳/时间刻度Location of a keyframe in seconds = timestamp/timescale

    {
    "version": 2,
    "timescale": 90000,
    "offset": 0,
    "framerate": 50,
    "width": 1280,
    "height": 720,
    "totalDuration": 18696321,
    "fragments": [
    {
      "start": 0,
      "duration": 18000
    },
    {
      "start": 18000,
      "duration": 3600,
      "interval": 3600,
      "events": [
        [
          {
            "reviewRecommended": false,
            "adultScore": 0.00001,
            "racyScore": 0.03077,
            "index": 5,
            "timestamp": 18000,
            "shotIndex": 0
          }
        ]
      ]
    },
    {
      "start": 18386372,
      "duration": 119149,
      "interval": 119149,
      "events": [
        [
          {
            "reviewRecommended": true,
            "adultScore": 0.00000,
            "racyScore": 0.91902,
            "index": 5085,
            "timestamp": 18386372,
            "shotIndex": 62
          }
        ]
      ]
    }
    ]
    }

媒体服务学习路径Media Services learning paths

媒体服务 v3(最新版本)Media Services v3 (latest)

查看最新版本的 Azure 媒体服务!Check out the latest version of Azure Media Services!

媒体服务 v2(旧版)Media Services v2 (legacy)

Azure 媒体服务分析概述Azure Media Services Analytics Overview

后续步骤Next steps

视频审查快速入门获取完整的源代码和 Visual Studio 项目。Get the full source code and the Visual Studio project from the video moderation quickstart.