Skip to content

Instantly share code, notes, and snippets.

@JonnyBurger
Created October 4, 2024 08:44
Show Gist options
  • Save JonnyBurger/96e1c1945e16ba1a54530d127f4060d5 to your computer and use it in GitHub Desktop.
Save JonnyBurger/96e1c1945e16ba1a54530d127f4060d5 to your computer and use it in GitHub Desktop.
Migrating the Remotion Recorder to the new captions format
// We have migrated the captions format to the `Caption` type:
// https://remotion.dev/docs/captions/caption
// This will allow other captioning solutions as well.
// If you have already created captions, migrate them using:
// Run this with `bun migrate.ts`
import { toCaptions } from "@remotion/install-whisper-cpp";
import { write } from "bun";
import { readFileSync, readdirSync, statSync } from "node:fs";
for (const item of readdirSync("public")) {
const isFolder = statSync(`public/${item}`).isDirectory();
if (!isFolder) {
continue;
}
const subs = readdirSync(`public/${item}`).filter((f) => f.endsWith(".json"));
for (const sub of subs) {
const whisperCppOutput = JSON.parse(
readFileSync(`public/${item}/${sub}`, "utf-8"),
);
if (!whisperCppOutput.systeminfo) {
continue;
}
const { captions } = toCaptions({ whisperCppOutput });
write(`public/${item}/${sub}`, JSON.stringify(captions, null, 2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment