使用 Azure Media Indexer 为媒体文件编制索引Indexing Media Files with Azure Media Indexer

备注

Azure Media Indexer 媒体处理器将停用。The Azure Media Indexer media processor will be retired. 有关停用日期,请参阅此旧组件主题。For the retirement dates, see this legacy components topic.

使用 Azure Media Indexer,可以使媒体文件内容可供搜索,并为隐藏的字幕和关键字生成全文本脚本。Azure Media Indexer enables you to make content of your media files searchable and to generate a full-text transcript for closed captioning and keywords. 可以只处理一个媒体文件,也可以一次处理多个媒体文件。You can process one media file or multiple media files in a batch.

在编制内容的索引时,请确保使用语音清晰的媒体文件(没有背景音乐、噪音、特效音或麦克风电流嘶嘶声)。When indexing content, make sure to use media files that have clear speech (without background music, noise, effects, or microphone hiss). 适当内容的某些示例包括:录制的会议、讲座或演示内容。Some examples of appropriate content are: recorded meetings, lectures, or presentations. 以下内容可能不适合用于编制索引:电影、电视剧、混合了音频和声音特效的任何内容、带有背景噪音(电流嘶嘶声)的不当录制内容。The following content might not be suitable for indexing: movies, TV shows, anything with mixed audio and sound effects, poorly recorded content with background noise (hiss).

索引作业可生成以下输出:An indexing job can generate the following outputs:

  • 下列格式的隐藏式字幕文件:TTMLWebVTTClosed caption files in the following formats: TTML, and WebVTT.

    隐藏字幕文件包含名为 Recognizability 的标记,该标记可以根据源视频中的语音辨别度对索引作业评分。Closed caption files include a tag called Recognizability, which scores an indexing job based on how recognizable the speech in the source video is. 用户可以使用 Recognizability 的值筛选可用的输出文件。You can use the value of Recognizability to screen output files for usability. 如果分数较低,则表示索引结果由于音频质量问题而不佳。A low score would mean poor indexing results due to audio quality.

  • 关键字文件 (XML)。Keyword file (XML).

本文介绍如何创建索引作业,以便为资产编制索引以及为多个文件编制索引This article shows how to create indexing jobs to Index an asset and Index multiple files.

使用配置和清单文件执行索引编制任务Using configuration and manifest files for indexing tasks

可以使用任务配置为索引编制任务指定更多详细信息。You can specify more details for your indexing tasks by using a task configuration. 例如,可以指定用于媒体文件的元数据。For example, you can specify which metadata to use for your media file. 此元数据可供语言引擎用于扩充其词汇,并大幅提高语音识别的准确性。This metadata is used by the language engine to expand its vocabulary, and greatly improves the speech recognition accuracy. 还可以指定所需的输出文件。You are also able to specify your desired output files.

还可以使用清单文件一次处理多个媒体文件。You can also process multiple media files at once by using a manifest file.

有关详细信息,请参阅 Azure Media Indexer 的任务预设For more information, see Task Preset for Azure Media Indexer.

为资产编制索引Index an asset

以下方法将媒体文件上传为资产,并创建为资产编制索引的作业。The following method uploads a media file as an asset and creates a job to index the asset.

