Skip to content

Open source CapCut alternative.

TypeScript

feat(site): add Original (match-source, up to 4K) export preset

David Le1b534e562458
diff --git a/site/src/cut/components/ExportDialog.tsx b/site/src/cut/components/ExportDialog.tsx
index 4a3ea897..0ef86a4f 100644
--- a/site/src/cut/components/ExportDialog.tsx
+++ b/site/src/cut/components/ExportDialog.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useRef, useState } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import { Check, FolderCheck } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
@@ -10,7 +10,13 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
-import { EXPORT_PRESETS, presetSettings, startExport, type ExportHandle } from "@/cut/lib/exportClient";
+import {
+ EXPORT_PRESETS,
+ originalSettings,
+ presetSettings,
+ startExport,
+ type ExportHandle,
+} from "@/cut/lib/exportClient";
import { useEditor } from "@/cut/lib/store";
import { cn } from "@/lib/utils";
@@ -23,7 +29,28 @@ type Phase =
export function ExportDialog() {
const setExportOpen = useEditor((s) => s.setExportOpen);
const aspect = useEditor((s) => s.aspect);
- const [presetId, setPresetId] = useState<string>(EXPORT_PRESETS[0].id);
+ const clips = useEditor((s) => s.clips);
+ const assets = useEditor((s) => s.assets);
+ // "Original" leads: sized from the footage on the timeline, so it is always
+ // the highest option. The fixed presets follow, flipped to the aspect.
+ const presets = useMemo(
+ () => [
+ {
+ id: "original",
+ label: "Original · matches source",
+ detail: "H.264 · best quality",
+ settings: originalSettings(aspect, clips, assets),
+ },
+ ...EXPORT_PRESETS.map((p) => ({
+ id: p.id,
+ label: p.label,
+ detail: p.detail,
+ settings: presetSettings(p, aspect),
+ })),
+ ],
+ [aspect, clips, assets]
+ );
+ const [presetId, setPresetId] = useState("original");
const [phase, setPhase] = useState<Phase>({ kind: "idle" });
const handleRef = useRef<ExportHandle | null>(null);
@@ -35,9 +62,9 @@ export function ExportDialog() {
};
const run = () => {
- const preset = EXPORT_PRESETS.find((p) => p.id === presetId) ?? EXPORT_PRESETS[0];
const s = useEditor.getState();
if (!s.projectId) return;
+ const settings = (presets.find((p) => p.id === presetId) ?? presets[0]).settings;
const handle = startExport(
s.projectId,
{
@@ -47,7 +74,7 @@ export function ExportDialog() {
overlays: s.overlays,
subtitles: s.subtitles,
},
- presetSettings(preset, s.aspect),
+ settings,
(stage, ratio) => setPhase({ kind: "running", stage, ratio })
);
handleRef.current = handle;
@@ -68,9 +95,7 @@ export function ExportDialog() {
{phase.kind === "idle" && (
<>
<div className="flex flex-col gap-2" role="radiogroup" aria-label="Export preset">
- {EXPORT_PRESETS.map((p) => {
- const dims = presetSettings(p, aspect);
- return (
+ {presets.map((p) => (
<button
key={p.id}
role="radio"
@@ -83,11 +108,10 @@ export function ExportDialog() {
>
<span className="text-sm font-medium">{p.label}</span>
<span className="text-xs text-muted-foreground">
- {dims.width} × {dims.height} · {p.detail}
+ {p.settings.width} × {p.settings.height} · {p.detail}
</span>
</button>
- );
- })}
+ ))}
</div>
<DialogFooter>
<Button className="w-full" onClick={run}>
diff --git a/site/src/cut/lib/exportClient.ts b/site/src/cut/lib/exportClient.ts
index c8b1aee7..725097cc 100644
--- a/site/src/cut/lib/exportClient.ts
+++ b/site/src/cut/lib/exportClient.ts
@@ -4,6 +4,7 @@ import { apiFetch, apiUrl } from "./api";
import { getClipSpans, totalDuration } from "./store";
import { cueOverlay } from "./subtitles";
import { renderOverlayPng } from "./textRender";
+import { FRAME } from "./types";
import type { Aspect, AudioClip, MediaAsset, SubtitlesBlock, TextOverlay, VideoClip } from "./types";
export interface ExportSettings {
@@ -46,6 +47,45 @@ export function presetSettings(
: { width, height, ...rest };
}
+/**
+ * "Original": the highest resolution the timeline's own footage justifies,
+ * along the project aspect. It scales the 1080p base by the sharpest source
+ * clip — never below the base (so it is always the highest option), never
+ * above 4K, and never upscaled past the source. Unknown source sizes fall
+ * back to the base.
+ */
+export function originalSettings(
+ aspect: Aspect,
+ clips: VideoClip[],
+ assets: MediaAsset[]
+): ExportSettings {
+ const base = FRAME[aspect];
+ const srcLong = Math.max(
+ 0,
+ ...getClipSpans(clips, assets).map((sp) =>
+ Math.max(sp.asset.width ?? 0, sp.asset.height ?? 0)
+ )
+ );
+ const k = Math.min(2, Math.max(1, srcLong / Math.max(base.w, base.h) || 1));
+ const even = (n: number) => 2 * Math.round((n * k) / 2);
+ return { width: even(base.w), height: even(base.h), fps: 30, crf: 19, preset: "medium" };
+}
+
+/** Reveal a rendered export in Finder (local engine only). */
+export async function revealExport(projectId: string, file: string) {
+ await apiFetch(
+ `/api/cut/projects/${projectId}/exports/${encodeURIComponent(file)}/reveal`,
+ { method: "POST" }
+ );
+}
+
+/** Delete a rendered export from the project folder. */
+export async function deleteExport(projectId: string, file: string) {
+ await apiFetch(`/api/cut/projects/${projectId}/exports/${encodeURIComponent(file)}`, {
+ method: "DELETE",
+ });
+}
+
export interface ExportHandle {
cancel: () => void;
done: Promise<{ outName: string }>;