Skip to main content
Skip table of contents

UC Use JavaScript in Shape Tags

Motivation

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.

Workflow

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:

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

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TranscodePresetDocument xmlns="http://xml.vidispine.com/schema/vidispine">
    <format>mxf</format>
</TranscodePresetDocument>

JavaScript for this shape tag:

CODE
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();
      channelMix.stream = shape.getAudioComponent().get(layout[i]).getEssenceStreamId();
      channelMix.channel = 0;
      mix.getInput().add(channelMix);
      preset.getAudio().withMix(mix);
}
for(var i = trackCount; i < 16; i++)
{
      var mix = new com.vidispine.generated.AudioTranscodePresetMixType();
      mix.setSilence(true);
      preset.getAudio().getMix().add(mix);
}
for(var i = 0; i < 16; i++)
{
      var stream = new java.lang.Integer(1);
      preset.getAudio().getStream().add(stream);
}

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.