Let's start with a shape tag. I have copied this from the built-in, and modified the resolution: 


 I then added a script: 

var inWidth = shape.getVideoComponent().get(0).getResolution().getWidth(); // http://apidoc.vidispine.com/latest/xsddocs/com/vidispine/generated/VideoComponentType.html
var inHeight = shape.getVideoComponent().get(0).getResolution().getHeight();
var scaling = preset.getVideo().getScaling();

var outWidth = scaling.getWidth();
var outHeight = scaling.getHeight();

var targetDAR = new com.vidispine.generated.AspectRatioType();

var proportionalDifference = outHeight * inWidth–outWidth * inHeight;

if (proportionalDifference > 0) { // output is taller (skinnier) than input
	padding = -proportionalDifference / outWidth;
	scaling.setTop(padding / 2);
	scaling.setBottom(padding - padding / 2);
} else { // output is fatter than input
	padding = proportionalDifference / outHeight;
	scaling.setLeft(padding / 2);
	scaling.setRight(padding - padding / 2);

The order of how Vidispine applies the commands in the scaling tag is:

  • Crop/pad
  • Rotate
  • Scale

So, we are comparing the proportions and either pad top/bottom or left/right. Remember that setTop/Bottom/Left/Right refers to cropping values: negative values mean padding.

The original (scaled):

The result (scaled):