Indexing Media Files with Azure Media Indexer 2 Preview

Overview

The Azure Media Indexer 2 Preview media processor (MP) enables you to make media files and content searchable, as well as generate closed captioning tracks. Compared to the previous version of Azure Media Indexer, Azure Media Indexer 2 Preview performs faster indexing and offers broader language support. Supported languages include English, Spanish, French, German, Italian, Chinese (Mandarin, Simplified), Portuguese, Arabic, and Japanese.

The Azure Media Indexer 2 Preview MP is currently in Preview.

This topic shows how to create indexing jobs with Azure Media Indexer 2 Preview.

Note

The following considerations apply:

Indexer 2 is not supported in Azure China and Azure Government.

When indexing content, make sure to use media files that have very 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).

This topic gives details about Azure Media Indexer 2 Preview and shows how to use it with Media Services SDK for .NET

Input and output files

Input files

Audio or video files

Output files

An indexing job can generate closed caption files in the following formats:

  • SAMI
  • TTML
  • WebVTT

Closed Caption (CC) files in these formats can be used to make audio and video files accessible to people with hearing disability.

Task configuration (preset)

When creating an indexing task with Azure Media Indexer 2 Preview, you must specify a configuration preset.

The following JSON sets available parameters.

{
  "version":"1.0",
  "Features":
    [
       {
       "Options": {
            "Formats":["WebVtt","ttml"],
            "Language":"enUs",
            "Type":"RecoOptions"
       },
       "Type":"SpReco"
    }]
}

Supported languages

Azure Media Indexer 2 Preview supports speech-to-text for the following languages (when specifying the language name in the task configuration, use 4-character code in brackets as shown below):

  • English [EnUs]
  • Spanish [EsEs]
  • Chinese (Mandarin, Simplified) [ZhCn]
  • French [FrFr]
  • German [DeDe]
  • Italian [ItIt]
  • Portuguese [PtBr]
  • Arabic (Egyptian) [ArEg]
  • Japanese [JaJp]

Sample code

The following program shows how to:

  1. Create an asset and upload a media file into the asset.
  2. Creates a job with an indexing task based on a configuration file that contains the following json preset.

     {
       "version":"1.0",
       "Features":
         [
            {
            "Options": {
                 "Formats":["WebVtt","ttml"],
                 "Language":"enUs",
                 "Type":"RecoOptions"
            },
            "Type":"SpReco"
         }]
     }
    
  3. Downloads the output files.

     using System;
     using System.Configuration;
     using System.IO;
     using System.Linq;
     using Microsoft.WindowsAzure.MediaServices.Client;
     using System.Threading;
     using System.Threading.Tasks;
    
     namespace IndexContent
     {
         class Program
         {
             // Read values from the App.config file.
             private static readonly string _mediaServicesAccountName =
                 ConfigurationManager.AppSettings["MediaServicesAccountName"];
             private static readonly string _mediaServicesAccountKey =
                 ConfigurationManager.AppSettings["MediaServicesAccountKey"];
    
             // Field for service context.
             private static CloudMediaContext _context = null;
             private static MediaServicesCredentials _cachedCredentials = null;
    
             static void Main(string[] args)
             {
    
                 // Create and cache the Media Services credentials in a static class variable.
                 _cachedCredentials = new MediaServicesCredentials(
                                 _mediaServicesAccountName,
                                 _mediaServicesAccountKey);
                 // Used the cached credentials to create CloudMediaContext.
                 _context = new CloudMediaContext(_cachedCredentials);
    
                 // Run indexing job.
                 var asset = RunIndexingJob(@"C:\supportFiles\Indexer\BigBuckBunny.mp4",
                                             @"C:\supportFiles\Indexer\config.json");
    
                 // Download the job output asset.
                 DownloadAsset(asset, @"C:\supportFiles\Indexer\Output");
             }
    
             static IAsset RunIndexingJob(string inputMediaFilePath, 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 Azure Media Indexer 2 Preview.
                 string MediaProcessorName = "Azure Media Indexer 2 Preview";
    
                 var processor = GetLatestMediaProcessorByName(MediaProcessorName);
    
                 // Read configuration from the specified file.
                 string configuration = 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)
                 {
                     ErrorDetail error = job.Tasks.First().ErrorDetails.First();
                     Console.WriteLine(string.Format("Error: {0}. {1}",
                                                     error.Code,
                                                     error.Message));
                     return null;
                 }
    
                 return job.OutputMediaAssets[0];
             }
    
             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;
             }
    
             static private void StateChanged(object sender, JobStateChangedEventArgs e)
             {
                 Console.WriteLine("Job state changed event:");
                 Console.WriteLine("  Previous state: " + e.PreviousState);
                 Console.WriteLine("  Current state: " + e.CurrentState);
    
                 switch (e.CurrentState)
                 {
                     case JobState.Finished:
                         Console.WriteLine();
                         Console.WriteLine("Job is finished.");
                         Console.WriteLine();
                         break;
                     case JobState.Canceling:
                     case JobState.Queued:
                     case JobState.Scheduled:
                     case JobState.Processing:
                         Console.WriteLine("Please wait...\n");
                         break;
                     case JobState.Canceled:
                     case JobState.Error:
                         // Cast sender as a job.
                         IJob job = (IJob)sender;
                         // Display or log error details as needed.
                         // LogJobStop(job.Id);
                         break;
                     default:
                         break;
                 }
             }
         }
     }
    

Media Services learning paths

You can view Azure Media Services learning paths here:

Provide feedback

Use the User Voice forum to provide feedback and make suggestions on how to improve Azure Media Services. You can also go directly to one of the following categories:

Azure Media Services Analytics Overview

Azure Media Analytics demos