使用 Azure Media Indexer 編輯媒體檔案索引Indexing Media Files with Azure Media Indexer

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:

  • 下列格式的隱藏式輔助字幕檔案:SAMITTMLWebVTTClosed caption files in the following formats: SAMI, 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).
  • 與 SQL Server 搭配使用的音訊編製索引 blob 檔案 (AIB)。Audio indexing blob file (AIB) for use with SQL server.

    如需詳細資訊,請參閱 搭配 Azure Media Indexer 和 SQL Server 使用 AIB 檔案For more information, see Using AIB Files with Azure Media Indexer and SQL Server.

本文示範如何建立索引作業來建立資產的索引建立多個檔案的索引This article shows how to create indexing jobs to Index an asset and Index multiple files.

如需最新的 Azure Media Indexer 更新,請參閱 媒體服務部落格For the latest Azure Media Indexer updates, see Media Services blogs.

針對索引工作使用組態和資訊清單檔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’. 針對每個輸入媒體檔案,系統會把所產生的 AIB、SAMI、TTML、WebVTT 及關鍵字檔案循序編號,並使用「別名」來命名。For each input media file, the resulting AIB, SAMI, TTML, WebVTT, and keyword files, are sequentially numbered and named using the "Alias."

檔案名稱File name 說明Description
InputFileName.aibInputFileName.aib 音訊索引 blob 檔案。Audio indexing blob file.

音訊索引 Blob (AIB) 檔案是二進位檔案,可以使用全文檢索搜尋在 Microsoft SQL Server 中搜尋。Audio Indexing Blob (AIB) file is a binary file that can be searched in Microsoft SQL server using full text search. AIB 檔比簡單的字幕檔案強大,因為它包含每個字的替代字,允許更豐富的搜尋經驗。The AIB file is more powerful than the simple caption files, because it contains alternatives for each word, allowing a much richer search experience.

它需要在執行 Microsoft SQL 2008 或更新版本的電腦上安裝 Indexer SQL 附加元件。It requires the installation of the Indexer SQL add-on on a machine running Microsoft SQL server 2008 or later. 使用 Microsoft SQL Server 全文檢索搜尋來搜尋 AIB 可以比搜尋 WAMI 產生之隱藏式字幕檔案提供更正確的搜尋結果。Searching the AIB using Microsoft SQL server full text search provides more accurate search results than searching the closed caption files generated by WAMI. 這是因為 AIB 包含發音類似的替代字,而隱藏式字幕檔案則包含音訊每一節的最高信賴字。This is because the AIB contains word alternatives that sound similar whereas the closed caption files contain the highest confidence word for each segment of the audio. 如果搜尋說的話重要性最高,則建議一起使用 AIB 和 Microsoft SQL Server。If searching for spoken words is of upmost importance, then it is recommended to use the AIB In conjunction with Microsoft SQL Server.

若要下載附加元件,請按一下 [Azure 媒體索引器 SQL 附加元件]。To download the add-on, click Azure Media Indexer SQL Add-on.

也可以利用其他搜尋引擎,例如 Apache Lucene/Solr,只根據隱藏式字幕和關鍵字 XML 檔案編製視訊的索引,但這會導致搜尋結果較不正確。It is also possible to utilize other search engines such as Apache Lucene/Solr to simply index the video based on the closed caption and keyword XML files, but this will result in less accurate search results.
InputFileName.smiInputFileName.smi
InputFileName.ttmlInputFileName.ttml
InputFileName.vttInputFileName.vtt
SAMI、TTML 和 WebVTT 格式的隱藏式輔助字幕 (CC) 檔案。Closed Caption (CC) files in SAMI, 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. 第一行是特殊行並包含可辨識分數。The first line is special and contains the Recognizability score. 後續每一行皆是下列資料的清單 (以 tab 鍵分隔):開始時間、結束時間、文字/片語、信賴值。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"

這些檔案的用途眾多,例如執行語音分析,或是公開到搜尋引擎 (例如 Bing、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:

InputFileInputFileAliasAliasMediaLengthMediaLengthErrorError
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. 您可以參閱輸出資訊清單檔,根據 Error 欄位值找出哪些輸入檔案失敗。You can refer to the output manifest file to find out which input files are failed, according to the Error column values. 針對失敗的輸入檔案,將不會產生結果的 AIB、SAMI、TTML、WebVTT 和關鍵字檔案。For input files that failed, the resulting AIB, SAMI, TTML, WebVTT and keyword files will NOT be generated.

Azure 媒體索引器的工作預設Task Preset for Azure Media Indexer

在工作旁邊提供選擇性工作預設,即可自訂從 Azure 媒體索引器處理。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 媒體索引器支援下列媒體檔案格式︰MP4、WMV、MP3、M4A、WMA、AAC、WAV。Azure Media Indexer supports the following media file formats: MP4, WMV, MP3, M4A, WMA, AAC, WAV.

您可以在 input 元素的 namelist 屬性中指定檔案名稱 (如下所示)。如果您未指定要編制索引的資產檔案,則會選擇主要檔案。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) thanifest file to the asset.

  4. 在輸入的 list 屬性中指定資訊清單檔的名稱。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. 適合用來準備 Indexer 以辨識非標準詞彙文字,例如專有名詞。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. 值會植入網際網路搜尋來尋找內容相關的文字文件,並使用內容來加強索引工作期間的內部字典。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] />"
featuresfeatures

在 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:

KeyKey

說明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;sami;webvttttml;sami;webvtt

GenerateAIBGenerateAIB

布林值旗標,用來指定是否需要 AIB 檔案 (適用於 SQL Server 和客戶索引器 IFilter)。A boolean flag specifying whether or not an AIB file is required (for use with SQL Server and the customer Indexer IFilter). 如需詳細資訊,請參閱 搭配 Azure Media Indexer 和 SQL Server 使用 AIB 檔案For more information, see Using AIB Files with Azure Media Indexer and SQL Server.

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 媒體索引器應回報下列其中一個錯誤碼: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. 如需詳細資訊,請參閱 v1.2 版部落格文章For more information, see the v1.2 release blog post.

媒體服務學習路徑Media Services learning paths

請參閱 Azure 媒體服務的最新版本:Azure 媒體服務 v3Check out the latest version of Azure Media Services: Azure Media Services v3.

您可以從下列主題著手:You can start with the following topics:

提供意見反應Provide feedback

利用 使用者心聲 論壇來提供意見並提出如何改善 Azure 媒體服務的建議。Use the User Voice forum to provide feedback and make suggestions on how to improve Azure Media Services. 您也可直接前往下列類別之一:You also can go directly to one of the following categories:

Azure 媒體服務分析概觀Azure Media Services Analytics Overview

搭配 Azure Media Indexer 和 SQL Server 使用 AIB 檔案Using AIB Files with Azure Media Indexer and SQL Server

使用 Azure Media Indexer 2 Preview 編製媒體檔案索引Indexing Media Files with Azure Media Indexer 2 Preview