Skip to content

Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.

fix: Remotion transparent overlay, 1080p sizing, word corrections, spinners

Nika Siradze2017b5cd2ee4
diff --git a/backend/cli.py b/backend/cli.py
index 3a9d37f..29a63e1 100644
--- a/backend/cli.py
+++ b/backend/cli.py
@@ -450,28 +450,32 @@ def cmd_process(args):
t0 = time.time()
for i, clip in enumerate(clips):
- print(f" Clip {i+1}/{len(clips)}: {clip['title'][:40]}...", end="", flush=True)
- try:
- result = generate_clip(
- video_path=video_path,
- start_second=clip["start_second"],
- end_second=clip["end_second"],
- caption_style=config.get("caption_style", "branded"),
- crop_strategy=config.get("crop_strategy", "face"),
- transcript_words=words,
- title=clip.get("title", f"clip_{i+1}"),
- output_dir=output_dir,
- logo_path=config.get("logo_path") or None,
- outro_path=config.get("outro_path") or None,
- keep_segments=clip.get("segments"),
- face_map=face_map,
- )
- results.append(result)
- print(f" ✓ {result['file_size_mb']}MB")
- except Exception as e:
- print(f" ✗ {e}")
- results.append({"status": "error", "error": str(e)})
- continue
+ ok = False
+ result = None
+ with _Spinner(f"Clip {i+1}/{len(clips)}: {clip['title'][:40]}...") as sp:
+ try:
+ result = generate_clip(
+ video_path=video_path,
+ start_second=clip["start_second"],
+ end_second=clip["end_second"],
+ caption_style=config.get("caption_style", "branded"),
+ crop_strategy=config.get("crop_strategy", "face"),
+ transcript_words=words,
+ title=clip.get("title", f"clip_{i+1}"),
+ output_dir=output_dir,
+ logo_path=config.get("logo_path") or None,
+ outro_path=config.get("outro_path") or None,
+ keep_segments=clip.get("segments"),
+ face_map=face_map,
+ )
+ results.append(result)
+ ok = True
+ except Exception as e:
+ print(f"\n ✗ {e}")
+ results.append({"status": "error", "error": str(e)})
+ continue
+ if ok:
+ print(f" ✓ Clip {i+1}/{len(clips)}: {result['file_size_mb']}MB")
# Generate thumbnail and append to clip immediately
if _thumb_enabled and _thumb_gen and result.get("output_path"):
@@ -566,6 +570,42 @@ def cmd_process(args):
)
+class _Spinner:
+ """Reusable terminal spinner for long-running operations."""
+
+ def __init__(self, message: str, indent: str = " "):
+ import threading
+ self._msg = message
+ self._indent = indent
+ self._stop = threading.Event()
+ self._thread = None
+
+ def __enter__(self):
+ import threading
+ self._stop.clear()
+
+ def _run():
+ frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
+ i = 0
+ while not self._stop.is_set():
+ print(f"\r{self._indent}{frames[i % len(frames)]} {self._msg[:55]:<55}", end="", flush=True)
+ i += 1
+ self._stop.wait(0.1)
+
+ self._thread = threading.Thread(target=_run, daemon=True)
+ self._thread.start()
+ return self
+
+ def update(self, message: str):
+ self._msg = message
+
+ def __exit__(self, *args):
+ self._stop.set()
+ if self._thread:
+ self._thread.join(timeout=1)
+ print(f"\r{self._indent}{'':60}\r", end="")
+
+
def _print_clips(clips: list):
"""Print clip list in the standard format."""
for i, c in enumerate(clips):
@@ -814,8 +854,8 @@ def _review_clips(clips: list, segments: list, energy_scores: list | None, confi
style=qstyle,
).ask()
if description and description.strip():
- print(f"\n Searching transcript...")
- found = _find_moment_with_claude(description.strip(), segments, clips)
+ with _Spinner("Searching transcript..."):
+ found = _find_moment_with_claude(description.strip(), segments, clips)
if found:
for f_clip in found:
print(f"\n {bold}Found:{reset} {f_clip['title']}")
@@ -841,13 +881,13 @@ def _review_clips(clips: list, segments: list, energy_scores: list | None, confi
elif action == "more":
top_n = config.get("top_clips", 5)
- print(f"\n Asking Claude for {top_n} more suggestions...")
from services.claude_suggest import suggest_with_claude
- more_clips = suggest_with_claude(
- segments=segments,
- top_n=top_n,
- progress_callback=lambda pct, msg: print(f" {msg}") if msg else None,
- )
+ with _Spinner(f"Asking Claude for {top_n} more suggestions...") as sp:
+ more_clips = suggest_with_claude(
+ segments=segments,
+ top_n=top_n,
+ progress_callback=lambda pct, msg: sp.update(msg) if msg else None,
+ )
if more_clips:
# Filter out duplicates (overlapping timestamps)
new_count = 0
@@ -899,17 +939,118 @@ def _post_render_loop(
if "output_path" in result:
rendered.append({"clip": clip, "result": result, "index": i})
+ def _open_clip(r):
+ """Open a rendered clip for preview."""
+ import subprocess as _sp
+ out = r["result"].get("output_path", "")
+ if out and os.path.exists(out):
+ _sp.Popen(["open", out] if sys.platform == "darwin" else ["xdg-open", out])
+
+ def _rerender_clip(r):
+ """Re-render a clip with current config."""
+ clip = r["clip"]
+ ok = False
+ with _Spinner(f"Rendering: {clip['title'][:40]}..."):
+ try:
+ new_result = generate_clip(
+ video_path=video_path,
+ start_second=clip["start_second"],
+ end_second=clip["end_second"],
+ caption_style=config.get("caption_style", "branded"),
+ crop_strategy=config.get("crop_strategy", "face"),
+ transcript_words=words,
+ title=clip.get("title", "clip"),
+ output_dir=output_dir,
+ logo_path=config.get("logo_path") or None,
+ outro_path=config.get("outro_path") or None,
+ keep_segments=clip.get("segments"),
+ face_map=face_map,
+ )
+ r["result"] = new_result
+ ok = True
+ except Exception as e:
+ print(f"\n ✗ {e}")
+ if ok:
+ print(f" ✓ {new_result['file_size_mb']}MB")
+ return ok
+
+ # Review each clip one by one — open for preview, ask for feedback
+ print(f"\n {'─' * 45}")
+ print(f" {bold}Review clips{reset}")
+
+ for idx, r in enumerate(rendered):
+ clip = r["clip"]
+ print(f"\n {accent}Clip {idx+1}/{len(rendered)}:{reset} {clip['title'][:50]}")
+ _open_clip(r)
+
+ while True:
+ action = questionary.select(
+ "",
+ choices=[
+ questionary.Choice("Looks good — next", value="next"),
+ questionary.Choice("Change caption style", value="style"),
+ questionary.Choice("Make shorter (trim end)", value="shorter"),
+ questionary.Choice("Make longer (extend end)", value="longer"),
+ questionary.Choice("Shift start earlier", value="earlier"),
+ questionary.Choice("Shift start later", value="later"),
+ questionary.Choice("Skip this clip (delete)", value="skip"),
+ ],
+ style=qstyle,
+ instruction="",
+ ).ask()
+
+ if action is None or action == "next":
+ break
+
+ if action == "skip":
+ # Remove the output file
+ out = r["result"].get("output_path", "")
+ if out and os.path.exists(out):
+ os.remove(out)
+ print(f" Removed: {os.path.basename(out)}")
+ r["_skipped"] = True
+ break
+
+ if action == "style":
+ new_style = questionary.select("Style:", choices=[
+ questionary.Choice("hormozi — bold uppercase, yellow highlight", value="hormozi"),
+ questionary.Choice("branded — dark pill on active word + logo", value="branded"),
+ questionary.Choice("karaoke — sentence visible, words light up", value="karaoke"),
+ questionary.Choice("subtle — clean small text at bottom", value="subtle"),
+ ], style=qstyle).ask()
+ if new_style:
+ config["caption_style"] = new_style
+ elif action == "shorter":
+ clip["end_second"] = clip["end_second"] - 5
+ clip["duration"] = max(10, clip["duration"] - 5)
+ elif action == "longer":
+ clip["end_second"] = clip["end_second"] + 5
+ clip["duration"] = clip["duration"] + 5
+ elif action == "earlier":
+ clip["start_second"] = max(0, clip["start_second"] - 5)
+ elif action == "later":
+ clip["start_second"] = clip["start_second"] + 3
+
+ # Re-render and open again
+ if _rerender_clip(r):
+ _open_clip(r)
+
+ rendered = [r for r in rendered if not r.get("_skipped")]
+ kept = len(rendered)
+ print(f"\n {bold}{kept} clips kept{reset}")
+
+ # Continue with additional actions
while True:
print(f"\n {'─' * 45}")
choices = [
questionary.Choice("Done — open output folder", value="done"),
- questionary.Choice("Re-render a clip (change style/timing)", value="rerender"),
+ questionary.Choice("Re-review a clip", value="rerender"),
questionary.Choice("Find another moment to clip", value="find"),
questionary.Choice("Get more suggestions from Claude", value="more"),
]
action = questionary.select(
- f"{len(rendered)} clips rendered",
+ f"{len(rendered)} clips",
choices=choices,
style=qstyle,
).ask()
@@ -932,68 +1073,50 @@ def _post_render_loop(
continue
r = rendered[pick]
- clip = r["clip"]
-
- # What to change?
- change_choices = [
- questionary.Choice("Caption style", value="style"),
- questionary.Choice("Make shorter (trim end)", value="shorter"),
- questionary.Choice("Make longer (extend end)", value="longer"),
- questionary.Choice("Shift start earlier", value="earlier"),
- questionary.Choice("Shift start later", value="later"),
- ]
- change = questionary.select("What to change?", choices=change_choices, style=qstyle).ask()
- if change is None:
- continue
-
- if change == "style":
- style_choices = [
- questionary.Choice("hormozi — bold uppercase, yellow highlight", value="hormozi"),
- questionary.Choice("branded — dark pill on active word + logo", value="branded"),
- questionary.Choice("karaoke — sentence visible, words light up", value="karaoke"),
- questionary.Choice("subtle — clean small text at bottom", value="subtle"),
- ]
- new_style = questionary.select("Style:", choices=style_choices, style=qstyle).ask()
- if new_style:
- config["caption_style"] = new_style
- elif change == "shorter":
- clip["end_second"] = clip["end_second"] - 5
- clip["duration"] = max(10, clip["duration"] - 5)
- elif change == "longer":
- clip["end_second"] = clip["end_second"] + 5
- clip["duration"] = clip["duration"] + 5
- elif change == "earlier":
- clip["start_second"] = max(0, clip["start_second"] - 5)
- elif change == "later":
- clip["start_second"] = clip["start_second"] + 3
+ _open_clip(r)
+
+ while True:
+ change = questionary.select("", choices=[
+ questionary.Choice("Looks good", value="done"),
+ questionary.Choice("Change caption style", value="style"),
+ questionary.Choice("Make shorter", value="shorter"),
+ questionary.Choice("Make longer", value="longer"),
+ questionary.Choice("Shift start earlier", value="earlier"),
+ questionary.Choice("Shift start later", value="later"),
+ ], style=qstyle, instruction="").ask()
+
+ if change is None or change == "done":
+ break
- # Re-render
- print(f"\n Re-rendering: {clip['title'][:40]}...", end="", flush=True)
- try:
- new_result = generate_clip(
- video_path=video_path,
- start_second=clip["start_second"],
- end_second=clip["end_second"],
- caption_style=config.get("caption_style", "branded"),
- crop_strategy=config.get("crop_strategy", "face"),
- transcript_words=words,
- title=clip.get("title", "clip"),
- output_dir=output_dir,
- logo_path=config.get("logo_path") or None,
- outro_path=config.get("outro_path") or None,
- keep_segments=clip.get("segments"),
- face_map=face_map,
- )
- r["result"] = new_result
- print(f" ✓ {new_result['file_size_mb']}MB")
- except Exception as e:
- print(f" ✗ {e}")
+ clip = r["clip"]
+ if change == "style":
+ new_style = questionary.select("Style:", choices=[
+ questionary.Choice("hormozi", value="hormozi"),
+ questionary.Choice("branded", value="branded"),
+ questionary.Choice("karaoke", value="karaoke"),
+ questionary.Choice("subtle", value="subtle"),
+ ], style=qstyle).ask()
+ if new_style:
+ config["caption_style"] = new_style
+ elif change == "shorter":
+ clip["end_second"] -= 5
+ clip["duration"] = max(10, clip["duration"] - 5)
+ elif change == "longer":
+ clip["end_second"] += 5
+ clip["duration"] += 5
+ elif change == "earlier":
+ clip["start_second"] = max(0, clip["start_second"] - 5)
+ elif change == "later":
+ clip["start_second"] += 3
+
+ if _rerender_clip(r):
+ _open_clip(r)
elif action == "find":
description = questionary.text("Describe the moment:", style=qstyle).ask()
if description and description.strip():
- print(f"\n Searching transcript...")
- found = _find_moment_with_claude(description.strip(), segments, clips)
+ with _Spinner("Searching transcript..."):
+ found = _find_moment_with_claude(description.strip(), segments, clips)
if found:
for f_clip in found:
print(f"\n {bold}Found:{reset} {f_clip['title']}")
@@ -1009,27 +1132,30 @@ def _post_render_loop(
).ask()
if render_it:
for f_clip in found:
- print(f" Rendering: {f_clip['title'][:40]}...", end="", flush=True)
- try:
- new_result = generate_clip(
- video_path=video_path,
- start_second=f_clip["start_second"],
- end_second=f_clip["end_second"],
- caption_style=config.get("caption_style", "branded"),
- crop_strategy=config.get("crop_strategy", "face"),
- transcript_words=words,
- title=f_clip.get("title", "clip"),
- output_dir=output_dir,
- logo_path=config.get("logo_path") or None,
- outro_path=config.get("outro_path") or None,
- keep_segments=f_clip.get("segments"),
- face_map=face_map,
- )
- rendered.append({"clip": f_clip, "result": new_result, "index": len(clips)})
- clips.append(f_clip)
- print(f" ✓ {new_result['file_size_mb']}MB")
- except Exception as e:
- print(f" ✗ {e}")
+ ok = False
+ with _Spinner(f"Rendering: {f_clip['title'][:40]}..."):
+ try:
+ new_result = generate_clip(
+ video_path=video_path,
+ start_second=f_clip["start_second"],
+ end_second=f_clip["end_second"],
+ caption_style=config.get("caption_style", "branded"),
+ crop_strategy=config.get("crop_strategy", "face"),
+ transcript_words=words,
+ title=f_clip.get("title", "clip"),
+ output_dir=output_dir,
+ logo_path=config.get("logo_path") or None,
+ outro_path=config.get("outro_path") or None,
+ keep_segments=f_clip.get("segments"),
+ face_map=face_map,
+ )
+ rendered.append({"clip": f_clip, "result": new_result, "index": len(clips)})
+ clips.append(f_clip)
+ ok = True
+ except Exception as e:
+ print(f"\n ✗ {e}")
+ if ok:
+ print(f" ✓ {new_result['file_size_mb']}MB")
else:
print(f" Couldn't find that moment. Try describing it differently.")
@@ -1066,27 +1192,30 @@ def _post_render_loop(
).ask()
if render_them:
for nc in new_clips:
- print(f" Rendering: {nc['title'][:40]}...", end="", flush=True)
- try:
- new_result = generate_clip(
- video_path=video_path,
- start_second=nc["start_second"],
- end_second=nc["end_second"],
- caption_style=config.get("caption_style", "branded"),
- crop_strategy=config.get("crop_strategy", "face"),
- transcript_words=words,
- title=nc.get("title", "clip"),
- output_dir=output_dir,
- logo_path=config.get("logo_path") or None,
- outro_path=config.get("outro_path") or None,
- keep_segments=nc.get("segments"),
- face_map=face_map,
- )
- rendered.append({"clip": nc, "result": new_result, "index": len(clips)})
- clips.append(nc)
- print(f" ✓ {new_result['file_size_mb']}MB")
- except Exception as e:
- print(f" ✗ {e}")
+ ok = False
+ with _Spinner(f"Rendering: {nc['title'][:40]}..."):
+ try:
+ new_result = generate_clip(
+ video_path=video_path,
+ start_second=nc["start_second"],
+ end_second=nc["end_second"],
+ caption_style=config.get("caption_style", "branded"),
+ crop_strategy=config.get("crop_strategy", "face"),
+ transcript_words=words,
+ title=nc.get("title", "clip"),
+ output_dir=output_dir,
+ logo_path=config.get("logo_path") or None,
+ outro_path=config.get("outro_path") or None,
+ keep_segments=nc.get("segments"),
+ face_map=face_map,
+ )
+ rendered.append({"clip": nc, "result": new_result, "index": len(clips)})
+ clips.append(nc)
+ ok = True
+ except Exception as e:
+ print(f"\n ✗ {e}")
+ if ok:
+ print(f" ✓ {new_result['file_size_mb']}MB")
else:
print(f" No new moments found (all duplicates of existing).")
else:
diff --git a/backend/services/clip_generator.py b/backend/services/clip_generator.py
index 4655fae..cdaeb02 100644
--- a/backend/services/clip_generator.py
+++ b/backend/services/clip_generator.py
@@ -159,6 +159,9 @@ def _build_tight_segments(
return segments
+_remotion_available = None # True/False/None — auto-detected on first render
+
+
def _render_with_remotion(
video_path: str,
words: list[dict],
@@ -170,20 +173,44 @@ def _render_with_remotion(
"""
Render captions using Remotion. Returns True on success, False to fall back to ASS.
"""
+ global _remotion_available
import subprocess
import json
+ # Quick bail if Remotion already failed this session
+ if _remotion_available is False:
+ return False
+
# Find the render script
project_root = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..")
render_script = os.path.join(project_root, "remotion", "render.mjs")
if not os.path.exists(render_script):
+ _remotion_available = False
return False
# Check node is available
node_path = shutil.which("node")
if not node_path:
+ _remotion_available = False
return False
+ # Pre-check: ensure bundle exists (prebundle if not)
+ cache_dir = os.path.join(project_root, ".podcli", "cache", "remotion-bundle")
+ bundle_index = os.path.join(cache_dir, "index.html")
+ if not os.path.exists(bundle_index):
+ # Try a quick prebundle
+ try:
+ r = subprocess.run(
+ [node_path, render_script, "--prebundle"],
+ capture_output=True, text=True, timeout=30, cwd=project_root,
+ )
+ if r.returncode != 0 or not os.path.exists(bundle_index):
+ _remotion_available = False
+ return False
+ except Exception:
+ _remotion_available = False
+ return False
+
# Prepare words JSON (adjust timestamps by offset)
adjusted_words = []
for w in words:
@@ -208,27 +235,38 @@ def _render_with_remotion(
if logo_path and os.path.exists(logo_path):
cmd.extend(["--logo", os.path.abspath(logo_path)])
+ # Stream stderr to terminal for progress
result = subprocess.run(
cmd,
- capture_output=True,
+ stdout=subprocess.PIPE,
+ stderr=None,
text=True,
timeout=600,
cwd=project_root,
)
if result.returncode == 0 and os.path.exists(output_path):
+ _remotion_available = True
return True
- # Log error but don't crash — will fall back to ASS
- if result.stderr:
- print(f" Remotion: {result.stderr[:200]}", flush=True)
+ # Log errors
+ stdout = result.stdout or ""
+ if stdout:
+ lines = [l.strip() for l in stdout.strip().split("\n") if l.strip()]
+ if lines:
+ print(f" Remotion: {lines[-1][:120]}", flush=True)
+
+ # Failed — disable for rest of session
+ if "Error" in stdout:
+ _remotion_available = False
return False
except subprocess.TimeoutExpired:
- print(" Remotion: timed out (10 min), falling back to ASS", flush=True)
+ print(" Remotion: timed out, using ASS for this session", flush=True)
+ _remotion_available = False
return False
except Exception as e:
- print(f" Remotion: {e}, falling back to ASS", flush=True)
+ _remotion_available = False
return False
finally:
try:
diff --git a/backend/services/corrections.py b/backend/services/corrections.py
index 2046dfd..6a0f3ff 100644
--- a/backend/services/corrections.py
+++ b/backend/services/corrections.py
@@ -94,13 +94,21 @@ def apply_corrections(
replacer = lambda m: _replace_match(m, corrections)
- # Fix individual words
+ # Fix individual words (strip punctuation for matching, preserve it in output)
for w in words:
word_text = w.get("word", "")
if word_text:
+ # Try regex match on full text first
new_text = pattern.sub(replacer, word_text)
if new_text != word_text:
w["word"] = new_text
+ else:
+ # Strip trailing/leading punctuation and try again
+ stripped = word_text.strip(".,!?;:\"'()-")
+ if stripped and stripped != word_text:
+ new_stripped = pattern.sub(replacer, stripped)
+ if new_stripped != stripped:
+ w["word"] = word_text.replace(stripped, new_stripped)
# Fix segment text (may contain multi-word corrections like "open AI" → "OpenAI")
for seg in segments:
diff --git a/backend/services/video_processor.py b/backend/services/video_processor.py
index 81bbdf6..bf144f6 100644
--- a/backend/services/video_processor.py
+++ b/backend/services/video_processor.py
@@ -1064,8 +1064,8 @@ def _use_face_map(
keyframes.append((start_t, prev_x))
keyframes.append((start_t + pan_duration, target_x))
else:
- keyframes.append((start_t, prev_x))
- keyframes.append((start_t + 0.01, target_x))
+ # Instant snap — single keyframe at new position, no transition frames
+ keyframes.append((start_t, target_x))
prev_x = target_x
if not keyframes:
diff --git a/remotion/render.mjs b/remotion/render.mjs
index 5791308..148bce1 100644
--- a/remotion/render.mjs
+++ b/remotion/render.mjs
@@ -21,6 +21,7 @@ import { bundle } from "@remotion/bundler";
import { renderMedia, selectComposition } from "@remotion/renderer";
import path from "path";
import fs from "fs";
+import os from "os";
import crypto from "crypto";
import { fileURLToPath } from "url";
@@ -119,11 +120,6 @@ async function main() {
const styleName = opts.style || "branded";
const fps = parseInt(opts.fps || "30", 10);
- // Calculate duration from video words
- const lastWord = words[words.length - 1];
- const durationSec = lastWord ? lastWord.end + 0.5 : 30;
- const durationInFrames = Math.ceil(durationSec * fps);
-
// Get cached bundle first (needed to copy assets into it)
const t0 = Date.now();
const bundleLocation = await getCachedBundle();
@@ -132,23 +128,57 @@ async function main() {
console.log(` bundled in ${(bundleMs / 1000).toFixed(1)}s`);
}
- // Symlink video into bundle's public dir so Remotion's server can serve it
- const publicDir = path.join(bundleLocation, "public");
- fs.mkdirSync(publicDir, { recursive: true });
-
- const videoExt = path.extname(opts.video);
- const videoDest = path.join(publicDir, `clip${videoExt}`);
- try { fs.unlinkSync(videoDest); } catch {}
- fs.symlinkSync(path.resolve(opts.video), videoDest);
- const videoSrc = `clip${videoExt}`;
-
- // Copy logo into bundle's public dir
- let logoSrc;
- if (opts.logo && fs.existsSync(opts.logo)) {
- const logoExt = path.extname(opts.logo);
- fs.copyFileSync(path.resolve(opts.logo), path.join(publicDir, `logo${logoExt}`));
- logoSrc = `logo${logoExt}`;
- }
+ // Serve video and logo via a tiny local HTTP server
+ // (Remotion's bundled server can't serve dynamically added files)
+ const http = await import("http");
+ const assetServer = http.createServer((req, res) => {
+ let filePath = null;
+ if (req.url === "/clip.mp4") filePath = path.resolve(opts.video);
+ else if (req.url === "/logo.png" && opts.logo) filePath = path.resolve(opts.logo);
+
+ if (filePath && fs.existsSync(filePath)) {
+ const stat = fs.statSync(filePath);
+ const ext = path.extname(filePath).slice(1);
+ const mime = { mp4: "video/mp4", png: "image/png", jpg: "image/jpeg", webp: "image/webp" }[ext] || "application/octet-stream";
+ res.writeHead(200, { "Content-Type": mime, "Content-Length": stat.size, "Access-Control-Allow-Origin": "*" });
+ fs.createReadStream(filePath).pipe(res);
+ } else {
+ res.writeHead(404);
+ res.end();
+ }
+ });
+ await new Promise((resolve) => assetServer.listen(0, "127.0.0.1", resolve));
+ const assetPort = assetServer.address().port;
+
+ const videoSrc = `http://127.0.0.1:${assetPort}/clip.mp4`;
+ const logoSrc = opts.logo ? `http://127.0.0.1:${assetPort}/logo.png` : undefined;
+
+ // Probe video dimensions and duration
+ let renderW = 1080;
+ let renderH = 1920;
+ let videoDuration = null;
+ try {
+ const { execSync } = await import("child_process");
+ const probe = execSync(
+ `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${path.resolve(opts.video)}"`,
+ { encoding: "utf-8", timeout: 5000 }
+ ).trim();
+ const [w, h] = probe.split("x").map(Number);
+ if (w > 0 && h > 0) {
+ renderW = w;
+ renderH = h;
+ }
+ const durStr = execSync(
+ `ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${path.resolve(opts.video)}"`,
+ { encoding: "utf-8", timeout: 5000 }
+ ).trim();
+ videoDuration = parseFloat(durStr);
+ } catch {}
+
+ // Calculate duration from video or word timing
+ const lastWord = words[words.length - 1];
+ const durationSec = videoDuration || (lastWord ? lastWord.end + 0.5 : 30);
+ const durationInFrames = Math.ceil(durationSec * fps);
const inputProps = {
videoSrc,
@@ -160,7 +190,7 @@ async function main() {
};
console.log(
- `Remotion: ${words.length} words, ${styleName}, ${durationInFrames}f @ ${fps}fps`
+ `Remotion: ${words.length} words, ${styleName}, ${renderW}x${renderH}, ${durationInFrames}f`
);
// Select composition
@@ -170,27 +200,54 @@ async function main() {
inputProps,
});
- // Render
+ // Render captions as transparent WebM overlay (no video = 10x faster)
+ const cpus = os.cpus().length;
+ const concurrency = Math.max(2, Math.min(cpus, 8));
+ // Store overlay in /tmp to survive temp dir cleanup
+ const overlayId = path.basename(opts.output, ".mp4");
+ const captionOverlay = path.join(os.tmpdir(), `remotion_overlay_${overlayId}.mov`);
+
+ let lastPct = -1;
await renderMedia({
composition: {
...composition,
durationInFrames,
fps,
- width: 2160,
- height: 3840,
+ width: renderW,
+ height: renderH,
},
serveUrl: bundleLocation,
- codec: "h264",
- outputLocation: opts.output,
+ codec: "prores",
+ proResProfile: "4444",
+ pixelFormat: "yuva444p10le",
+ imageFormat: "png",
+ outputLocation: captionOverlay,
inputProps,
+ concurrency,
onProgress: ({ progress }) => {
- process.stderr.write(
- ` rendering: ${Math.round(progress * 100)}%\r`
- );
+ const pct = Math.round(progress * 100);
+ if (pct > lastPct + 9) {
+ lastPct = pct;
+ process.stderr.write(` captions: ${pct}%\n`);
+ }
},
});
- console.log(`\nDone: ${opts.output}`);
+ assetServer.close();
+
+ // Composite: overlay transparent captions (ProRes 4444 with alpha) onto video
+ const { execSync } = await import("child_process");
+ process.stderr.write(" compositing...\n");
+ execSync(
+ `ffmpeg -y -i "${path.resolve(opts.video)}" -i "${captionOverlay}" ` +
+ `-filter_complex "[0:v][1:v]overlay=0:0:shortest=1" ` +
+ `-c:v libx264 -crf 18 -preset fast -map 0:a -c:a copy "${opts.output}"`,
+ { stdio: ["pipe", "pipe", "inherit"], timeout: 300000 }
+ );
+
+ // Clean up overlay
+ try { fs.unlinkSync(captionOverlay); } catch {}
+ console.log(`Done: ${opts.output}`);
}
main().catch((err) => {
diff --git a/remotion/src/CaptionedClip.tsx b/remotion/src/CaptionedClip.tsx
index ebc8d56..04eefbb 100644
--- a/remotion/src/CaptionedClip.tsx
+++ b/remotion/src/CaptionedClip.tsx
@@ -26,14 +26,10 @@ export const CaptionedClip: React.FC<CaptionedClipProps> = ({
branded: BrandedCaptions,
}[style.name];
+ // Render captions only (transparent bg) — FFmpeg composites onto video later
+ // This is 10x faster than decoding video through Chrome
return (
- <AbsoluteFill style={{ backgroundColor: "black" }}>
- {videoSrc ? (
- <OffthreadVideo
- src={videoSrc.startsWith("http") ? videoSrc : staticFile(videoSrc)}
- style={{ width: "100%", height: "100%", objectFit: "cover" }}
- />
- ) : null}
+ <AbsoluteFill style={{ backgroundColor: "transparent" }}>
{style.name === "branded" ? (
<BrandedCaptions words={words} style={style} logoSrc={logoSrc} />
) : (
diff --git a/remotion/src/Root.tsx b/remotion/src/Root.tsx
index d47bd27..7101208 100644
--- a/remotion/src/Root.tsx
+++ b/remotion/src/Root.tsx
@@ -26,8 +26,8 @@ export const RemotionRoot: React.FC = () => {
component={CaptionedClip}
durationInFrames={durationInFrames}
fps={fps}
- width={2160}
- height={3840}
+ width={1080}
+ height={1920}
defaultProps={{
videoSrc: inputProps.videoSrc || "",
words: inputProps.words || [],
diff --git a/remotion/src/components/BrandedCaptions.tsx b/remotion/src/components/BrandedCaptions.tsx
index f4422e0..ab3af42 100644
--- a/remotion/src/components/BrandedCaptions.tsx
+++ b/remotion/src/components/BrandedCaptions.tsx
@@ -79,13 +79,13 @@ const WordWithPill: React.FC<{
<span
style={{
position: "absolute",
- top: -8,
- left: -32,
- right: -32,
- bottom: -8,
+ top: -4,
+ left: -16,
+ right: -16,
+ bottom: -4,
backgroundColor: "rgba(0, 0, 0, 0.85)",
- borderRadius: 36,
- boxShadow: "0 8px 40px rgba(0, 0, 0, 0.5)",
+ borderRadius: 18,
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.5)",
opacity: pillOpacity,
pointerEvents: "none",
}}
@@ -111,7 +111,7 @@ const CaptionLine: React.FC<{
fontSize: style.fontSize,
fontWeight: 400,
color: style.color,
- textShadow: "0 0 80px rgba(0, 0, 0, 0.15), 0 0 160px rgba(0, 0, 0, 0.1), 0 0 300px rgba(0, 0, 0, 0.08)",
+ textShadow: "0 0 40px rgba(0, 0, 0, 0.15), 0 0 80px rgba(0, 0, 0, 0.1), 0 0 150px rgba(0, 0, 0, 0.08)",
lineHeight: 1.25,
}}
>
@@ -156,10 +156,10 @@ export const BrandedCaptions: React.FC<Props> = ({
src={logoSrc.startsWith("http") ? logoSrc : staticFile(logoSrc)}
style={{
position: "absolute",
- top: 361,
- left: 216,
- width: 510,
- height: 252,
+ top: 180,
+ left: 108,
+ width: 255,
+ height: 126,
objectFit: "contain",
}}
/>
@@ -173,8 +173,8 @@ export const BrandedCaptions: React.FC<Props> = ({
style={{
position: "absolute",
bottom: style.marginBottom,
- left: 120,
- right: 120,
+ left: 60,
+ right: 60,
display: "flex",
flexDirection: "column",
alignItems: "center",
diff --git a/remotion/src/types.ts b/remotion/src/types.ts
index 186a8c3..cc09e5d 100644
--- a/remotion/src/types.ts
+++ b/remotion/src/types.ts
@@ -65,13 +65,13 @@ export const STYLES: Record<string, CaptionStyle> = {
},
branded: {
name: "branded",
- fontSize: 200,
+ fontSize: 100,
fontFamily: FONT,
color: "#FFFFFF",
activeColor: "#FFFFFF",
uppercase: false,
- wordsPerChunk: 5,
+ wordsPerChunk: 4,
position: "lower-third",
- marginBottom: 850,
+ marginBottom: 420,
},
};