如果未指定配置文件,则将使用所有默认设置为媒体文件编制索引。If no configuration file is specified, the media file is indexed with all default settings.

    static bool RunIndexingJob(string inputMediaFilePath, string outputFolder, string configurationFile = "")
    {
        // Create an asset and upload the input media file to storage.
        IAsset asset = CreateAssetAndUploadSingleFile(inputMediaFilePath,
            "My Indexing Input Asset",
            AssetCreationOptions.None);

        // Declare a new job.
        IJob job = _context.Jobs.Create("My Indexing Job");

        // Get a reference to the Azure Media Indexer.
        string MediaProcessorName = "Azure Media Indexer";
        IMediaProcessor processor = GetLatestMediaProcessorByName(MediaProcessorName);

        // Read configuration from file if specified.
        string configuration = string.IsNullOrEmpty(configurationFile) ? "" : File.ReadAllText(configurationFile);

        // Create a task with the encoding details, using a string preset.
        ITask task = job.Tasks.AddNew("My Indexing Task",
            processor,
            configuration,
            TaskOptions.None);

        // Specify the input asset to be indexed.
        task.InputAssets.Add(asset);

        // Add an output asset to contain the results of the job.
        task.OutputAssets.AddNew("My Indexing Output Asset", AssetCreationOptions.None);

        // Use the following event handler to check job progress.  
        job.StateChanged += new EventHandler<JobStateChangedEventArgs>(StateChanged);

        // Launch the job.
        job.Submit();

        // Check job execution and wait for job to finish.
        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)
        {
            Console.WriteLine("Exiting method due to job error.");
            return false;
        }

        // Download the job outputs.
        DownloadAsset(task.OutputAssets.First(), outputFolder);

        return true;
    }

    static IAsset CreateAssetAndUploadSingleFile(string filePath, string assetName, AssetCreationOptions options)
    {
        IAsset asset = _context.Assets.Create(assetName, options);

        var assetFile = asset.AssetFiles.Create(Path.GetFileName(filePath));
        assetFile.Upload(filePath);

        return asset;
    }

    static void DownloadAsset(IAsset asset, string outputDirectory)
    {
        foreach (IAssetFile file in asset.AssetFiles)
        {
            file.Download(Path.Combine(outputDirectory, file.Name));
        }
    }

    static IMediaProcessor GetLatestMediaProcessorByName(string mediaProcessorName)
    {
        var processor = _context.MediaProcessors
        .Where(p => p.Name == mediaProcessorName)
        .ToList()
        .OrderBy(p => new Version(p.Version))
        .LastOrDefault();

        if (processor == null)
            throw new ArgumentException(string.Format("Unknown media processor",
                                                       mediaProcessorName));

        return processor;
    }  

输出文件Output files

默认情况下,索引作业生成以下输出文件。By default, an indexing job generates the following output files. 这些文件将存储在第一个输出资产中。The files are stored in the first output asset.

如果有多个输入媒体文件,索引器会为名为“JobResult.txt”的作业输出生成清单文件。When there is more than one input media file, Indexer generates a manifest file for the job outputs, named ‘JobResult.txt’. 对于每个输入媒体文件,生成的 TTML、WebVTT 和关键字文件将依序编号,并使用“"Alias.”来命名For each input media file, the resulting TTML, WebVTT, and keyword files are sequentially numbered and named using the "Alias."

文件名File name 说明Description
InputFileName.ttmlInputFileName.ttml
InputFileName.vttInputFileName.vtt
采用 TTML 和 WebVTT 格式的隐藏式字幕 (CC) 文件。Closed Caption (CC) files in TTML and WebVTT formats.

这些文件可用于使听力障碍用户能够访问音频和视频文件。They can be used to make audio and video files accessible to people with hearing disability.

隐藏式字幕文件包含名为 Recognizability 的标记,该标记可以根据源视频中的语音辨别度对索引作业评分Closed Caption files include a tag called Recognizability which scores an indexing job based on how recognizable the speech in the source video is. 可使用 Recognizability 的值筛选可用的输出文件You can use the value of Recognizability to screen output files for usability. 如果分数较低,则表示索引结果由于音频质量问题而不佳。A low score would mean poor indexing results due to audio quality.
InputFileName.kw.xml
InputFileName.info
InputFileName.kw.xml
InputFileName.info
关键字和信息文件。Keyword and info files.

关键字文件是 XML 文件,其中包含从语音内容中提取的关键字,以及频率和偏移量信息。Keyword file is an XML file that contains keywords extracted from the speech content, with frequency and offset information.

