Change Audio Channel Configuration of Asset

This ExtendScript code configures the audio mapping of a video asset imported into Premiere Pro.

For instance, a video file with 16 audio channels will be remapped to 4 channels, with the following mapping: channel 0 to 0, channel 1 to 1, channel 2 to 6, and channel 3 to 12.

// moovIT GmbH
// Check if an asset has (already been imported

// B Dimmel
// Version 1.0
// Date: Dec 9th 2024
// Changelog: Dec 9th 2024
// Initial release

// Path to the media file
var path = '{stream.variable.source}';
// Desired audio channel count
var count = 4;

// Function call to change the audio channel count of the specified media file
changeAudioChannelCount(path, count);

// Function definition to change the audio channel count
function changeAudioChannelCount(path, count) {
  try {
    // Find media items in the project that match the specified path
    var media = app.project.rootItem.findItemsMatchingMediaPath(new File(path).fsName);
    
    // Loop through all found media items
    for (var i = 0; i < media.length; i++) {
      // Get the current audio channel mapping for the media item
      var mapping = media[i].getAudioChannelMapping;
      if (mapping) {
        // Set audio channel mappings (example: map channel 0 to 0, 1 to 1, 2 to 6, and 3 to 12)
        // Counts start at 0 which is channel 1
        mapping.setMappingForChannel(0, 0);
        mapping.setMappingForChannel(1, 1);
        mapping.setMappingForChannel(2, 6);
        mapping.setMappingForChannel(3, 12);

        // Set the number of audio channels to the desired count
        mapping.audioClipsNumber = count;

        // Apply the modified audio channel mapping to the media item
        media[i].setAudioChannelMapping(mapping);
      }
    }
  } catch (error) {
    // Handle any errors that occur during the process
    // Currently, the catch block is empty, so errors will be silently ignored
  }
}

// Get the active project
var project = app.project;

// Save the project
project.save();

Last updated