Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat: effect previews render from each effect's real FFmpeg chain

Jareer26648bb7a4ed
diff --git a/desktop/src/assets/effect-previews/.gitkeep b/desktop/src/assets/effect-previews/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/desktop/src/components/MediaBin.tsx b/desktop/src/components/MediaBin.tsx
index f7771102..f29ca041 100644
--- a/desktop/src/components/MediaBin.tsx
+++ b/desktop/src/components/MediaBin.tsx
@@ -774,6 +774,23 @@ function TransitionsPage({
);
}
+/**
+ * Rendered effect previews, one image per effect id, produced by
+ * `scripts/generate-effect-previews.mjs` running each effect's real FFmpeg
+ * chain over the chosen source still. Globbed so a missing render simply
+ * falls back to the effect's gradient swatch - the catalogue never breaks
+ * because a preview was not generated yet.
+ */
+const EFFECT_PREVIEWS: Record<string, string> = Object.fromEntries(
+ Object.entries(
+ import.meta.glob("../assets/effect-previews/*.{webp,jpg,png}", {
+ eager: true,
+ query: "?url",
+ import: "default",
+ }),
+ ).map(([file, url]) => [file.replace(/^.*\/|\.\w+$/g, ""), url as string]),
+);
+
function EffectsPage({
category,
onApply,
@@ -784,17 +801,41 @@ function EffectsPage({
const visible = EFFECTS.filter((effect) => effect.category === category);
return (
<ul className={`${CARD_GRID} pt-2`}>
- {visible.map((effect) => (
- <CatalogueCard
- key={effect.id}
- label={effect.label}
- blurb={effect.blurb}
- onApply={() => onApply(effect.id)}
- >
- <span className="absolute inset-0" style={{ background: effect.swatch }} aria-hidden />
- <Icon name="sparkles" size={20} strokeWidth={1.5} className="relative text-white/85" />
- </CatalogueCard>
- ))}
+ {visible.map((effect) => {
+ const preview = EFFECT_PREVIEWS[effect.id];
+ return (
+ <CatalogueCard
+ key={effect.id}
+ label={effect.label}
+ blurb={effect.blurb}
+ onApply={() => onApply(effect.id)}
+ >
+ {preview ? (
+ <img
+ src={preview}
+ alt=""
+ aria-hidden
+ draggable={false}
+ className="absolute inset-0 h-full w-full object-cover"
+ />
+ ) : (
+ <>
+ <span
+ className="absolute inset-0"
+ style={{ background: effect.swatch }}
+ aria-hidden
+ />
+ <Icon
+ name="sparkles"
+ size={20}
+ strokeWidth={1.5}
+ className="relative text-white/85"
+ />
+ </>
+ )}
+ </CatalogueCard>
+ );
+ })}
</ul>
);
}
diff --git a/scripts/generate-effect-previews.mjs b/scripts/generate-effect-previews.mjs
new file mode 100644
index 00000000..a01505e0
--- /dev/null
+++ b/scripts/generate-effect-previews.mjs
@@ -0,0 +1,86 @@
+#!/usr/bin/env node
+// Renders one preview thumbnail per video effect by running each effect's
+// real FFmpeg chain - the same `buildEffectChain` the exporter uses, at its
+// default parameters - over one source image. The catalogue then shows what
+// an effect actually does instead of a gradient standing in for it.
+//
+// node scripts/generate-effect-previews.mjs <image> [outDir]
+//
+// Defaults land in desktop/src/assets/effect-previews/<effect-id>.webp,
+// where the media bin picks them up by id (Vite globs the directory).
+// Re-run whenever the source image or the effect list changes.
+//
+// The image is scaled to tile size *before* the chain runs, so pixel-sized
+// effects (blur radii, pixelation) read at preview scale instead of
+// vanishing; WebP at quality 80 keeps the whole set a few kilobytes each.
+
+import { createRequire } from "node:module";
+import { execFileSync } from "node:child_process";
+import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import { pathToFileURL, fileURLToPath } from "node:url";
+
+const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
+const [, , image, outDirArg] = process.argv;
+if (!image) {
+ console.error("usage: generate-effect-previews.mjs <image> [outDir]");
+ process.exit(2);
+}
+const outDir = outDirArg ?? path.join(root, "desktop/src/assets/effect-previews");
+const TILE = { width: 320, height: 180 };
+
+// The effect catalogue is TypeScript inside the app; esbuild (already there
+// as Vite's own dependency) bundles it into an importable module so this
+// script reads the same source of truth the app ships.
+const require = createRequire(path.join(root, "desktop/package.json"));
+const esbuild = require("esbuild");
+const scratch = mkdtempSync(path.join(tmpdir(), "wolfcut-previews-"));
+const bundled = path.join(scratch, "effects.mjs");
+await esbuild.build({
+ entryPoints: [path.join(root, "desktop/src/lib/effects.ts")],
+ bundle: true,
+ format: "esm",
+ outfile: bundled,
+});
+const { EFFECTS, buildEffectChain } = await import(pathToFileURL(bundled));
+
+// WebP when this ffmpeg can encode it, JPEG otherwise - at 320x180 the
+// difference is a few kilobytes per tile, not worth failing over.
+const encoders = execFileSync("ffmpeg", ["-hide_banner", "-encoders"], {
+ stdio: ["ignore", "pipe", "ignore"],
+}).toString();
+const format = encoders.includes("libwebp")
+ ? { args: ["-c:v", "libwebp", "-quality", "80"], extension: "webp" }
+ : { args: ["-c:v", "mjpeg", "-q:v", "4"], extension: "jpg" };
+
+mkdirSync(outDir, { recursive: true });
+const failed = [];
+for (const effect of EFFECTS) {
+ // Default parameters, position 0 in the chain - a fresh apply.
+ const chain = buildEffectChain([{ id: effect.id, params: {} }]);
+ const fit =
+ `scale=${TILE.width}:${TILE.height}:force_original_aspect_ratio=increase,` +
+ `crop=${TILE.width}:${TILE.height}`;
+ const filter = chain ? `${fit},${chain}` : fit;
+ const out = path.join(outDir, `${effect.id}.${format.extension}`);
+ try {
+ execFileSync(
+ "ffmpeg",
+ ["-y", "-v", "error", "-i", image, "-vf", filter,
+ "-frames:v", "1", ...format.args, out],
+ { stdio: ["ignore", "ignore", "pipe"] },
+ );
+ console.log(` ${effect.id}.${format.extension}`);
+ } catch (error) {
+ failed.push(effect.id);
+ console.error(`FAILED ${effect.id}: ${error.stderr?.toString().trim() || error.message}`);
+ }
+}
+rmSync(scratch, { recursive: true, force: true });
+
+console.log(`\n${EFFECTS.length - failed.length}/${EFFECTS.length} previews written to ${outDir}`);
+if (failed.length > 0) {
+ console.error(`failed: ${failed.join(", ")}`);
+ process.exit(1);
+}