信息文件是一种纯文本文件,其中包含有关每个已识别术语的详细信息。Info file is a plain-text file that contains granular information about each term recognized. 第一行很特别,包含 Recognizability 评分。The first line is special and contains the Recognizability score. 后续每一行是使用制表符分隔的以下数据的列表:开始时间、结束时间、单词/短语、置信度。Each subsequent line is a tab-separated list of the following data: start time, end time, word/phrase, confidence. 时间以秒为单位,置信度为数字 0-1。The times are given in seconds and the confidence is given as a number from 0-1.

示例行:“1.20 1.45 word 0.67”Example line: "1.20 1.45 word 0.67"

这些文件可用于各种目的,如执行语音分析,公开给必应、Google 或 Microsoft SharePoint 等搜索引擎以使媒体文件更容易被发现,甚至用于传送更具相关性的广告。These files can be used for a number of purposes, such as, to perform speech analytics, or exposed to search engines such as Bing, Google or Microsoft SharePoint to make the media files more discoverable, or even used to deliver more relevant ads.
JobResult.txtJobResult.txt 输出清单,仅当为多个文件编制索引时才提供,包含以下信息:Output manifest, present only when indexing multiple files, containing the following information:

InputFileInputFile别名AliasMediaLengthMediaLength错误Error
a.mp4a.mp4Media_1Media_130030000
b.mp4b.mp4Media_2Media_20030003000
c.mp4c.mp4Media_3Media_360060000

如果没有为所有输入媒体文件成功编制索引,索引编制作业会失败,错误代码为 4000。If not all input media files are indexed successfully, the indexing job fails with error code 4000. 有关详细信息,请参阅 错误代码For more information, see Error codes.

为多个文件编制索引Index multiple files

以下方法将多个媒体文件上传为资产,并创建一次性为所有这些文件编制索引的作业。The following method uploads multiple media files as an asset, and creates a job to index all these files in a batch.

创建具有“.lst”扩展名的清单文件,并将其上传到资产。A manifest file with the ".lst" extension is created and uploading into the asset. 该清单文件包含所有资产文件的列表。The manifest file contains the list of all the asset files. 有关详细信息,请参阅 Azure Media Indexer 的任务预设For more information, see Task Preset for Azure Media Indexer.

    static bool RunBatchIndexingJob(string[] inputMediaFiles, string outputFolder)
    {
        // Create an asset and upload to storage.
        IAsset asset = CreateAssetAndUploadMultipleFiles(inputMediaFiles,
            "My Indexing Input Asset - Batch Mode",
            AssetCreationOptions.None);

        // Create a manifest file that contains all the asset file names and upload to storage.
        string manifestFile = "input.lst";            
        File.WriteAllLines(manifestFile, asset.AssetFiles.Select(f => f.Name).ToArray());
        var assetFile = asset.AssetFiles.Create(Path.GetFileName(manifestFile));
        assetFile.Upload(manifestFile);

        // Declare a new job.
        IJob job = _context.Jobs.Create("My Indexing Job - Batch Mode");

        // Get a reference to the Azure Media Indexer.
        string MediaProcessorName = "Azure Media Indexer";
        IMediaProcessor processor = GetLatestMediaProcessorByName(MediaProcessorName);

        // Read configuration.
        string configuration = File.ReadAllText("batch.config");

        // Create a task with the encoding details, using a string preset.
        ITask task = job.Tasks.AddNew("My Indexing Task - Batch Mode",
            processor,
            configuration,
            TaskOptions.None);

        // Specify the input asset to be indexed.
        task.InputAssets.Add(asset);

        // Add an output asset to contain the results of the job.
        task.OutputAssets.AddNew("My Indexing Output Asset - Batch Mode", AssetCreationOptions.None);

        // Use the following event handler to check job progress.  
        job.StateChanged += new EventHandler<JobStateChangedEventArgs>(StateChanged);

        // Launch the job.
        job.Submit();

        // Check job execution and wait for job to finish.
        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)
        {
            Console.WriteLine("Exiting method due to job error.");
            return false;
        }

        // Download the job outputs.
        DownloadAsset(task.OutputAssets.First(), outputFolder);

        return true;
    }

    private static IAsset CreateAssetAndUploadMultipleFiles(string[] filePaths, string assetName, AssetCreationOptions options)
    {
        IAsset asset = _context.Assets.Create(assetName, options);

        foreach (string filePath in filePaths)
        {
            var assetFile = asset.AssetFiles.Create(Path.GetFileName(filePath));
            assetFile.Upload(filePath);
        }

        return asset;
    }

