Participant
April 28, 2024
Question
File not Found Error
- April 28, 2024
- 1 reply
- 194 views
Hi,
I wrote a script using VSCode and ExtendScript Debugger and keep running into a File not Found error. I put a debugging block at the beginning of my script but it seems to fail on ANY file on my computer. I'm running on Apple M1 Monterey and checked the Open with Rosetta box for VsCode. My AfterEffects is up to date. I've enabled Full Disk Access for VsCode and AfterEffects and have checked Allow Scripts to Write Files and Access Network in AfterEffects preferences as well.
Can someone please let me know what I'm missing? I've pasted my script below. Thanks!
(function() {
app.beginUndoGroup("Batch Video Processing");
alert("New script started");
function testFileAccess() {
var file = new File("C:\\Users\\ezh\\Downloads\\new.mp4");
if (file.exists) {
alert("File exists and can be accessed.");
} else {
alert("File does not exist or cannot be accessed.");
}
}
testFileAccess(); // This will help to check if the script can access the file
// Function to import files from a folder and add them to the project
function importFilesFromFolder(folderPath) {
var folder = new Folder(folderPath);
alert(folderPath)
var files = folder.getFiles("*.mp4");
alert("Number of files found: " + files.length); // Debugging line
for (var i = 0; i < files.length; i++) {
alert("in loop")
var importOptions = new ImportOptions(files[i]);
var footage = app.project.importFile(importOptions);
processVideo(footage, i + 1);
}
}
alert("Done")
// Function to apply transformations to a video and export different versions
function processVideo(footage, index) {
var compName = "Nested Sequence " + index;
var comp = app.project.items.addComp(compName, footage.width, footage.height, 1, footage.duration, 30);
var layer = comp.layers.add(footage);
// Applying transformations and exporting
applyEffectAndExport(layer, "Edge", index, "edge");
applyEffectAndExport(layer, "Invert", index, "invert");
applyEffectAndExport(layer, "Invert", index, "rgb_invert", true); // RGB invert (requires special handling)
applyEffectAndExport(layer, "Tint", index, "gray", true); // Grayscale (requires special handling)
applyEffectAndExport(layer, "Tint", index, "gray_invert", true, true); // Grayscale invert negative (requires special handling)
applyEffectAndExport(layer, "Transform", index, "vflip", false, false, true); // Vertical flip
applyEffectAndExport(layer, "Transform", index, "hflip", false, true, false); // Horizontal flip
applyEffectAndExport(layer, "Transform", index, "shrink", true); // Shrink (requires special handling)
applyEffectAndExport(layer, "Fast Blur", index, "5blur", false, false, false, 5); // Blur radius 5
applyEffectAndExport(layer, "Fast Blur", index, "8blur", false, false, false, 8); // Blur radius 8
}
alert("here")
// Function to apply a specific effect and export the result
function applyEffectAndExport(layer, effectName, index, exportName, isCustomSettings, invertLum, verticalFlip, horizontalFlip, blurRadius) {
var effect = layer.Effects.addProperty(effectName);
// Custom settings for specific effects
if (isCustomSettings) {
if (effectName === "Invert") {
if (invertLum) {
// Set to invert luminance
effect.property("Invert").setValue(true);
}
} else if (effectName === "Tint") {
// Apply grayscale settings
effect.property("Map Black To").setValue([0,0,0]);
effect.property("Map White To").setValue([255,255,255]);
if (invertLum) {
effect.property("Map White To").setValue([0,0,0]);
effect.property("Map Black To").setValue([255,255,255]);
}
} else if (effectName === "Transform") {
if (verticalFlip) {
effect.property("Scale").setValue([-100, 100]); // Vertical flip
} else if (horizontalFlip) {
effect.property("Scale").setValue([100, -100]); // Horizontal flip
} else if (shrink) {
effect.property("Scale").setValue([50, 50]); // Shrink
}
} else if (effectName === "Fast Blur") {
effect.property("Blurriness").setValue(blurRadius);
}
}
// Define render settings and output module settings
var outputFolder = "C:\\Users\\ezh\\Desktop\\960\\4_test_output";
var outputFile = new File(outputFolder + index + "_" + exportName + ".mp4");
var renderQueueItem = app.project.renderQueue.items.add(comp);
var outputModule = renderQueueItem.outputModule(1);
outputModule.file = outputFile;
renderQueueItem.render = true; // Start rendering
}
// Start importing files and processing
var sourceFolder = "C:\\Users\\ezh\\Desktop\\960\\4_test";
alert("found")
importFilesFromFolder(sourceFolder);
app.endUndoGroup();
})();