-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphotoImporterEffects.js
More file actions
110 lines (85 loc) · 3.37 KB
/
Copy pathphotoImporterEffects.js
File metadata and controls
110 lines (85 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// ExtendScript for Adobe After Effects to import all photos from a folder into a composition with specific duration in milliseconds
// Path to the folder containing photos
// Desired duration for each photo in milliseconds
var photoDurationMs = 100; // 5000 milliseconds (5 seconds)
// Function to get all image files from a folder
function getFilesArray(folderPath) {
var folder = new Folder(folderPath);
if (!folder.exists) {
throw new Error("Folder does not exist: " + folderPath);
}
var files = folder.getFiles();
// Ensure files is an array
if (!Array.isArray(files)) {
files = Array.prototype.slice.call(files);
}
// Filter to include only File objects
files = files.filter(function(file) {
return file instanceof File;
});
return files;
}
var folderPath = "C:/Users/will/coding projects/video maker scripts/editScript/downloaded_images"; // Update this to your folder path
function getPhotoPaths(folderPath) {
var folder = new Folder(folderPath);
if (!folder.exists) {
throw new Error("Folder does not exist: " + folderPath);
}
var files = folder.getFiles();
// Ensure files is an array
if (!Array.isArray(files)) {
files = Array.prototype.slice.call(files);
}
// Filter to include only File objects
files = files.filter(function(file) {
return file instanceof File;
});
// Map to get fsName of each file
var filePaths = files.map(function(file) {
return file.fsName;
});
return filePaths;
}
// Function to import files and return the imported project items
function importFiles(filePaths) {
var importedItems = [];
for (var i = 0; i < filePaths.length; i++) {
var importOptions = new ImportOptions(new File(filePaths[i]));
if (importOptions.canImportAs(ImportAsType.FOOTAGE)) {
importOptions.importAs = ImportAsType.FOOTAGE;
var importedFile = app.project.importFile(importOptions);
importedItems.push(importedFile);
}
}
return importedItems;
}
// Function to create a new composition
function createNewComposition(compName, width, height, duration, frameRate) {
var comp = app.project.items.addComp(compName, width, height, 1, duration, frameRate);
return comp;
}
// Function to add items to the composition with specific duration in milliseconds
function addItemsToComposition(comp, items, durationMs) {
var durationSec = durationMs / 1000; // Convert milliseconds to seconds
for (var i = 0; i < items.length; i++) {
var layer = comp.layers.add(items[i]);
layer.startTime = i * durationSec;
layer.outPoint = layer.startTime + durationSec;
}
}
// Main function to execute the script
function main() {
app.beginUndoGroup("Import Photos to Composition");
var photoPaths = getPhotoPaths(folderPath);
var importedItems = importFiles(photoPaths);
// Set composition settings
var compWidth = 1920;
var compHeight = 1080;
var compFrameRate = 30;
var compDuration = (importedItems.length * photoDurationMs) / 1000; // Convert to seconds
var comp = createNewComposition("Photo Composition", compWidth, compHeight, compDuration, compFrameRate);
addItemsToComposition(comp, importedItems, photoDurationMs);
app.endUndoGroup();
}
// Execute the main function
main();