Skip to content

Open source CapCut alternative.

TypeScript

feat(site): every video track is treated the same — one clip panel, full audio parity [rebuild]

David Le22f2a5528030
diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsx
index a2159a9a..3db390ee 100644
--- a/site/src/cut/components/Inspector.tsx
+++ b/site/src/cut/components/Inspector.tsx
@@ -24,7 +24,7 @@ import {
TooltipTrigger,
} from "@/components/ui/tooltip";
import { Textarea } from "@/components/ui/textarea";
-import { baseClips, getClipSpans, useEditor, type EditorState } from "@/cut/lib/store";
+import { baseClips, clipWindow, useEditor, type EditorState } from "@/cut/lib/store";
import { GenerateSubtitlesAudio } from "@/cut/components/VoicePicker";
import {
parseNumberInput,
@@ -177,13 +177,7 @@ export function Inspector() {
return (
<aside className="flex min-h-0 flex-col overflow-y-auto border-l border-border bg-card">
{clip ? (
- // The base row (track 0) carries transitions and the sequence controls;
- // a layer clip gets the compositing panel (track, framing, layout).
- clip.track === 0 ? (
- <ClipPanel key={clip.id} clip={clip} />
- ) : (
- <LayerClipPanel key={clip.id} clip={clip} />
- )
+ <ClipPanel key={clip.id} clip={clip} />
) : audio ? (
<AudioPanel key={audio.id} clip={audio} />
) : overlay ? (
@@ -325,54 +319,6 @@ function ClipPanel({ clip }: { clip: VideoClip }) {
const [xfadeDraft, setXfadeDraft] = useState<number | null>(null);
const [volumeDraft, setVolumeDraft] = useState<number | null>(null);
const volume = volumeDraft ?? clip.volume ?? 1;
- // Subtitle cues overlapping this clip's timeline span, for the per-clip
- // readout. A selector rather than a snapshot so the generate button reads
- // fresh ids after it auto-transcribes the cut.
- const selectClipCueIds = useCallback(
- (s: EditorState) => {
- const sp = getClipSpans(s.clips, s.assets).find((x) => x.clip.id === clip.id);
- if (!sp) return [];
- return s.subtitles.cues
- .filter((c) => c.text.trim() && c.end > sp.start && c.start < sp.start + sp.len)
- .map((c) => c.id);
- },
- [clip.id]
- );
- const ensureClipCues = useCallback(
- () => useEditor.getState().generateClipSubtitles(clip.id),
- [clip.id]
- );
- // Generated voiceover clips overlapping this clip's span — the "Generated
- // audio" slider drives them all, so clip sound and voiceover balance from one
- // panel. Same joined-string trick as the cue ids for reference stability.
- const [genVolDraft, setGenVolDraft] = useState<number | null>(null);
- const genCk = useSliderCheckpoint();
- const genAudioKey = useEditor((s) => {
- const sp = getClipSpans(s.clips, s.assets).find((x) => x.clip.id === clip.id);
- if (!sp) return "";
- // AI-voice audio regardless of where it was made: the Audio panel tags
- // voiceovers, the chat tags its own — both are voice over this clip.
- const voiceAssets = new Set(
- s.assets
- .filter((a) => a.origin === "voiceover" || (a.origin === "chat" && a.type === "audio"))
- .map((a) => a.id)
- );
- return s.audioClips
- .filter((a) => {
- const len = (a.out - a.in) / (a.speed && a.speed > 0 ? a.speed : 1);
- return (
- voiceAssets.has(a.assetId) && a.start < sp.start + sp.len && a.start + len > sp.start
- );
- })
- .map((a) => a.id)
- .join("\n");
- });
- const genAudioIds = useMemo(() => (genAudioKey ? genAudioKey.split("\n") : []), [genAudioKey]);
- const genVolStore = useEditor((s) => {
- const first = s.audioClips.find((a) => a.id === genAudioIds[0]);
- return first ? first.volume : 1;
- });
- const genVol = genVolDraft ?? genVolStore;
const speed = speedDraft ?? clip.speed ?? 1;
const xfade = xfadeDraft ?? clip.transition ?? 0;
const speedLen = (clip.out - clip.in) / (speed > 0 ? speed : 1);
@@ -420,6 +366,22 @@ function ClipPanel({ clip }: { clip: VideoClip }) {
/>
)}
</Row>
+ <Row label="Starts at">
+ <ScrubValue
+ label="Starts at"
+ value={clip.start}
+ min={0}
+ max={Infinity}
+ step={0.1}
+ keyStep={1}
+ format={formatTime}
+ parse={parseTimeInput}
+ onCommit={(v) => {
+ updateClip(clip.id, { start: Math.max(0, v) });
+ useEditor.getState().sortClips();
+ }}
+ />
+ </Row>
<Row label="Speed">
<Slider
className="clip-speed data-horizontal:w-24"
@@ -645,62 +607,120 @@ function ClipPanel({ clip }: { clip: VideoClip }) {
rect={rectOf(clip)}
onPick={(frame, fit) => updateClip(clip.id, { frame, fit })}
/>
- <div className="mt-2 flex flex-col gap-1 border-t border-border pt-3">
- <GenerateSubtitlesAudio
- selectCueIds={selectClipCueIds}
- ensureCues={ensureClipCues}
- label="Generate audio for clip"
- />
- {genAudioIds.length > 0 && (
- <Row label="Volume">
- <Slider
- className="clip-gen-volume data-horizontal:w-24"
- min={0}
- max={1.5}
- step={0.05}
- value={genVol}
- onValueChange={(v) => {
- genCk.begin();
- setGenVolDraft(Number(v));
- const s = useEditor.getState();
- genAudioIds.forEach((id) => s.updateAudioTransient(id, { volume: Number(v) }));
- }}
- onValueCommitted={() => {
- genCk.end();
- setGenVolDraft(null);
- }}
- />
- <ScrubValue
- label="Generated audio volume"
- className="w-9 text-muted-foreground"
- value={genVol}
- min={0}
- max={1.5}
- step={0.05}
- format={formatPercent}
- parse={parsePercentInput}
- onScrub={(v) => {
- genCk.begin();
- setGenVolDraft(v);
- const s = useEditor.getState();
- genAudioIds.forEach((id) => s.updateAudioTransient(id, { volume: v }));
- }}
- onCommit={(v) => {
- genCk.begin();
- const s = useEditor.getState();
- genAudioIds.forEach((id) => s.updateAudioTransient(id, { volume: v }));
- genCk.end();
- setGenVolDraft(null);
- }}
- />
- </Row>
- )}
- </div>
+ <ClipGeneratedAudio clip={clip} />
</div>
</>
);
}
+/** Per-clip generated-audio block: the voice picker, "Generate audio for clip"
+ * (which transcribes just this clip when it has no cues yet), and one volume
+ * slider driving the voiceovers laid over the clip. Shared by the base-row and
+ * layer clip panels. */
+function ClipGeneratedAudio({ clip }: { clip: VideoClip }) {
+ // Subtitle cues overlapping this clip's timeline span, for the per-clip
+ // readout. A selector rather than a snapshot so the generate button reads
+ // fresh ids after it auto-transcribes the cut.
+ const selectClipCueIds = useCallback(
+ (s: EditorState) => {
+ const sp = clipWindow(s.clips, s.assets, clip.id);
+ if (!sp) return [];
+ return s.subtitles.cues
+ .filter((c) => c.text.trim() && c.end > sp.start && c.start < sp.start + sp.len)
+ .map((c) => c.id);
+ },
+ [clip.id]
+ );
+ const ensureClipCues = useCallback(
+ () => useEditor.getState().generateClipSubtitles(clip.id),
+ [clip.id]
+ );
+ // Generated voiceover clips overlapping this clip's span — the "Generated
+ // audio" slider drives them all, so clip sound and voiceover balance from one
+ // panel. Same joined-string trick as the cue ids for reference stability.
+ const [genVolDraft, setGenVolDraft] = useState<number | null>(null);
+ const genCk = useSliderCheckpoint();
+ const genAudioKey = useEditor((s) => {
+ const sp = clipWindow(s.clips, s.assets, clip.id);
+ if (!sp) return "";
+ // AI-voice audio regardless of where it was made: the Audio panel tags
+ // voiceovers, the chat tags its own — both are voice over this clip.
+ const voiceAssets = new Set(
+ s.assets
+ .filter((a) => a.origin === "voiceover" || (a.origin === "chat" && a.type === "audio"))
+ .map((a) => a.id)
+ );
+ return s.audioClips
+ .filter((a) => {
+ const len = (a.out - a.in) / (a.speed && a.speed > 0 ? a.speed : 1);
+ return (
+ voiceAssets.has(a.assetId) && a.start < sp.start + sp.len && a.start + len > sp.start
+ );
+ })
+ .map((a) => a.id)
+ .join("\n");
+ });
+ const genAudioIds = useMemo(() => (genAudioKey ? genAudioKey.split("\n") : []), [genAudioKey]);
+ const genVolStore = useEditor((s) => {
+ const first = s.audioClips.find((a) => a.id === genAudioIds[0]);
+ return first ? first.volume : 1;
+ });
+ const genVol = genVolDraft ?? genVolStore;
+ return (
+ <div className="mt-2 flex flex-col gap-1 border-t border-border pt-3">
+ <GenerateSubtitlesAudio
+ selectCueIds={selectClipCueIds}
+ ensureCues={ensureClipCues}
+ label="Generate audio for clip"
+ />
+ {genAudioIds.length > 0 && (
+ <Row label="Volume">
+ <Slider
+ className="clip-gen-volume data-horizontal:w-24"
+ min={0}
+ max={1.5}
+ step={0.05}
+ value={genVol}
+ onValueChange={(v) => {
+ genCk.begin();
+ setGenVolDraft(Number(v));
+ const s = useEditor.getState();
+ genAudioIds.forEach((id) => s.updateAudioTransient(id, { volume: Number(v) }));
+ }}
+ onValueCommitted={() => {
+ genCk.end();
+ setGenVolDraft(null);
+ }}
+ />
+ <ScrubValue
+ label="Generated audio volume"
+ className="w-9 text-muted-foreground"
+ value={genVol}
+ min={0}
+ max={1.5}
+ step={0.05}
+ format={formatPercent}
+ parse={parsePercentInput}
+ onScrub={(v) => {
+ genCk.begin();
+ setGenVolDraft(v);
+ const s = useEditor.getState();
+ genAudioIds.forEach((id) => s.updateAudioTransient(id, { volume: v }));
+ }}
+ onCommit={(v) => {
+ genCk.begin();
+ const s = useEditor.getState();
+ genAudioIds.forEach((id) => s.updateAudioTransient(id, { volume: v }));
+ genCk.end();
+ setGenVolDraft(null);
+ }}
+ />
+ </Row>
+ )}
+ </div>
+ );
+}
+
function AudioPanel({ clip }: { clip: AudioClip }) {
const asset = useEditor((s) => s.assets.find((a) => a.id === clip.assetId));
const updateAudioTransient = useEditor((s) => s.updateAudioTransient);
@@ -916,139 +936,6 @@ function AudioPanel({ clip }: { clip: AudioClip }) {
);
}
-function LayerClipPanel({ clip }: { clip: VideoClip }) {
- const asset = useEditor((s) => s.assets.find((a) => a.id === clip.assetId));
- const update = useEditor((s) => s.updateOverlayClip);
- const updateTransient = useEditor((s) => s.updateOverlayClipTransient);
- const ck = useSliderCheckpoint();
- const speed = clip.speed && clip.speed > 0 ? clip.speed : 1;
- const len = (clip.out - clip.in) / speed;
- const maxOut = asset && asset.type !== "image" ? asset.duration : Infinity;
- const setLayer = (patch: Partial<VideoClip>) => {
- ck.begin();
- updateTransient(clip.id, patch);
- };
- const commitLayer = (patch: Partial<VideoClip>) => {
- setLayer(patch);
- ck.end();
- };
- return (
- <>
- <PanelTitle>Video clip</PanelTitle>
- <div className="flex flex-col gap-1 px-3.5 pb-4">
- <div className="mb-1.5 flex items-baseline justify-between gap-2 border-b border-border pb-2.5">
- <div className="truncate text-xs font-medium" title={asset?.name}>
- {asset?.name}
- </div>
- <Value className="shrink-0 text-muted-foreground">{formatTime(len)}</Value>
- </div>
- <Row label="Trim">
- <ScrubValue
- label="Trim start"
- value={clip.in}
- min={0}
- max={clip.out - MIN_TRIM}
- step={0.1}
- keyStep={1}
- format={formatTime}
- parse={parseTimeInput}
- onCommit={(v) => commitLayer({ in: v })}
- />
- <Value className="text-muted-foreground">–</Value>
- <ScrubValue
- label="Trim end"
- value={clip.out}
- min={clip.in + MIN_TRIM}
- max={maxOut}
- step={0.1}
- keyStep={1}
- format={formatTime}
- parse={parseTimeInput}
- onCommit={(v) => commitLayer({ out: v })}
- />
- {Number.isFinite(maxOut) && (clip.in > 1e-3 || clip.out < maxOut - 1e-3) && (
- <ResetButton
- title="Reset trim"
- onClick={() => commitLayer({ in: 0, out: maxOut })}
- />
- )}
- </Row>
- <Row label="Starts at">
- <ScrubValue
- label="Starts at"
- value={clip.start}
- min={0}
- max={Infinity}
- step={0.1}
- keyStep={1}
- format={formatTime}
- parse={parseTimeInput}
- onCommit={(v) => commitLayer({ start: v })}
- />
- </Row>
- <Row label="Speed">
- <Slider
- className="layer-speed data-horizontal:w-24"
- min={SPEED_MIN}
- max={SPEED_MAX}
- step={0.05}
- value={speed}
- onValueChange={(v) => {
- ck.begin();
- const n = Number(v);
- updateTransient(clip.id, { speed: Math.abs(n - 1) < 1e-4 ? undefined : n });
- }}
- onValueCommitted={ck.end}
- />
- <ScrubValue
- label="Speed"
- className="w-9 text-muted-foreground"
- value={speed}
- min={SPEED_FLOOR}
- max={Infinity}
- step={0.05}
- format={formatSpeed}
- parse={parseSpeedInput}
- onScrub={(v) => setLayer({ speed: Math.abs(v - 1) < 1e-4 ? undefined : v })}
- onCommit={(v) => commitLayer({ speed: Math.abs(v - 1) < 1e-4 ? undefined : v })}
- />
- {Math.abs(speed - 1) > 1e-4 && (
- <ResetButton title="Reset speed" onClick={() => commitLayer({ speed: undefined })} />
- )}
- </Row>
- <LayoutButtons
- rect={rectOf(clip)}
- onPick={(frame, fit) => update(clip.id, { frame, fit })}
- />
- <Row label="Framing">
- <div className="flex rounded-lg border border-input p-0.5">
- {(["fit", "fill"] as const).map((mode) => (
- <button
- key={mode}
- className={cn(
- "rounded-md px-2.5 py-1 text-[11.5px] font-medium transition-colors",
- (clip.fit ?? "fit") === mode
- ? "bg-neutral-900 text-white"
- : "text-muted-foreground hover:text-foreground"
- )}
- onClick={() => update(clip.id, { fit: mode })}
- >
- {mode === "fit" ? "Fit" : "Fill"}
- </button>
- ))}
- </div>
- </Row>
- <Row label="Mute audio">
- <Switch checked={clip.muted} onCheckedChange={(v) => update(clip.id, { muted: v })} />
- </Row>
- <Row label="Hidden">
- <Switch checked={!!clip.hidden} onCheckedChange={(v) => update(clip.id, { hidden: v })} />
- </Row>
- </div>
- </>
- );
-}
-
function TextPanel({ overlay: o }: { overlay: TextOverlay }) {
const update = useEditor((s) => s.updateOverlay);
const sizeCk = useSliderCheckpoint();
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsx
index 13a7592b..70a0afa9 100644
--- a/site/src/cut/components/Timeline.tsx
+++ b/site/src/cut/components/Timeline.tsx
@@ -1994,7 +1994,7 @@ function OverlayClipView({
<MuteChip
muted={clip.muted}
className="bottom-1 left-1"
- onToggle={() => useEditor.getState().updateOverlayClip(clip.id, { muted: !clip.muted })}
+ onToggle={() => useEditor.getState().updateClip(clip.id, { muted: !clip.muted })}
/>
)}
{(clip.speed ?? 1) !== 1 && (
@@ -2009,7 +2009,7 @@ function OverlayClipView({
<HideChip
hidden={!!clip.hidden}
className="bottom-1 right-2"
- onToggle={() => useEditor.getState().updateOverlayClip(clip.id, { hidden: !clip.hidden })}
+ onToggle={() => useEditor.getState().updateClip(clip.id, { hidden: !clip.hidden })}
/>
<span
className={cn(trimHandle, "tl-trim-l left-0")}
diff --git a/site/src/cut/hooks/usePlayback.ts b/site/src/cut/hooks/usePlayback.ts
index ba6fcce0..c269982c 100644
--- a/site/src/cut/hooks/usePlayback.ts
+++ b/site/src/cut/hooks/usePlayback.ts
@@ -353,11 +353,7 @@ class Engine {
}
private overlayVideoFor(clip: VideoClip, asset: MediaAsset): MediaEl {
- const had = this.overlayEls.get(clip.id);
- const el = this.elFor(this.overlayEls, clip.id, asset);
- // Overlay audio is mixed on export, not previewed here.
- if (el !== had && !isImageEl(el)) el.muted = true;
- return el;
+ return this.elFor(this.overlayEls, clip.id, asset);
}
private clearCanvas() {
@@ -432,6 +428,14 @@ class Engine {
const target = clip.in + Math.max(0, t - clip.start) * speed;
const tol = play ? 0.34 : 0.05;
if (Math.abs(el.currentTime - target) > tol && !el.seeking) el.currentTime = target;
+ // Overlay audio previews like the export mixes it: the clip's own volume,
+ // ducked under a live voiceover, silent when muted. (The tick dims it
+ // further with the project fade.)
+ el.muted = !!clip.muted;
+ el.volume = Math.max(
+ 0,
+ Math.min(1, (clip.volume ?? 1) * duckGainAt(useEditor.getState().audioClips, t))
+ );
if (play) {
if (el.paused && el.readyState >= 2) void el.play().catch(() => {});
} else if (!el.paused) {
@@ -726,9 +730,14 @@ class Engine {
// The whole-video fade veils the finished frame and dims the sound —
// the master's element volume (set by composite) and the soundtrack.
const fadeGain = this.projectFadeGain(t, total);
- if (fadeGain < 1 && span) {
- const mel = this.videoEls.get(span.clip.id);
- if (mel && !isImageEl(mel)) mel.volume = Math.min(mel.volume, fadeGain);
+ if (fadeGain < 1) {
+ if (span) {
+ const mel = this.videoEls.get(span.clip.id);
+ if (mel && !isImageEl(mel)) mel.volume = Math.min(mel.volume, fadeGain);
+ }
+ for (const el of this.overlayEls.values()) {
+ if (!isImageEl(el)) el.volume = Math.min(el.volume, fadeGain);
+ }
}
this.drawProjectFade(fadeGain);
this.cleanupOverlays(active);
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index 23dc1330..f789812d 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -327,7 +327,7 @@ export async function runAiTool(
if (!id) throw new ToolError("Could not create the overlay clip.");
// Same undo step as the add: the layout rides the transient patch.
if (typeof input.layout === "string")
- cur.updateOverlayClipTransient(id, layoutPatch(input.layout));
+ cur.updateClipTransient(id, layoutPatch(input.layout));
const c = useEditor.getState().clips.find((x) => x.id === id)!;
return {
id: c.id,
@@ -371,7 +371,7 @@ export async function runAiTool(
if (input.fit === "fit" || input.fit === "fill") patch.fit = input.fit;
if (isNum(input.speed)) patch.speed = Math.max(SPEED_FLOOR, input.speed);
if (Object.keys(patch).length === 0) throw new ToolError("Nothing to change.");
- s.updateOverlayClip(c.id, patch);
+ s.updateClip(c.id, patch);
const next = useEditor.getState().clips.find((x) => x.id === c.id)!;
return {
id: next.id,
@@ -417,10 +417,6 @@ export async function runAiTool(
const id = input.clipId ? String(input.clipId) : s.selection?.kind === "clip" ? s.selection.id : null;
if (!id) throw new ToolError("Pass clipId or select a video clip first.");
const clip = requireItem(s.clips, id, "video clip");
- // detachAudio lifts sound off the base sequence; a layer clip has no
- // span there and the store would silently do nothing.
- if (clip.track !== 0)
- throw new ToolError("That clip is on an overlay track — detach works on timeline (track 0) clips.");
if (clip.muted) throw new ToolError("That clip's audio is muted — nothing to detach.");
s.select({ kind: "clip", id: clip.id });
s.detachAudio();
diff --git a/site/src/cut/lib/exportClient.ts b/site/src/cut/lib/exportClient.ts
index 3577524d..215761f6 100644
--- a/site/src/cut/lib/exportClient.ts
+++ b/site/src/cut/lib/exportClient.ts
@@ -238,6 +238,7 @@ async function buildExportForm(
// covers what's below" branch fires — normalizing to "fit" defeated it.
fit: c.fit,
muted: c.muted,
+ volume: c.volume,
speed: c.speed,
image: assetById.get(c.assetId)!.type === "image",
}));
diff --git a/site/src/cut/lib/laneTracks.ts b/site/src/cut/lib/laneTracks.ts
index 4bda2880..04e284bc 100644
--- a/site/src/cut/lib/laneTracks.ts
+++ b/site/src/cut/lib/laneTracks.ts
@@ -173,7 +173,7 @@ const overlayClipAdapter: LaneAdapter<VideoClip> = {
multiLane: false,
raws: (s) => overlayLayers(s.clips),
view: (c) => ({ id: c.id, start: c.start, len: clipLen(c), lane: c.track }),
- apply: (patches) => useEditor.getState().updateOverlayClipsTransient(patches),
+ apply: (patches) => useEditor.getState().updateClipsTransient(patches),
movePatch: (c, start) => ({ id: c.id, patch: { start } }),
trimLeftPatch: (c, newStart) => ({
id: c.id,
diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.ts
index 5d16936e..440e6622 100644
--- a/site/src/cut/lib/store.ts
+++ b/site/src/cut/lib/store.ts
@@ -199,9 +199,6 @@ export interface EditorState {
* and push whole lanes at a time (one bulk patcher per lane-track kind). */
updateOverlaysTransient: (patches: { id: string; patch: Partial<TextOverlay> }[]) => void;
updateAudiosTransient: (patches: { id: string; patch: Partial<AudioClip> }[]) => void;
- /** Bulk-patch layer (non-base-track) clips in one commit — the lane
- * coordinator parts and pushes a whole track at a time. */
- updateOverlayClipsTransient: (patches: { id: string; patch: Partial<VideoClip> }[]) => void;
updateCuesTransient: (patches: { id: string; patch: Partial<SubtitleCue> }[]) => void;
updateClipsTransient: (patches: { id: string; patch: Partial<VideoClip> }[]) => void;
updateClipTransient: (id: string, patch: Partial<VideoClip>) => void;
@@ -220,8 +217,6 @@ export interface EditorState {
* Inserting a track renumbers the ones above it; dropping onto track 0 lands
* free-positioned at the drop time. Owns its own history. */
dropVideoClip: (id: string, place: VideoTrackPlacement, start: number) => void;
- updateOverlayClip: (id: string, patch: Partial<VideoClip>) => void;
- updateOverlayClipTransient: (id: string, patch: Partial<VideoClip>) => void;
/** iMovie "Detach Audio": lift the selected clip's sound onto the
* soundtrack track (and mute the clip) so it can be cut independently. */
detachAudio: () => void;
@@ -1064,17 +1059,6 @@ export const useEditor = create<EditorState>((set, get) => {
};
}),
- updateOverlayClipsTransient: (patches) =>
- set((s) => {
- const byId = new Map(patches.map((p) => [p.id, p.patch]));
- return {
- clips: s.clips.map((c) => {
- const patch = byId.get(c.id);
- return patch ? { ...c, ...patch } : c;
- }),
- };
- }),
-
updateCuesTransient: (patches) =>
set((s) => {
const byId = new Map(patches.map((p) => [p.id, p.patch]));
@@ -1220,22 +1204,12 @@ export const useEditor = create<EditorState>((set, get) => {
});
},
- updateOverlayClip: (id, patch) => {
- push();
- get().updateOverlayClipTransient(id, patch);
- },
-
- updateOverlayClipTransient: (id, patch) =>
- set((s) => ({
- clips: s.clips.map((c) => (c.id === id ? { ...c, ...patch } : c)),
- })),
-
detachAudio: () => {
const { clips, assets, selection } = get();
if (selection?.kind !== "clip") return;
const clip = clips.find((c) => c.id === selection.id);
if (!clip || clip.muted) return; // no sound to detach
- const span = getClipSpans(clips, assets).find((sp) => sp.clip.id === clip.id);
+ const span = clipWindow(clips, assets, clip.id);
if (!span) return;
push();
const audio: AudioClip = {
@@ -1785,7 +1759,7 @@ export const useEditor = create<EditorState>((set, get) => {
throw new Error("Subtitles are already generating — try again in a moment.");
}
const projectId = s.projectId;
- const sp = getClipSpans(s.clips, s.assets).find((x) => x.clip.id === clipId);
+ const sp = clipWindow(s.clips, s.assets, clipId);
if (!sp) throw new Error("The clip is no longer on the timeline.");
const lane = s.subtitleLane;
const epoch = laneEpoch;
@@ -2505,6 +2479,24 @@ export function getClipSpans(
return spans;
}
+/** One video clip's timeline window with its asset, wherever the clip lives:
+ * track-0 clips read theirs off the span fold, layer clips straight from their
+ * own placement. Null when the clip or its asset is gone. */
+export function clipWindow(
+ clips: VideoClip[],
+ assets: MediaAsset[],
+ clipId: string
+): { clip: VideoClip; asset: MediaAsset; start: number; len: number } | null {
+ const clip = clips.find((c) => c.id === clipId);
+ if (!clip) return null;
+ if (clip.track === 0) {
+ const sp = getClipSpans(clips, assets).find((x) => x.clip.id === clipId);
+ return sp ? { clip: sp.clip, asset: sp.asset, start: sp.start, len: sp.len } : null;
+ }
+ const asset = assets.find((a) => a.id === clip.assetId);
+ return asset ? { clip, asset, start: clip.start, len: clipLen(clip) } : null;
+}
+
/** End of video track 0: where its last clip runs out (clips are free-placed,
* so gaps count toward this, they just play black). */
export function totalDuration(clips: VideoClip[]) {
diff --git a/site/src/cut/server/jobs.ts b/site/src/cut/server/jobs.ts
index 77c2e165..dc261d0b 100644
--- a/site/src/cut/server/jobs.ts
+++ b/site/src/cut/server/jobs.ts
@@ -62,6 +62,8 @@ export interface ExportSpec {
frame?: { x: number; y: number; w: number; h: number };
fit?: "fit" | "fill";
muted: boolean;
+ /** Gain on the clip's own audio, 0..1.5; absent = 1 (unchanged). */
+ volume?: number;
speed?: number;
/** A still image: looped for the clip's length instead of trimmed. */
image?: boolean;
@@ -663,10 +665,11 @@ async function runExport(job: Job, spec: ExportSpec) {
);
if (!oc.muted && audioPresence.get(oc.file)) {
const tempo = ospeed !== 1 ? `${atempoChain(ospeed)},` : "";
+ const vol = (oc.volume ?? 1) !== 1 ? `volume=${num(oc.volume ?? 1)},` : "";
const delayMs = Math.max(0, Math.round(oc.start * 1000));
const lab = `ovs${k}`;
filters.push(
- `[${idx}:a]atrim=${num(oc.in)}:${num(oc.out)},asetpts=PTS-STARTPTS,${tempo}` +
+ `[${idx}:a]atrim=${num(oc.in)}:${num(oc.out)},asetpts=PTS-STARTPTS,${tempo}${vol}` +
`aresample=44100,aformat=sample_fmts=fltp:channel_layouts=stereo,adelay=${delayMs}:all=1[${lab}]`
);
overlaySoundLabels.push(lab);