Media Mapping
This article discusses the media mapping phase of encoding. You can find an overview of the entire encoding process in the Job Processing article.
To decide which input files represent which streams, the Encoding Service uses the settings in the MediaMappings section. There are three layers of settings which enable more and more focused filtering of the input files.
First, regular expressions can be used to filter the files which represent the video/audio/subtitle/caption streams.
{
"VideoStreamExpression": "^video.(mp4|avi|mov|mkv|mxf)$",
"AudioFileLanguageExpression": "^audio-([a-zA-Z0-9\\-]+).mp3$",
"SubtitleFileLanguageExpression": "^subtitle-([a-zA-Z0-9\\-]+).(vtt|ttml|srt)$",
"CaptionFileLanguageExpression": "^caption-([a-zA-Z0-9\\-]+).(vtt|ttml|srt)$",
}
Files not matched by any of the provided regular expressions will not be used
at all. Only a single file is expected with a video stream. All the other
streams can be specified separately for every language. Use a regular
expression group to match the language - the first matched group will be
treated as the language code. For example, the file audio-DEU.mp3
will be
interpreted as an audio track for the language "DEU" (German).
See Languages in the Axinom Encoding Overview article for details on how the Encoding Service handles languages.
Second, if the file names do not clearly indicate a language, more generic patterns can be used to match all audio/subtitles/captions files and then a specific mapping can be used to map a file to a language, e.g.:
{
"AudioStreams": [
{
"Language": "en",
"FileNameExpression": "audio-en.mp3"
},
{
"Language": "fr",
"FileNameExpression": "audio-fr.mp3"
}
]
}
Finally, the list of languages to be used can be further limited:
{
"AudioLanguages": ["fr"]
}
Even though two audio streams were found - English and French, only the one in French (audio-fr.mp3) will be used for encoding.
Specifying the Audio Tracks in the Video File
With some video files, you might need to specify which audio tracks are for which channels, what the audio track languages are, and so on.
For example, let’s consider an MXF file where we have:
- (Track 0 for the video).
- Tracks 1-2 for stereo audio.
- Tracks 3-8 for 5.1 audio.
- Tracks 9-10 for descriptive audio in stereo.
Where all audio tracks are mono audio, representing one audio channel.
In this case we need to manually specify the audio tracks in the video file. To do this, we use the following API:
{
"MediaMappings" : {
...
"AudioMappings": {
"VideoStreamAudioTracks": [
{
"TrackIndices": [1,2], // Audio track indices in the input (can be a single index)
"Language": "en" // Language of the audio tracks
},
{
"TrackIndices": [3, 4, 5, 6, 7, 8],
"Language": "en"
},
{
"TrackIndices": [9, 10],
"Language": "en"
}
]
},
...
}
}
In this example the output will have three audio streams and they will have the characteristics specified in the request. The audio in the MXF file is taken from the indices specified in the request and each "group" will be joined into one track.
You can also use this API simply for setting the language for certain audio tracks, or for omitting them altogether, in the video file.