Open source CapCut alternative.
TypeScript
feat(site): in-tab export renders any length
David Le1afa912cfc8a
diff --git a/site/src/cut/components/ExportDialog.tsx b/site/src/cut/components/ExportDialog.tsxindex 182417b9..a65cbe10 100644--- a/site/src/cut/components/ExportDialog.tsx+++ b/site/src/cut/components/ExportDialog.tsx@@ -59,7 +59,7 @@ export function ExportDialog() {const selected = presets.find((p) => p.id === presetId) ?? presets[0];// A browser-resident project has exactly one renderer: this tab. Ask up- // front whether the tab can hold this cut at the chosen size, so a refusal+ // front whether the browser can encode at the chosen size, so a refusal// is a message here instead of an error card after the dialog closed.const cutMode = useCutMode();const [fits, setFits] = useState(true);@@ -151,7 +151,7 @@ export function ExportDialog() {<p className="text-center text-[11px] text-muted-foreground">{fits? "Renders in the background. You can keep editing, open another project, or export more — each shows in the corner."- : "This project is too big to export from this tab. Move it to Cloud (top bar) to export."}+ : "This browser can't export at this size. Move the project to Cloud (top bar) to export."}</p></DialogFooter></DialogContent>diff --git a/site/src/cut/lib/exportRender.ts b/site/src/cut/lib/exportRender.tsindex febf85bd..5f037a4e 100644--- a/site/src/cut/lib/exportRender.ts+++ b/site/src/cut/lib/exportRender.ts@@ -871,26 +871,20 @@ async function drawStamps(}/**- * Whether this render should happen in the tab.- *- * Three things have to hold. The cut has to be one a tab can carry — past ten- * minutes or 4K it belongs on the worker, which has a whole machine rather than- * a share of one. The browser has to offer scratch storage, because the render- * writes its file to origin-private disk rather than the heap. And the browser- * has to actually be able to encode it: whether WebCodecs offers a video- * encoder for these dimensions is a fact about the browser, not about the- * project, and asking after the render has already been routed here leaves- * nowhere to go. Answering all three first means a browser that cannot carry- * the render quietly renders on the worker, the way every cloud export did- * before this path existed.+ * Whether this browser can render the export at all. Two facts decide it,+ * both about the browser: it has to offer scratch storage, because the render+ * writes its file to origin-private disk, and WebCodecs has to offer a video+ * encoder at these dimensions. A cut of any length renders in the tab — the+ * pipeline streams to disk, so duration costs time, and the answer here has+ * to be known up front because a cloud project whose browser can't carry the+ * render quietly renders on the worker instead.*/export async function canRenderInBrowser(doc: ExportDoc,settings: ExportSettings): Promise<boolean> {const duration = projectDuration(doc);- const pixels = settings.width * settings.height;- if (!(duration > 0) || duration > 10 * 60 || pixels > 3840 * 2160) return false;+ if (!(duration > 0)) return false;if (typeof navigator.storage?.getDirectory !== "function" ||typeof FileSystemFileHandle === "undefined" ||diff --git a/site/src/cut/lib/exportStore.ts b/site/src/cut/lib/exportStore.tsindex 4e55f2ee..fed5c675 100644--- a/site/src/cut/lib/exportStore.ts+++ b/site/src/cut/lib/exportStore.ts@@ -109,9 +109,10 @@ export const useExports = create<ExportsState>((set, get) => ({const backend = getBackend();// A cloud project renders in the tab: no upload of the cut to a container,// no queue behind other accounts, and the file matches the preview because- // the same compositor drew both. Past what a tab can hold — a long cut, a- // very large frame — it goes to the worker, which has a whole machine. A- // browser-resident project renders in the tab too; the tab is its machine.+ // the same compositor drew both. A browser that can't carry the render —+ // no encoder at these dimensions, no scratch storage — sends it to the+ // worker, which has a whole machine. A browser-resident project renders in+ // the tab too; the tab is its machine.const inBrowser =(backend.kind === "cloud" || backend.kind === "browser") &&(await canRenderInBrowser(doc, settings));@@ -140,17 +141,19 @@ export const useExports = create<ExportsState>((set, get) => ({};const fail = (err: unknown) => {const msg = err instanceof Error ? err.message : String(err);+ // A browser-resident project has exactly one other renderer, so a failed+ // render says where to take it.+ const hint = " Move the project to Cloud to export.";+ const full = backend.kind === "browser" && !msg.includes(hint) ? msg + hint : msg;set((s) => ({local: s.local.map((r) =>- r.id === localId ? { ...r, status: "error" as const, error: msg, abort: undefined } : r+ r.id === localId ? { ...r, status: "error" as const, error: full, abort: undefined } : r),}));};try {if (backend.kind === "browser" && !inBrowser) {- throw new Error(- "This project is too big to export from this tab. Move it to Cloud to export."- );+ throw new Error("This browser can't render this export.");}if (inBrowser) {await runBrowserExport(projectId, doc, settings, {