/**
* This script creates a new composition with a blurred background effect.
* It duplicates the selected footage, scales it to fit the composition,
* applies a Gaussian Blur and Levels effect to the duplicated layer,
* and renames the layers accordingly.
*/
// Get the active project
var project = app.project;
if (!project) {
alert("No project open.");
} else {
app.beginUndoGroup("Create Blurred Background");
// Get the selected items
var selectedItems = project.selection;
if (selectedItems.length === 0) {
alert("No footage selected.");
} else {
var footage = selectedItems[0];
// Create a new composition
var compWidth = 1920;
var compHeight = 1080;
var compDuration = footage.duration;
var compFPS = footage.frameRate;
var comp = project.items.addComp("Blurred Background Comp", compWidth, compHeight, 1, compDuration, compFPS);
// Add the footage to the composition
var layer = comp.layers.add(footage);
// Scale to fit height
var scaleFactor = (compHeight / footage.height) * 100;
layer.transform.scale.setValue([scaleFactor, scaleFactor]);
layer.transform.position.setValue([compWidth / 2, compHeight / 2]);
// Duplicate the layer
var duplicateLayer = layer.duplicate();
duplicateLayer.moveBefore(layer);
// Scale the duplicated layer to fill width
var duplicateScaleFactor = (compWidth / footage.width) * 100;
duplicateLayer.transform.scale.setValue([duplicateScaleFactor, duplicateScaleFactor]);
// Add Gaussian Blur effect to duplicated layer
var blurEffect = duplicateLayer.Effects.addProperty("ADBE Gaussian Blur 2");
blurEffect.property("Blurriness").setValue(100);
// Add Levels effect to duplicated layer
var levelsEffect = duplicateLayer.property("Effects").addProperty("ADBE Easy Levels");
// Rename the layers
duplicateLayer.name = "Background Layer";
layer.name = "Foreground Layer";
// Reorder layers to ensure original layer is on top
layer.moveToBeginning();
// Open the new composition
comp.openInViewer();
app.endUndoGroup();
}
}