You can attach external audio files to a video source using MFile in MPlatform SDK or MFReader in MFormats SDK. You can select tracks from each external file, choose a starting position, and repeat external audio while the main source continues playing.
External-audio properties
The table covers file-based external-audio configuration on MFile and MFReader. All entries are configurable properties, supplied as strings; the value column describes how each string is interpreted. Use the MPlatform column with PropsSet on MFile and the MFormats column with PropsSet on MFReader. In the properties string passed to FileNameSet or ReaderOpen, use the names without the file:: prefix.
For indexed properties, replace N with a positive integer: 1 for the second external file, 2 for the third, and so on. The first file uses the unsuffixed name.
| MFormats property | MPlatform property | Value type / units | Meaning and scope |
|---|---|---|---|
external_audio |
file::external_audio |
String: file path | Attaches the first external audio file. |
external_audio.N |
file::external_audio.N |
String: file path | Attaches an additional external audio file. Configure consecutive file numbers without leaving an empty entry. |
external_audio_track |
file::external_audio_track |
Zero-based integer index or comma-separated index list | Selects audio tracks within the first external file. 0 selects its first audio track; 1 selects its second; 0,1 selects both. The default selection is 0. Use -1 to disable audio from this external file. |
external_audio_track.N |
file::external_audio_track.N |
Zero-based integer index or comma-separated index list | Selects tracks within external file N, using the same values as external_audio_track. The suffix identifies the file, while the value identifies tracks inside it. |
external_audio_offset |
file::external_audio_offset |
Nonnegative decimal number, seconds | Sets the starting position within the first external audio file. For example, 15.0 skips its first 15 seconds; it does not delay the start of the main source. |
external_audio_offset.N |
file::external_audio_offset.N |
Nonnegative decimal number, seconds | Sets the starting position within external file N. |
external_audio_loop |
file::external_audio_loop |
Boolean: true or false
|
Enables or disables repetition when an external audio file reaches its end. This is a reader-wide setting, without a per-file numeric suffix. See Loop external audio. |
Attach an external audio file
You can specify a path with the external_audio property when opening a source. Quote paths inside a properties string, particularly when they contain spaces:
myFile.FileNameSet(pathToMyFile, @"external_audio='c:\MP3_audio.mp3'"); // MPlatform SDK
myReader.ReaderOpen(pathToMyFile, @"external_audio='c:\MP3_audio.mp3'"); // MFormats SDK
Or specify the path with PropsSet:
(myFile as IMProps).PropsSet("file::external_audio", @"c:\MP3_audio.mp3"); // MPlatform SDK
myReader.PropsSet("external_audio", @"c:\MP3_audio.mp3"); // MFormats SDK
For a predictable initial configuration, supply the path, track selection, offset, and looping setting together in the opening properties string. MPlatform playback starts with FilePlayStart. In MFormats, continue retrieving and processing frames in your application's normal frame loop after ReaderOpen, releasing each frame after use.
Choose a starting position
Use external_audio_offset to start reading the external audio from a position measured in seconds:
(myFile as IMProps).PropsSet("file::external_audio_offset", "15.0"); // Start from the 15th second of the external file
myReader.PropsSet("external_audio_offset", "15.0"); // MFormats SDK
Select audio tracks
Use external_audio_track to select an audio track inside the external file. Track numbering starts at zero:
(myFile as IMProps).PropsSet("file::external_audio_track", "1"); // Use the second audio track
myReader.PropsSet("external_audio_track", "1"); // MFormats SDK
For more than one track, specify their indices as a comma-separated list, such as 0,1. Use external_audio_track for tracks in the external file and audio_track for tracks in the main source.
Attach multiple external audio files
You can use multiple audio files as external audio tracks for a given video file:
(myFile as IMProps).PropsSet("file::external_audio", @"c:\FirstTrack.mp3"); // MPlatform SDK
(myFile as IMProps).PropsSet("file::external_audio.1", @"c:\SecondTrack.mp3");
(myFile as IMProps).PropsSet("file::external_audio.2", @"c:\ThirdTrack.wav");
myReader.PropsSet("external_audio", "first.mp3"); // MFormats SDK
myReader.PropsSet("external_audio.1", "second.mp3");
myReader.PropsSet("external_audio.2", "third.mp3");
Use matching suffixes for each file's track and offset settings. For example, external_audio_track.1 selects tracks inside the second external file, and external_audio_offset.1 sets its starting position. Keep file entries consecutive: reading the list stops at the first empty path.
Loop external audio
Set external_audio_loop=true to repeat external audio independently of the main file. When an external file reaches its end, playback restarts it from the beginning. Timestamps for subsequent passes are advanced by the accumulated external-file duration to keep them on the main playback timeline.
This is useful when a short audio file should continue during a longer video. The setting applies to external audio and does not enable looping of the main source. Setting it to false disables this independent repetition.
Requirements: the external file must report a positive duration and support restarting from its beginning.
The following examples attach external audio, enable repetition, and disable the main source's original audio:
// MPlatform SDK: myFile is an MFileClass instance.
myFile.FileNameSet(pathToMyFile,
@"external_audio='c:\MP3_audio.mp3' external_audio_loop=true audio_track=-1");
myFile.FilePlayStart();
// MFormats SDK: myReader is an MFReaderClass instance.
myReader.ReaderOpen(pathToMyFile,
@"external_audio='c:\MP3_audio.mp3' external_audio_loop=true audio_track=-1");
// Continue the application's normal frame retrieval and processing loop.
The equivalent property names for PropsSet are:
(myFile as IMProps).PropsSet("file::external_audio_loop", "true"); // MPlatform SDK
myReader.PropsSet("external_audio_loop", "true"); // MFormats SDK
A property readback can confirm the configured value, but checking output audio across the external file's end is necessary to confirm repetition in your playback workflow.
External-file opening settings
External audio files are opened with default splitter settings. Opening options from the main source, such as mxf.index_path, are not passed to an external .mxf audio file. Use the external-audio properties above to configure file paths, track selection, starting positions, and repetition.
How to disable original audio
Specify the audio_track property of your source object as -1 to disable its original audio while retaining the selected external audio:
(myFile as IMProps).PropsSet("file::audio_track", "-1"); // Disable the original audio
myReader.PropsSet("audio_track", "-1"); // MFormats SDK
External image for audio files
If you use an audio file as a source and you need to use some cover image during its playback you should specify the img_stub property. You can use a HEX-code of a color or a path to an image as a value for this property:
(myFile as IMProps).PropsSet("file::img_stub", @"c:\myTestBG.png");
Usage for MPlaylist and MMixer objects
For MPlaylist items or MMixer streams, the approach is the same. For example:
(myItem as IMProps).PropsSet("file::external_audio", @"c:\MP3_audio.mp3");Still have questions?
Tell us what didn’t work or what you’d like clarified.