部分成功的作业Partially Succeeded Job

如果没有为所有输入媒体文件成功编制索引,索引编制作业会失败,错误代码为 4000。If not all input media files are indexed successfully, the indexing job will fail with error code 4000. 有关详细信息,请参阅 错误代码For more information, see Error codes.

生成相同的输出(与成功的作业一样)。The same outputs (as succeeded jobs) are generated. 可以参考输出清单文件,以根据“错误”列的值查明哪些输入文件失败。You can refer to the output manifest file to find out which input files are failed, according to the Error column values. 对于失败的输入文件,不会生成相应的 TTML、WebVTT 和关键字文件。For input files that failed, the resulting TTML, WebVTT, and keyword files will NOT be generated.

Azure Media Indexer 的任务预设Task Preset for Azure Media Indexer

可以通过连同任务一起提供可选任务预设,来自定义 Azure Media Indexer 的处理操作。The processing from Azure Media Indexer can be customized by providing an optional task preset alongside the task. 下面描述了此配置 xml 文件的格式。The following describes the format of this configuration xml.

名称Name 必需Require 说明Description
inputinput falsefalse 要编制索引的资产文件。Asset file(s) that you want to index.

Azure Media Indexer 支持以下格式的媒体文件:MP4、WMV、MP3、M4A、WMA、AAC、WAV。Azure Media Indexer supports the following media file formats: MP4, WMV, MP3, M4A, WMA, AAC, WAV.

可以在 input 元素的“名称”或“列表”属性中指定文件名(如下所示)。如果不指定要编制索引的文件,则选择主文件 。You can specify the file name (s) in the name or list attribute of the input element (as shown below).If you do not specify which asset file to index, the primary file is picked. 如果未设置主资产文件,则为输入资产中的第一个文件编制索引。If no primary asset file is set, the first file in the input asset is indexed.

若要显式指定资产文件名,请执行:To explicitly specify the asset file name, do:
<input name="TestFile.wmv">

还可以一次为多个资产文件编制索引(最多 10 个文件)。You can also index multiple asset files at once (up to 10 files). 为此,请按以下步骤操作:To do this:

  1. 创建一个文本文件(清单文件),并为其指定扩展名 .lst。Create a text file (manifest file) and give it an .lst extension.

  2. 将输入资产中所有资产文件名的列表添加到此清单文件。Add a list of all the asset file names in your input asset to this manifest file.

  3. 将该清单文件添加(上传)到资产。Add (upload) the manifest file to the asset.

  4. 在输入的列表属性中指定清单文件的名称。Specify the name of the manifest file in the input’s list attribute.
    <input list="input.lst">



注意:如果在清单文件中添加了 10 个以上的文件,则索引作业会失败并显示 2006 错误代码。Note: If you add more than 10 files to the manifest file, the indexing job will fail with the 2006 error code.
metadatametadata falsefalse 用于词汇自适应的指定资产文件的元数据。Metadata for the specified asset file(s) used for Vocabulary Adaptation. 在准备索引器以使其能够识别非标准词汇(例如专有名词)时,该元素非常有用。Useful to prepare Indexer to recognize non-standard vocabulary words such as proper nouns.
<metadata key="..." value="..."/>

