Skip to main content
Skip table of contents

How to add <output> groups for each pair of audio channels

This guide includes parts of a user case from one of our customers.

Customer asked;

"Please could you give me an example script that can dynamically add <output> groups for each pair of audio channels?
The profile I have below is for 4 channels, but I need one that does 2, 4, 6, up to 16.

CODE
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TranscodePresetDocument xmlns="http://xml.vidispine.com/schema/vidispine">
    <name>360ProxyAudioStream</name>
    <format>mp4</format>
    <audio>
        <output>
            <format>mp4</format>
            <codec>aac</codec>
            <bitrate>128000</bitrate>
            <channel>0</channel>
            <channel>1</channel>
            <stream>2</stream>
        </output>
        <output>
            <format>mp4</format>
            <codec>aac</codec>
            <bitrate>128000</bitrate>
            <channel>3</channel>
            <channel>4</channel>
            <stream>2</stream>
        </output>
    </audio>
    <video>
        <codec>h264</codec>
        <bitrate>1000000</bitrate>
        <resolution>
            <width>640</width>
            <height>360</height>
        </resolution>
    </video>
</TranscodePresetDocument>

Resolution;

CODE
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TranscodePresetDocument xmlns="http://xml.vidispine.com/schema/vidispine">
  <name>360ProxyAudioStream</name>
  <format>mp4</format>
  <audio>
    <output>
      <format>mp4</format>
      <codec>aac</codec>
      <bitrate>128000</bitrate>
      <channel>0</channel>
      <channel>1</channel>
      <stream>2</stream>
    </output>
  </audio>
  <video>
    <codec>h264</codec>
    <bitrate>1000000</bitrate>
    <resolution>
      <width>640</width>
      <height>360</height>
    </resolution>
  </video>
  <script>
var template = preset.getAudio().getOutput().get(0);
var initialChannels = preset.getAudio().getOutput().size() * 2;

var channelCount = 4;
for (i = initialChannels; i &lt; channelCount; i += 2) {
  var output = template.clone();
  output.getChannel().clear();
  output.getStream().clear();

  output.getChannel().add(new java.lang.Integer(i));
  output.getChannel().add(new java.lang.Integer(i+1));
  output.getStream().add(new java.lang.Integer(2));
  preset.getAudio().getOutput().add(output);
}
</script>
</TranscodePresetDocument>

To test the script against an item/shape, you can use;

CODE
GET /shape-tag/(tag-name)/item/(item-id)/shape/(shape-id)

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.