-
Subtitle Script for AE
Hey guys I’ve been working on a lot of subtitle videos lately and just wanted to share a script i made that might save other people some time and headaches too. The way it works is that it takes an existing, stylized text layer and runs through a SRT transcript file of the video. And then it duplicates that layer to keep the style, and updates the text and timing. I’m only a beginner at scripting so it’s nothing amazing but wanted to share it.
I used WhisperAI to get a quick and accurate transcript, you’re mileage may vary with quality but how you get the transcript file is up to you. The script is looking for this format so I’d recommend whisper as this is the default way it exports the SRT files:
“1
00:00:00,000 –> 00:00:01,760
I took this this morning and I just went on a run
2
00:00:01,760 –> 00:00:03,680
and I had one of my best times ever.
3
00:00:03,680 –> 00:00:06,020
I feel so good, I still have energy.
4
00:00:06,020 –> 00:00:08,280
The focus was great, I didn’t feel jittery,
5
00:00:08,280 –> 00:00:09,760
my energy lasts me all day.”
This is the JS script that you’ll need to save as a .jsx file somewhere on your computer for AE to load up:
// Function to parse SRT file contentfunction parseSRT(srtContent) {
var lines = srtContent.split(‘\n’);
var parsed = [];
var index = 0;
while (index < lines.length) {
var sequenceNumber = lines[index++];
var timecodes = lines[index++].split(‘ –> ‘);
var text = lines[index++];
index++; // Skip the empty line
parsed.push({
sequenceNumber: sequenceNumber,
startTime: timecodes[0],
endTime: timecodes[1],
text: text
});
}
return parsed;
}
// Function to convert timecode to seconds (00:00:00,000 format)
function convertTimecodeToSeconds(timecode) {
var parts = timecode.split(‘:’);
var hours = parseInt(parts[0], 10);
var minutes = parseInt(parts[1], 10);
var seconds = parseFloat(parts[2].replace(‘,’, ‘.’));
return (hours * 3600) + (minutes * 60) + seconds;
}
// Display dialog to select SRT file
var srtFile = File.openDialog(“Select an SRT file”);
if (srtFile !== null) {
// Read the SRT file content
srtFile.open(“r”);
var srtContent = srtFile.read();
srtFile.close();
// Parse the SRT content
var parsedSRT = parseSRT(srtContent);
// Get the currently selected text layer
var currentComp = app.project.activeItem;
var selectedLayers = currentComp.selectedLayers;
var originalTextLayer = selectedLayers[0]; // Assuming the first selected layer is the text layer you want to duplicate
// Loop through each parsed SRT entry
for (var i = 0; i < parsedSRT.length; i++) {
var entry = parsedSRT[i];
// Duplicate the original text layer
var newTextLayer = originalTextLayer.duplicate();
// Update the text content
newTextLayer.property(“Source Text”).setValue(entry.text);
// Update the start and end times (convert timecodes to seconds)
var startTimeInSeconds = convertTimecodeToSeconds(entry.startTime);
var endTimeInSeconds = convertTimecodeToSeconds(entry.endTime);
// Explicitly set inPoint and outPoint
newTextLayer.inPoint = startTimeInSeconds;
newTextLayer.outPoint = endTimeInSeconds;
// Fit layer to comp width
fitLayerToCompWidth(newTextLayer, currentComp);
}
} else {
alert(“No SRT file selected. Operation cancelled.”);
}
And that’s basically it, just save that script, select your original text layer, and go to file > script >run script. Click on the .jsx file and it should prompt you to select your SRT file. I made the original text layer in a paragraph text box so that it would keep the additional new layers 100% in frame. It’s nothing special but I hope it can save you guys some time here and there. I wouldn’t be surprised if something like exists already but it was still fun to make haha.
Sorry, there were no replies found.