Skip to main content
Skip table of contents

UC Use JavaScript in Shape Tags


VidiCore’s TRANSCODE jobs determine the destination format of the created file from the transcode preset storage on a shape tag. These transcode presets often are static and define a specific format.

For advanced use-cases, however, more flexibility may be required. This can be achieved by using JavaScript in a transcode preset.


The following example shows how to exchange audio tracks on an MXF file that has HDF audio layout (one MXF track for each audio channel) by using JavaScript in a shape tag.

Shape tag definition:

PUT /API/shape-tag/audioxchange 
Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TranscodePresetDocument xmlns="">

JavaScript for this shape tag:

PUT /API/shape-tag/audioxchange/script 
Content-Type: application/javascript

var layout = jobMetadata.get("AudioMapping").split(',');
var trackCount = shape.getAudioComponent().size();
preset.setAudio(new com.vidispine.generated.AudioTranscodePresetType());
for(var i = 0; i < trackCount; i++)
      var mix = new com.vidispine.generated.AudioTranscodePresetMixType();
      var channelMix = new com.vidispine.generated.AudioTranscodePresetChannelMixType(); = shape.getAudioComponent().get(layout[i]).getEssenceStreamId(); = 0;
for(var i = trackCount; i < 16; i++)
      var mix = new com.vidispine.generated.AudioTranscodePresetMixType();
for(var i = 0; i < 16; i++)
      var stream = new java.lang.Integer(1);

Use this API call to start a VidiCore job exchanging the audio tracks of an 8-channel source file:

POST /API/item/<itemId>/transcode?tag=audioxchange&createThumbnails=false&jobmetadata=AudioMapping%3D2,3,4,5,6,7,0,1

The desired channel mapping is supplied via the jobmetadata value AudioMapping. Each number defines the 0-based index of the source channel. The destination channel is defined by the position in the list. For a 16-channel source file 16 comma-separated numbers need to be specified.

To test the shape tag script:

GET /API/shape-tag/audioxchange/item/<itemId>/shape/<shapeId>?job=<jobId>

The job ID in the query parameter job is required to fill the script variable jobMetadata. Detailled documentation on the objects available in a shape tag JavaScript can be found in APIdoc:

Refer to the VidiCore knowledge for more information: Overriding Presets When Transcoding

JavaScript errors detected

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

If this problem persists, please contact our support.