可以提供预定义You can supply values for predefined keys. 当前支持以下键:Currently the following keys are supported:

“title”和“description”- 用于词汇适应,以微调作业的语言模型及改进语音辨识准确度。“title” and “description” - used for vocabulary adaptation to tweak the language model for your job and improve speech recognition accuracy. 值将植入 Internet 搜索以查找上下文相关的文本文档,并在执行索引任务期间使用内容来扩大内部字典。The values seed Internet searches to find contextually relevant text documents, using the contents to augment the internal dictionary for the duration of your Indexing task.
<metadata key="title" value="[Title of the media file]" />
<metadata key="description" value="[Description of the media file] />"
功能features

在版本 1.2 中添加。Added in version 1.2. 目前,唯一支持的功能是语音识别(“ASR”)。Currently, the only supported feature is speech recognition ("ASR").
falsefalse 语音识别功能具有以下设置键:The Speech Recognition feature has the following settings keys:

Key

说明Description

示例值Example value

语言Language

要在多媒体文件中识别的自然语言。The natural language to be recognized in the multimedia file.

英语、西班牙语English, Spanish

CaptionFormatsCaptionFormats

以分号分隔的所需输出字幕格式的列表(如果有)a semicolon-separated list of the desired output caption formats (if any)

ttml;webvttttml;webvtt

True; FalseTrue; False

GenerateKeywordsGenerateKeywords

布尔标志,指定是否需要关键字 XML 文件。A boolean flag specifying whether or not a keyword XML file is required.

True; False。True; False.

ForceFullCaptionForceFullCaption

布尔型标志,指定是否强制完整字幕(不考虑可信度)。A boolean flag specifying whether or not to force full captions (regardless of confidence level).

默认值为 false,在此情况下,将忽略最终字幕输出中可信度小于 50% 的单词和短语并将其替换为省略号(“...”)。Default is false, in which case words and phrases which have a less than 50% confidence level are omitted from the final caption outputs and replaced by ellipses ("..."). 省略号可用于字幕质量控制和审核。The ellipses are useful for caption quality control and auditing.

True; False。True; False.

错误代码Error codes

如果发生错误,Azure Media Indexer 应返回以下错误代码之一:In the case of an error, Azure Media Indexer should report back one of the following error codes:

代码Code 名称Name 可能的原因Possible Reasons
20002000 配置无效Invalid configuration 配置无效Invalid configuration
20012001 输入资产无效Invalid input assets 输入资产缺失或资产为空。Missing input assets or empty asset.
20022002 清单无效Invalid manifest 清单为空或清单包含无效项目。Manifest is empty or manifest contains invalid items.
20032003 无法下载媒体文件Failed to download media file 清单文件中的 URL 无效。Invalid URL in manifest file.
20042004 协议不受支持Unsupported protocol 不支持媒体 URL 的协议。Protocol of media URL is not supported.
20052005 文件类型不受支持Unsupported file type 不支持输入媒体文件类型。Input media file type is not supported.
20062006 输入文件太多Too many input files 输入清单中的文件超过 10 个。There are more than 10 files in the input manifest.
30003000 无法解码媒体文件Failed to decode media file 媒体编解码器不受支持,Unsupported media codec
or
受损的媒体文件Corrupted media file
or
输入媒体中没有音频流。No audio stream in input media.
40004000 分批编制索引部分成功Batch indexing partially succeeded 一些输入媒体文件无法编制索引。Some of the input media files are failed to be indexed. 有关详细信息,请参阅 输出文件For more information, see Output files.
其他other 内部错误Internal errors 请联系支持团队。Please contact support team. indexer@microsoft.comindexer@microsoft.com

支持的语言Supported Languages

当前支持英语和西班牙语。Currently, the English and Spanish languages are supported.

媒体服务学习路径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 Media Services Analytics Overview(Azure 媒体服务分析概述)Azure Media Services Analytics Overview