Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

feat(editor): clip system with splitting, per-clip speed, and timeline UI

webadderall292dec983642
diff --git a/src/components/video-editor/SettingsPanel.tsx b/src/components/video-editor/SettingsPanel.tsx
index f6cb07cb..39d6d080 100644
--- a/src/components/video-editor/SettingsPanel.tsx
+++ b/src/components/video-editor/SettingsPanel.tsx
@@ -148,6 +148,10 @@ interface SettingsPanelProps {
onZoomDelete?: (id: string) => void;
selectedTrimId?: string | null;
onTrimDelete?: (id: string) => void;
+ selectedClipId?: string | null;
+ selectedClipSpeed?: number | null;
+ onClipSpeedChange?: (speed: number) => void;
+ onClipDelete?: (id: string) => void;
shadowIntensity?: number;
onShadowChange?: (intensity: number) => void;
backgroundBlur?: number;
@@ -503,6 +507,10 @@ export function SettingsPanel({
onZoomDelete,
selectedTrimId,
onTrimDelete,
+ selectedClipId,
+ selectedClipSpeed,
+ onClipSpeedChange,
+ onClipDelete,
shadowIntensity = 0.67,
onShadowChange,
backgroundBlur = 0,
@@ -806,6 +814,12 @@ export function SettingsPanel({
}
};
+ const handleClipDeleteClick = () => {
+ if (selectedClipId && onClipDelete) {
+ onClipDelete(selectedClipId);
+ }
+ };
+
const crop = cropRegion ?? {
x: 0,
y: 0,
@@ -1184,7 +1198,7 @@ export function SettingsPanel({
if (isBackgroundPanel) {
return (
- <div className="flex-[2] min-w-[280px] max-w-[332px] bg-[#161619] border border-white/10 rounded-2xl flex flex-col shadow-xl h-full overflow-hidden">
+ <div className="flex-[2] w-[332px] min-w-[280px] max-w-[332px] bg-[#161619] border border-white/10 rounded-2xl flex flex-col shadow-xl h-full overflow-hidden">
<div className="flex-1 overflow-y-auto custom-scrollbar p-4">
<div className="mb-4 flex items-center gap-2">
<Palette className="w-4 h-4 text-[#2563EB]" />
@@ -1934,8 +1948,8 @@ export function SettingsPanel({
})();
return (
- <div className="basis-[332px] min-w-[280px] max-w-[332px] bg-[#161619] border border-white/10 rounded-2xl flex flex-col shadow-xl h-full overflow-hidden shrink-0">
- <div className="flex-1 min-h-0 overflow-y-auto custom-scrollbar p-4 pb-0">
+ <div className="flex-[2] w-[332px] min-w-[280px] max-w-[332px] bg-[#161619] border border-white/10 rounded-2xl flex flex-col shadow-xl h-full overflow-hidden">
+ <div className="flex-1 min-h-0 overflow-y-auto custom-scrollbar p-4 pb-0" style={{ scrollbarGutter: 'stable' }}>
<AnimatePresence mode="wait" initial={false}>
<motion.div
key={activeEffectSection}
@@ -1951,7 +1965,7 @@ export function SettingsPanel({
<div className={cn(
"flex-shrink-0 border-t border-white/10 bg-[#151518] p-4 pt-3",
- !selectedZoomId && !selectedTrimId && !selectedSpeedId && "hidden"
+ !selectedZoomId && !selectedTrimId && !selectedSpeedId && !selectedClipId && "hidden"
)}>
{selectedZoomId && (
<div className="mb-4">
@@ -2055,6 +2069,57 @@ export function SettingsPanel({
</Button>
</div>
)}
+
+ {selectedClipId && (
+ <div className="mb-4">
+ <div className="mb-3 flex items-center justify-between">
+ <span className="text-sm font-medium text-slate-200">Clip Speed</span>
+ {selectedClipSpeed != null && selectedClipSpeed !== 1 && (
+ <span className="rounded-full bg-[#06b6d4]/10 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wider text-[#06b6d4]">
+ {selectedClipSpeed}×
+ </span>
+ )}
+ </div>
+ <div className="grid grid-cols-8 gap-1.5">
+ {[
+ { speed: 0.25, label: "0.25×" },
+ { speed: 0.5, label: "0.5×" },
+ { speed: 0.75, label: "0.75×" },
+ { speed: 1, label: "1×" },
+ { speed: 1.25, label: "1.25×" },
+ { speed: 1.5, label: "1.5×" },
+ { speed: 1.75, label: "1.75×" },
+ { speed: 2, label: "2×" },
+ ].map((option) => {
+ const isActive = selectedClipSpeed === option.speed;
+ return (
+ <Button
+ key={option.speed}
+ type="button"
+ onClick={() => onClipSpeedChange?.(option.speed)}
+ className={cn(
+ "h-auto w-full rounded-lg border px-0.5 py-2 text-center shadow-sm transition-all duration-200 ease-out cursor-pointer",
+ isActive
+ ? "border-[#06b6d4] bg-[#06b6d4] text-white"
+ : "border-white/5 bg-white/5 text-slate-400 hover:bg-white/10 hover:border-white/10 hover:text-slate-200",
+ )}
+ >
+ <span className="text-[10px] font-semibold">{option.label}</span>
+ </Button>
+ );
+ })}
+ </div>
+ <Button
+ onClick={handleClipDeleteClick}
+ variant="destructive"
+ size="sm"
+ className="mt-2 h-8 w-full gap-2 border border-red-500/20 bg-red-500/10 text-xs text-red-400 transition-all hover:border-red-500/30 hover:bg-red-500/20"
+ >
+ <Trash2 className="h-3 w-3" />
+ Delete Clip
+ </Button>
+ </div>
+ )}
</div>
</div>
diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsx
index 56fd7bbf..a591d442 100644
--- a/src/components/video-editor/VideoEditor.tsx
+++ b/src/components/video-editor/VideoEditor.tsx
@@ -13,7 +13,7 @@ import {
} from "lucide-react";
import { AnimatePresence, LayoutGroup, motion } from "motion/react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
+import { Panel, PanelGroup } from "react-resizable-panels";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import {
@@ -103,6 +103,8 @@ import {
type PlaybackSpeed,
type SpeedRegion,
type TrimRegion,
+ type ClipRegion,
+ clipsToTrims,
type WebcamOverlaySettings,
type ZoomDepth,
type ZoomFocus,
@@ -118,12 +120,14 @@ import {
type EditorHistorySnapshot = {
zoomRegions: ZoomRegion[];
trimRegions: TrimRegion[];
+ clipRegions: ClipRegion[];
speedRegions: SpeedRegion[];
annotationRegions: AnnotationRegion[];
audioRegions: AudioRegion[];
autoCaptions: CaptionCue[];
selectedZoomId: string | null;
selectedTrimId: string | null;
+ selectedClipId: string | null;
selectedSpeedId: string | null;
selectedAnnotationId: string | null;
selectedAudioId: string | null;
@@ -372,6 +376,8 @@ export default function VideoEditor() {
const [selectedZoomId, setSelectedZoomId] = useState<string | null>(null);
const [trimRegions, setTrimRegions] = useState<TrimRegion[]>([]);
const [selectedTrimId, setSelectedTrimId] = useState<string | null>(null);
+ const [clipRegions, setClipRegions] = useState<ClipRegion[]>([]);
+ const [selectedClipId, setSelectedClipId] = useState<string | null>(null);
const [speedRegions, setSpeedRegions] = useState<SpeedRegion[]>([]);
const [selectedSpeedId, setSelectedSpeedId] = useState<string | null>(null);
const [annotationRegions, setAnnotationRegions] = useState<AnnotationRegion[]>([]);
@@ -429,6 +435,7 @@ export default function VideoEditor() {
const projectBrowserFallbackTriggerRef = useRef<HTMLButtonElement | null>(null);
const nextZoomIdRef = useRef(1);
const nextTrimIdRef = useRef(1);
+ const nextClipIdRef = useRef(1);
const nextSpeedIdRef = useRef(1);
const nextAudioIdRef = useRef(1);
@@ -860,6 +867,7 @@ export default function VideoEditor() {
webcam: WebcamOverlaySettings;
zoomRegions: ZoomRegion[];
trimRegions: TrimRegion[];
+ clipRegions: ClipRegion[];
speedRegions: SpeedRegion[];
annotationRegions: AnnotationRegion[];
audioRegions: AudioRegion[];
@@ -951,6 +959,7 @@ export default function VideoEditor() {
webcam,
zoomRegions,
trimRegions,
+ clipRegions,
speedRegions,
annotationRegions,
audioRegions,
@@ -992,6 +1001,7 @@ export default function VideoEditor() {
webcam,
zoomRegions,
trimRegions,
+ clipRegions,
speedRegions,
annotationRegions,
audioRegions,
@@ -1010,12 +1020,14 @@ export default function VideoEditor() {
return {
zoomRegions,
trimRegions,
+ clipRegions,
speedRegions,
annotationRegions,
audioRegions,
autoCaptions,
selectedZoomId,
selectedTrimId,
+ selectedClipId,
selectedSpeedId,
selectedAnnotationId,
selectedAudioId,
@@ -1023,12 +1035,14 @@ export default function VideoEditor() {
}, [
zoomRegions,
trimRegions,
+ clipRegions,
speedRegions,
annotationRegions,
audioRegions,
autoCaptions,
selectedZoomId,
selectedTrimId,
+ selectedClipId,
selectedSpeedId,
selectedAnnotationId,
selectedAudioId,
@@ -1040,12 +1054,14 @@ export default function VideoEditor() {
const cloned = cloneSnapshot(snapshot);
setZoomRegions(cloned.zoomRegions);
setTrimRegions(cloned.trimRegions);
+ setClipRegions(cloned.clipRegions);
setSpeedRegions(cloned.speedRegions);
setAnnotationRegions(cloned.annotationRegions);
setAudioRegions(cloned.audioRegions);
setAutoCaptions(cloned.autoCaptions);
setSelectedZoomId(cloned.selectedZoomId);
setSelectedTrimId(cloned.selectedTrimId);
+ setSelectedClipId(cloned.selectedClipId);
setSelectedSpeedId(cloned.selectedSpeedId);
setSelectedAnnotationId(cloned.selectedAnnotationId);
setSelectedAudioId(cloned.selectedAudioId);
@@ -1058,6 +1074,10 @@ export default function VideoEditor() {
"trim",
cloned.trimRegions.map((region) => region.id),
);
+ nextClipIdRef.current = deriveNextId(
+ "clip",
+ cloned.clipRegions.map((region) => region.id),
+ );
nextSpeedIdRef.current = deriveNextId(
"speed",
cloned.speedRegions.map((region) => region.id),
@@ -1163,6 +1183,8 @@ export default function VideoEditor() {
setWebcam(normalizedEditor.webcam);
setZoomRegions(normalizedEditor.zoomRegions);
setTrimRegions(normalizedEditor.trimRegions);
+ setClipRegions((normalizedEditor as any).clipRegions ?? []);
+ clipInitializedRef.current = ((normalizedEditor as any).clipRegions ?? []).length > 0;
setSpeedRegions(normalizedEditor.speedRegions);
setAnnotationRegions(normalizedEditor.annotationRegions);
setAudioRegions(normalizedEditor.audioRegions);
@@ -1177,6 +1199,7 @@ export default function VideoEditor() {
setSelectedZoomId(null);
setSelectedTrimId(null);
+ setSelectedClipId(null);
setSelectedSpeedId(null);
setSelectedAnnotationId(null);
setSelectedAudioId(null);
@@ -1189,6 +1212,10 @@ export default function VideoEditor() {
"trim",
normalizedEditor.trimRegions.map((region) => region.id),
);
+ nextClipIdRef.current = deriveNextId(
+ "clip",
+ ((normalizedEditor as any).clipRegions ?? []).map((region: ClipRegion) => region.id),
+ );
nextSpeedIdRef.current = deriveNextId(
"speed",
normalizedEditor.speedRegions.map((region) => region.id),
@@ -1876,6 +1903,25 @@ export default function VideoEditor() {
);
}, [loopCursor, normalizedCursorTelemetry, displayedTimelineWindow]);
+ // Initialize a full-track clip when duration is first known
+ const clipInitializedRef = useRef(false);
+ useEffect(() => {
+ const totalMs = Math.round(duration * 1000);
+ if (totalMs <= 0 || clipInitializedRef.current) return;
+ if (clipRegions.length === 0) {
+ const id = `clip-${nextClipIdRef.current++}`;
+ setClipRegions([{ id, startMs: 0, endMs: totalMs, speed: 1 }]);
+ }
+ clipInitializedRef.current = true;
+ }, [duration, clipRegions.length]);
+
+ // Derive trimRegions from clipRegions so export/playback pipelines stay unchanged
+ useEffect(() => {
+ const totalMs = Math.round(duration * 1000);
+ if (totalMs <= 0 || clipRegions.length === 0) return;
+ setTrimRegions(clipsToTrims(clipRegions, totalMs));
+ }, [clipRegions, duration]);
+
const effectiveZoomRegions = zoomRegions;
useEffect(() => {
@@ -2075,6 +2121,91 @@ export default function VideoEditor() {
[selectedTrimId],
);
+ const handleSelectClip = useCallback((id: string | null) => {
+ setSelectedClipId(id);
+ if (id) {
+ setSelectedZoomId(null);
+ setSelectedAnnotationId(null);
+ setSelectedAudioId(null);
+ }
+ }, []);
+
+ const handleClipSplit = useCallback(
+ (splitMs: number) => {
+ setClipRegions((prev) => {
+ const target = prev.find((c) => splitMs > c.startMs && splitMs < c.endMs);
+ if (!target) return prev;
+ const leftId = `clip-${nextClipIdRef.current++}`;
+ const rightId = `clip-${nextClipIdRef.current++}`;
+ const left: ClipRegion = { id: leftId, startMs: target.startMs, endMs: Math.round(splitMs), speed: target.speed };
+ const right: ClipRegion = { id: rightId, startMs: Math.round(splitMs), endMs: target.endMs, speed: target.speed };
+ return prev.flatMap((c) => (c.id === target.id ? [left, right] : [c]));
+ });
+ },
+ [],
+ );
+
+ const handleClipSpanChange = useCallback((id: string, span: Span) => {
+ const oldClip = clipRegions.find((c) => c.id === id);
+ const newStart = Math.round(span.start);
+ const newEnd = Math.round(span.end);
+
+ if (oldClip) {
+ const startDelta = newStart - oldClip.startMs;
+ const endDelta = newEnd - oldClip.endMs;
+ const isMove = Math.abs(startDelta - endDelta) < 1 && Math.abs(startDelta) > 0;
+
+ if (isMove) {
+ const delta = startDelta;
+ setZoomRegions((prev) =>
+ prev.map((zoom) => {
+ const overlaps = zoom.startMs < oldClip.endMs && zoom.endMs > oldClip.startMs;
+ if (overlaps) {
+ return {
+ ...zoom,
+ startMs: zoom.startMs + delta,
+ endMs: zoom.endMs + delta,
+ };
+ }
+ return zoom;
+ }),
+ );
+ }
+ }
+
+ setClipRegions((prev) =>
+ prev.map((clip) =>
+ clip.id === id
+ ? { ...clip, startMs: newStart, endMs: newEnd }
+ : clip,
+ ),
+ );
+ }, [clipRegions]);
+
+ const handleClipSpeedChange = useCallback(
+ (speed: number) => {
+ if (!selectedClipId) return;
+ setClipRegions((prev) =>
+ prev.map((clip) =>
+ clip.id === selectedClipId
+ ? { ...clip, speed }
+ : clip,
+ ),
+ );
+ },
+ [selectedClipId],
+ );
+
+ const handleClipDelete = useCallback(
+ (id: string) => {
+ setClipRegions((prev) => prev.filter((clip) => clip.id !== id));
+ if (selectedClipId === id) {
+ setSelectedClipId(null);
+ }
+ },
+ [selectedClipId],
+ );
+
const handleSelectSpeed = useCallback((id: string | null) => {
setSelectedSpeedId(id);
if (id) {
@@ -3529,10 +3660,6 @@ export default function VideoEditor() {
</div>
</Panel>
- <PanelResizeHandle className="h-3 bg-transparent transition-colors mx-4 flex items-center justify-center">
- <div className="w-8 h-1 bg-white/20 rounded-full"></div>
- </PanelResizeHandle>
-
{/* Timeline section */}
<Panel defaultSize={33} minSize={20}>
<div className="h-full min-h-0 bg-[#17171a] rounded-2xl border border-white/10 shadow-lg overflow-auto flex flex-col">
@@ -3540,6 +3667,7 @@ export default function VideoEditor() {
videoDuration={duration}
currentTime={currentTime}
onSeek={handleSeek}
+ videoPath={videoPath}
cursorTelemetry={normalizedCursorTelemetry}
autoSuggestZoomsTrigger={autoSuggestZoomsTrigger}
onAutoSuggestZoomsConsumed={handleAutoSuggestZoomsConsumed}
@@ -3556,6 +3684,11 @@ export default function VideoEditor() {
onTrimDelete={handleTrimDelete}
selectedTrimId={selectedTrimId}
onSelectTrim={handleSelectTrim}
+ clipRegions={clipRegions}
+ onClipSplit={handleClipSplit}
+ onClipSpanChange={handleClipSpanChange}
+ selectedClipId={selectedClipId}
+ onSelectClip={handleSelectClip}
speedRegions={speedRegions}
onSpeedAdded={handleSpeedAdded}
onSpeedSpanChange={handleSpeedSpanChange}
@@ -3599,6 +3732,12 @@ export default function VideoEditor() {
onZoomDelete={handleZoomDelete}
selectedTrimId={selectedTrimId}
onTrimDelete={handleTrimDelete}
+ selectedClipId={selectedClipId}
+ selectedClipSpeed={
+ selectedClipId ? (clipRegions.find((c) => c.id === selectedClipId)?.speed ?? 1) : null
+ }
+ onClipSpeedChange={(speed) => selectedClipId && handleClipSpeedChange(speed)}
+ onClipDelete={handleClipDelete}
shadowIntensity={shadowIntensity}
onShadowChange={setShadowIntensity}
backgroundBlur={backgroundBlur}
diff --git a/src/components/video-editor/timeline/Item.tsx b/src/components/video-editor/timeline/Item.tsx
index cc387ea9..52305c23 100644
--- a/src/components/video-editor/timeline/Item.tsx
+++ b/src/components/video-editor/timeline/Item.tsx
@@ -1,6 +1,6 @@
import type { Span } from "dnd-timeline";
import { useItem } from "dnd-timeline";
-import { Gauge, MessageSquare, Music, Scissors, ZoomIn } from "lucide-react";
+import { Film, Gauge, MessageSquare, Music, Scissors, ZoomIn } from "lucide-react";
import { useMemo } from "react";
import { cn } from "@/lib/utils";
import glassStyles from "./ItemGlass.module.css";
@@ -14,7 +14,7 @@ interface ItemProps {
onSelect?: () => void;
zoomDepth?: number;
speedValue?: number;
- variant?: 'zoom' | 'trim' | 'annotation' | 'speed' | 'audio';
+ variant?: 'zoom' | 'trim' | 'clip' | 'annotation' | 'speed' | 'audio';
}
// Map zoom depth to multiplier labels
@@ -56,6 +56,7 @@ export default function Item({
const isZoom = variant === 'zoom';
const isTrim = variant === 'trim';
+ const isClip = variant === 'clip';
const isSpeed = variant === 'speed';
const isAudio = variant === 'audio';
@@ -63,6 +64,8 @@ export default function Item({
? glassStyles.glassGreen
: isTrim
? glassStyles.glassRed
+ : isClip
+ ? glassStyles.glassCyan
: isSpeed
? glassStyles.glassAmber
: isAudio
@@ -73,6 +76,8 @@ export default function Item({
? '#2563EB'
: isTrim
? '#ef4444'
+ : isClip
+ ? '#06b6d4'
: isSpeed
? '#d97706'
: isAudio
@@ -136,6 +141,13 @@ export default function Item({
Trim
</span>
</>
+ ) : isClip ? (
+ <>
+ <Film className="w-3.5 h-3.5 shrink-0" />
+ <span className="text-[11px] font-semibold tracking-tight whitespace-nowrap">
+ Clip
+ </span>
+ </>
) : isSpeed ? (
<>
<Gauge className="w-3.5 h-3.5 shrink-0" />
diff --git a/src/components/video-editor/timeline/ItemGlass.module.css b/src/components/video-editor/timeline/ItemGlass.module.css
index 95cfe5e3..78ebe232 100644
--- a/src/components/video-editor/timeline/ItemGlass.module.css
+++ b/src/components/video-editor/timeline/ItemGlass.module.css
@@ -128,6 +128,32 @@
z-index: 10;
}
+.glassCyan {
+ position: relative;
+ border-radius: 8px;
+ -corner-smoothing: antialiased;
+ background: rgba(6, 182, 212, 0.15);
+ border: 1px solid rgba(6, 182, 212, 0.3);
+ box-shadow: 0 2px 12px 0 rgba(6, 182, 212, 0.1) inset;
+ margin: 1px 0;
+ backdrop-filter: blur(4px);
+ -webkit-backdrop-filter: blur(4px);
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+}
+
+.glassCyan:hover {
+ background: rgba(6, 182, 212, 0.25);
+ border-color: rgba(6, 182, 212, 0.5);
+ box-shadow: 0 4px 20px 0 rgba(6, 182, 212, 0.2) inset;
+}
+
+.glassCyan.selected {
+ background: rgba(6, 182, 212, 0.35);
+ border-color: #06b6d4;
+ box-shadow: 0 0 0 1px #06b6d4, 0 4px 20px 0 rgba(6, 182, 212, 0.3) inset;
+ z-index: 10;
+}
+
.zoomEndCap {
position: absolute;
top: 0;
@@ -148,7 +174,9 @@
.glassAmber:hover .zoomEndCap,
.glassAmber.selected .zoomEndCap,
.glassPurple:hover .zoomEndCap,
-.glassPurple.selected .zoomEndCap {
+.glassPurple.selected .zoomEndCap,
+.glassCyan:hover .zoomEndCap,
+.glassCyan.selected .zoomEndCap {
opacity: 1;
}
diff --git a/src/components/video-editor/timeline/TimelineEditor.tsx b/src/components/video-editor/timeline/TimelineEditor.tsx
index 72c6dc53..59c7935c 100644
--- a/src/components/video-editor/timeline/TimelineEditor.tsx
+++ b/src/components/video-editor/timeline/TimelineEditor.tsx
@@ -7,30 +7,30 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
-import { Plus, Scissors, ZoomIn, MessageSquare, ChevronDown, Check, Gauge, WandSparkles, Music, Crop } from "lucide-react";
+import { Plus, Scissors, ZoomIn, MessageSquare, ChevronDown, Check, WandSparkles, Music, Crop } from "lucide-react";
import { toast } from "sonner";
import { cn } from "@/lib/utils";
import { v4 as uuidv4 } from 'uuid';
import { useScopedT } from "@/contexts/I18nContext";
import { useShortcuts } from "@/contexts/ShortcutsContext";
import { matchesShortcut } from "@/lib/shortcuts";
-import { resolveMediaElementSource } from "@/lib/exporter/localMediaSource";
import { ASPECT_RATIOS, type AspectRatio, getAspectRatioLabel, isCustomAspectRatio } from "@/utils/aspectRatioUtils";
import { formatShortcut } from "@/utils/platformUtils";
import { loadEditorPreferences, saveEditorPreferences } from "../editorPreferences";
-import { TutorialHelp } from "../TutorialHelp";
import TimelineWrapper from "./TimelineWrapper";
import Row from "./Row";
import Item from "./Item";
import KeyframeMarkers from "./KeyframeMarkers";
import type { Range, Span } from "dnd-timeline";
-import type { ZoomRegion, TrimRegion, AnnotationRegion, SpeedRegion, AudioRegion, CursorTelemetryPoint, ZoomFocus } from "../types";
+import type { ZoomRegion, TrimRegion, ClipRegion, AnnotationRegion, SpeedRegion, AudioRegion, CursorTelemetryPoint, ZoomFocus } from "../types";
+import { toFileUrl } from "../projectPersistence";
import { detectInteractionCandidates, normalizeCursorTelemetry } from "./zoomSuggestionUtils";
+import { useAudioPeaks, type AudioPeaksData } from "./useAudioPeaks";
+import AudioWaveform from "./AudioWaveform";
const ZOOM_ROW_ID = "row-zoom";
-const TRIM_ROW_ID = "row-trim";
+const CLIP_ROW_ID = "row-clip";
const ANNOTATION_ROW_ID = "row-annotation";
-const SPEED_ROW_ID = "row-speed";
const AUDIO_ROW_ID = "row-audio";
const FALLBACK_RANGE_MS = 1000;
const TARGET_MARKER_COUNT = 12;
@@ -57,6 +57,12 @@ interface TimelineEditorProps {
onTrimDelete?: (id: string) => void;
selectedTrimId?: string | null;
onSelectTrim?: (id: string | null) => void;
+ clipRegions?: ClipRegion[];
+ onClipSplit?: (splitMs: number) => void;
+ onClipSpanChange?: (id: string, span: Span) => void;
+ onClipDelete?: (id: string) => void;
+ selectedClipId?: string | null;
+ onSelectClip?: (id: string | null) => void;
annotationRegions?: AnnotationRegion[];
onAnnotationAdded?: (span: Span) => void;
onAnnotationSpanChange?: (id: string, span: Span) => void;
@@ -79,6 +85,7 @@ interface TimelineEditorProps {
onAspectRatioChange: (aspectRatio: AspectRatio) => void;
onOpenCropEditor?: () => void;
isCropped?: boolean;
+ videoPath?: string | null;
}
interface TimelineScaleConfig {
@@ -94,7 +101,7 @@ interface TimelineRenderItem {
label: string;
zoomDepth?: number;
speedValue?: number;
- variant: 'zoom' | 'trim' | 'annotation' | 'speed' | 'audio';
+ variant: 'zoom' | 'trim' | 'clip' | 'annotation' | 'speed' | 'audio';
}
const SCALE_CANDIDATES = [
@@ -448,17 +455,20 @@ function Timeline({
onSeek,
onSelectZoom,
onSelectTrim,
+ onSelectClip,
onSelectAnnotation,
onSelectSpeed,
onSelectAudio,
selectedZoomId,
- selectedTrimId,
+ selectedTrimId: _selectedTrimId,
+ selectedClipId,
selectedAnnotationId,
- selectedSpeedId,
+ selectedSpeedId: _selectedSpeedId,
selectedAudioId,
selectAllBlocksActive = false,
onClearBlockSelection,
keyframes = [],
+ audioPeaks,
}: {
items: TimelineRenderItem[];
videoDurationMs: number;
@@ -466,17 +476,20 @@ function Timeline({
onSeek?: (time: number) => void;
onSelectZoom?: (id: string | null) => void;
onSelectTrim?: (id: string | null) => void;
+ onSelectClip?: (id: string | null) => void;
onSelectAnnotation?: (id: string | null) => void;
onSelectSpeed?: (id: string | null) => void;
onSelectAudio?: (id: string | null) => void;
selectedZoomId: string | null;
selectedTrimId?: string | null;
+ selectedClipId?: string | null;
selectedAnnotationId?: string | null;
selectedSpeedId?: string | null;
selectedAudioId?: string | null;
selectAllBlocksActive?: boolean;
onClearBlockSelection?: () => void;
keyframes?: { id: string; time: number }[];
+ audioPeaks?: AudioPeaksData | null;
}) {
const { setTimelineRef, style, sidebarWidth, range, pixelsToValue } = useTimelineContext();
const localTimelineRef = useRef<HTMLDivElement | null>(null);
@@ -497,6 +510,7 @@ function Timeline({
// This is handled by event propagation - items stop propagation
onSelectZoom?.(null);
onSelectTrim?.(null);
+ onSelectClip?.(null);
onSelectAnnotation?.(null);
onSelectSpeed?.(null);
onSelectAudio?.(null);
@@ -512,12 +526,12 @@ function Timeline({
const timeInSeconds = absoluteMs / 1000;
onSeek(timeInSeconds);
- }, [onSeek, onSelectZoom, onSelectTrim, onSelectAnnotation, onSelectSpeed, onSelectAudio, videoDurationMs, sidebarWidth, range.start, pixelsToValue]);
+ }, [onSeek, onSelectZoom, onSelectTrim, onSelectClip, onSelectAnnotation, onSelectSpeed, onSelectAudio, videoDurationMs, sidebarWidth, range.start, pixelsToValue]);
const zoomItems = items.filter(item => item.rowId === ZOOM_ROW_ID);
- const trimItems = items.filter(item => item.rowId === TRIM_ROW_ID);
+
+ const clipItems = items.filter(item => item.rowId === CLIP_ROW_ID);
const annotationItems = items.filter(item => item.rowId === ANNOTATION_ROW_ID);
- const speedItems = items.filter(item => item.rowId === SPEED_ROW_ID);
const audioItems = items.filter(item => item.rowId === AUDIO_ROW_ID);
return (
@@ -538,39 +552,41 @@ function Timeline({
/>
<div className="relative z-10 flex flex-1 min-h-0 flex-col">
- <Row id={ZOOM_ROW_ID} isEmpty={zoomItems.length === 0} hint="Press Z to add zoom">
- {zoomItems.map((item) => (
+ <Row id={CLIP_ROW_ID} isEmpty={clipItems.length === 0} hint="Press C to split clip">
+ {audioPeaks && <AudioWaveform peaks={audioPeaks} />}
+ {clipItems.map((item) => (
<Item
id={item.id}
key={item.id}
rowId={item.rowId}
span={item.span}
- isSelected={selectAllBlocksActive || item.id === selectedZoomId}
- onSelect={() => onSelectZoom?.(item.id)}
- zoomDepth={item.zoomDepth}
- variant="zoom"
+ isSelected={selectAllBlocksActive || item.id === selectedClipId}
+ onSelect={() => onSelectClip?.(item.id)}
+ variant="clip"
>
{item.label}
</Item>
))}
</Row>
- <Row id={TRIM_ROW_ID} isEmpty={trimItems.length === 0} hint="Press T to add trim">
- {trimItems.map((item) => (
+ <Row id={ZOOM_ROW_ID} isEmpty={zoomItems.length === 0} hint="Press Z to add zoom">
+ {zoomItems.map((item) => (
<Item
id={item.id}
key={item.id}
rowId={item.rowId}
span={item.span}
- isSelected={selectAllBlocksActive || item.id === selectedTrimId}
- onSelect={() => onSelectTrim?.(item.id)}
- variant="trim"
+ isSelected={selectAllBlocksActive || item.id === selectedZoomId}
+ onSelect={() => onSelectZoom?.(item.id)}
+ zoomDepth={item.zoomDepth}
+ variant="zoom"
>
{item.label}
</Item>
))}
</Row>
+
<Row
id={ANNOTATION_ROW_ID}
isEmpty={annotationItems.length === 0}
@@ -591,23 +607,6 @@ function Timeline({
))}
</Row>
- <Row id={SPEED_ROW_ID} isEmpty={speedItems.length === 0} hint="Press S to add speed">
- {speedItems.map((item) => (
- <Item
- id={item.id}
- key={item.id}
- rowId={item.rowId}
- span={item.span}
- isSelected={selectAllBlocksActive || item.id === selectedSpeedId}
- onSelect={() => onSelectSpeed?.(item.id)}
- variant="speed"
- speedValue={item.speedValue}
- >
- {item.label}
- </Item>
- ))}
- </Row>
-
<Row id={AUDIO_ROW_ID} isEmpty={audioItems.length === 0} hint="Click music icon to add audio">
{audioItems.map((item) => (
<Item
@@ -649,6 +648,12 @@ export default function TimelineEditor({
onTrimDelete,
selectedTrimId,
onSelectTrim,
+ clipRegions = [],
+ onClipSplit,
+ onClipSpanChange,
+ onClipDelete,
+ selectedClipId,
+ onSelectClip,
annotationRegions = [],
onAnnotationAdded,
onAnnotationSpanChange,
@@ -671,6 +676,7 @@ export default function TimelineEditor({
onAspectRatioChange,
onOpenCropEditor,
isCropped = false,
+ videoPath,
}: TimelineEditorProps) {
const t = useScopedT("settings");
const initialEditorPreferences = useMemo(() => loadEditorPreferences(), []);
@@ -695,6 +701,7 @@ export default function TimelineEditor({
const isTimelineFocusedRef = useRef(false);
const timelineContainerRef = useRef<HTMLDivElement>(null);
const { shortcuts: keyShortcuts, isMac } = useShortcuts();
+ const audioPeaks = useAudioPeaks(videoPath);
useEffect(() => {
setRange(createInitialRange(totalMs));
@@ -779,6 +786,12 @@ export default function TimelineEditor({
onSelectTrim(null);
}, [selectedTrimId, onTrimDelete, onSelectTrim]);
+ const deleteSelectedClip = useCallback(() => {
+ if (!selectedClipId || !onClipDelete || !onSelectClip) return;
+ onClipDelete(selectedClipId);
+ onSelectClip(null);
+ }, [selectedClipId, onClipDelete, onSelectClip]);
+
const deleteSelectedAnnotation = useCallback(() => {
if (!selectedAnnotationId || !onAnnotationDelete || !onSelectAnnotation) return;
onAnnotationDelete(selectedAnnotationId);
@@ -800,15 +813,17 @@ export default function TimelineEditor({
const clearSelectedBlocks = useCallback(() => {
onSelectZoom(null);
onSelectTrim?.(null);
+ onSelectClip?.(null);
onSelectAnnotation?.(null);
onSelectSpeed?.(null);
onSelectAudio?.(null);
setSelectAllBlocksActive(false);
- }, [onSelectAnnotation, onSelectAudio, onSelectSpeed, onSelectTrim, onSelectZoom]);
+ }, [onSelectAnnotation, onSelectAudio, onSelectClip, onSelectSpeed, onSelectTrim, onSelectZoom]);
const hasAnyTimelineBlocks =
zoomRegions.length > 0 ||
trimRegions.length > 0 ||
+ clipRegions.length > 0 ||
annotationRegions.length > 0 ||
speedRegions.length > 0 ||
audioRegions.length > 0;
@@ -816,12 +831,14 @@ export default function TimelineEditor({
const deleteAllBlocks = useCallback(() => {
const zoomIds = zoomRegions.map((region) => region.id);
const trimIds = trimRegions.map((region) => region.id);
+ const clipIds = clipRegions.map((region) => region.id);
const annotationIds = annotationRegions.map((region) => region.id);
const speedIds = speedRegions.map((region) => region.id);
const audioIds = audioRegions.map((region) => region.id);
zoomIds.forEach((id) => onZoomDelete(id));
trimIds.forEach((id) => onTrimDelete?.(id));
+ clipIds.forEach((id) => onClipDelete?.(id));
annotationIds.forEach((id) => onAnnotationDelete?.(id));
speedIds.forEach((id) => onSpeedDelete?.(id));
audioIds.forEach((id) => onAudioDelete?.(id));
@@ -832,8 +849,10 @@ export default function TimelineEditor({
annotationRegions,
audioRegions,
clearSelectedBlocks,
+ clipRegions,
onAnnotationDelete,
onAudioDelete,
+ onClipDelete,
onSpeedDelete,
onTrimDelete,
onZoomDelete,
@@ -852,6 +871,11 @@ export default function TimelineEditor({
onSelectTrim?.(id);
}, [onSelectTrim]);
+ const handleSelectClip = useCallback((id: string | null) => {
+ setSelectAllBlocksActive(false);
+ onSelectClip?.(id);
+ }, [onSelectClip]);
+
const handleSelectAnnotation = useCallback((id: string | null) => {
setSelectAllBlocksActive(false);
onSelectAnnotation?.(id);
@@ -1153,6 +1177,13 @@ export default function TimelineEditor({
onTrimAdded({ start: startPos, end: startPos + actualDuration });
}, [videoDuration, totalMs, currentTimeMs, trimRegions, onTrimAdded, defaultRegionDurationMs]);
+ const handleSplitClip = useCallback(() => {
+ if (!videoDuration || videoDuration === 0 || totalMs === 0 || !onClipSplit) {
+ return;
+ }
+ onClipSplit(currentTimeMs);
+ }, [videoDuration, totalMs, currentTimeMs, onClipSplit]);
+
const handleAddSpeed = useCallback(() => {
if (!videoDuration || videoDuration === 0 || totalMs === 0 || !onSpeedAdded) {
return;
@@ -1196,24 +1227,14 @@ export default function TimelineEditor({
const audioPath = result.path;
// Load the audio file to get its full duration
- const audioSource = await resolveMediaElementSource(audioPath);
const audioDurationMs = await new Promise<number>((resolve) => {
- const audio = new Audio();
- const finish = (durationMs: number) => {
- audio.pause();
- audio.src = "";
- audioSource.revoke();
- resolve(durationMs);
- };
-
- audio.preload = "metadata";
+ const audio = new Audio(toFileUrl(audioPath));
audio.addEventListener('loadedmetadata', () => {
- finish(Math.round(audio.duration * 1000));
- }, { once: true });
+ resolve(Math.round(audio.duration * 1000));
+ });
audio.addEventListener('error', () => {
- finish(0);
- }, { once: true });
- audio.src = audioSource.src;
+ resolve(0);
+ });
});
if (audioDurationMs <= 0) {
@@ -1284,6 +1305,9 @@ export default function TimelineEditor({
if (matchesShortcut(e, keyShortcuts.addTrim, isMac)) {
handleAddTrim();
}
+ if (matchesShortcut(e, keyShortcuts.splitClip, isMac)) {
+ handleSplitClip();
+ }
if (matchesShortcut(e, keyShortcuts.addAnnotation, isMac)) {
handleAddAnnotation();
}
@@ -1324,6 +1348,8 @@ export default function TimelineEditor({
deleteSelectedZoom();
} else if (selectedTrimId) {
deleteSelectedTrim();
+ } else if (selectedClipId) {
+ deleteSelectedClip();
} else if (selectedAnnotationId) {
deleteSelectedAnnotation();
} else if (selectedSpeedId) {
@@ -1335,7 +1361,7 @@ export default function TimelineEditor({
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
- }, [addKeyframe, handleAddZoom, handleAddTrim, handleAddAnnotation, handleAddSpeed, deleteAllBlocks, deleteSelectedKeyframe, deleteSelectedZoom, deleteSelectedTrim, deleteSelectedAnnotation, deleteSelectedSpeed, deleteSelectedAudio, selectedKeyframeId, selectedZoomId, selectedTrimId, selectedAnnotationId, selectedSpeedId, selectedAudioId, annotationRegions, currentTime, hasAnyTimelineBlocks, onSelectAnnotation, keyShortcuts, isMac, selectAllBlocksActive]);
+ }, [addKeyframe, handleAddZoom, handleAddTrim, handleSplitClip, handleAddAnnotation, handleAddSpeed, deleteAllBlocks, deleteSelectedKeyframe, deleteSelectedZoom, deleteSelectedTrim, deleteSelectedClip, deleteSelectedAnnotation, deleteSelectedSpeed, deleteSelectedAudio, selectedKeyframeId, selectedZoomId, selectedTrimId, selectedClipId, selectedAnnotationId, selectedSpeedId, selectedAudioId, annotationRegions, currentTime, hasAnyTimelineBlocks, onSelectAnnotation, keyShortcuts, isMac, selectAllBlocksActive]);
const clampedRange = useMemo<Range>(() => {
if (totalMs === 0) {
@@ -1358,12 +1384,12 @@ export default function TimelineEditor({
variant: 'zoom',
}));
- const trims: TimelineRenderItem[] = trimRegions.map((region, index) => ({
+ const clips: TimelineRenderItem[] = clipRegions.map((region, index) => ({
id: region.id,
- rowId: TRIM_ROW_ID,
+ rowId: CLIP_ROW_ID,
span: { start: region.startMs, end: region.endMs },
- label: `Trim ${index + 1}`,
- variant: 'trim',
+ label: `Clip ${index + 1}`,
+ variant: 'clip',
}));
const annotations: TimelineRenderItem[] = annotationRegions.map((region) => {
@@ -1388,15 +1414,6 @@ export default function TimelineEditor({
};
});
- const speeds: TimelineRenderItem[] = speedRegions.map((region, index) => ({
- id: region.id,
- rowId: SPEED_ROW_ID,
- span: { start: region.startMs, end: region.endMs },
- label: `Speed ${index + 1}`,
- speedValue: region.speed,
- variant: 'speed',
- }));
-
const audios: TimelineRenderItem[] = audioRegions.map((region) => {
const fileName = region.audioPath.split(/[\\/]/).pop()?.replace(/\.[^.]+$/, '') || 'Audio';
return {
@@ -1408,32 +1425,29 @@ export default function TimelineEditor({
};
});
- return [...zooms, ...trims, ...annotations, ...speeds, ...audios];
- }, [zoomRegions, trimRegions, annotationRegions, speedRegions, audioRegions]);
+ return [...zooms, ...clips, ...annotations, ...audios];
+ }, [zoomRegions, clipRegions, annotationRegions, audioRegions]);
// Flat list of all non-annotation region spans for neighbour-clamping during drag/resize
const allRegionSpans = useMemo(() => {
const zooms = zoomRegions.map((r) => ({ id: r.id, start: r.startMs, end: r.endMs }));
- const trims = trimRegions.map((r) => ({ id: r.id, start: r.startMs, end: r.endMs }));
- const speeds = speedRegions.map((r) => ({ id: r.id, start: r.startMs, end: r.endMs }));
+ const clips = clipRegions.map((r) => ({ id: r.id, start: r.startMs, end: r.endMs }));
const audios = audioRegions.map((r) => ({ id: r.id, start: r.startMs, end: r.endMs }));
- return [...zooms, ...trims, ...speeds, ...audios];
- }, [zoomRegions, trimRegions, speedRegions, audioRegions]);
+ return [...zooms, ...clips, ...audios];
+ }, [zoomRegions, clipRegions, audioRegions]);
const handleItemSpanChange = useCallback((id: string, span: Span) => {
- // Check if it's a zoom, trim, speed, or annotation item
+ // Check if it's a zoom, trim, clip, speed, or annotation item
if (zoomRegions.some(r => r.id === id)) {
onZoomSpanChange(id, span);
- } else if (trimRegions.some(r => r.id === id)) {
- onTrimSpanChange?.(id, span);
- } else if (speedRegions.some(r => r.id === id)) {
- onSpeedSpanChange?.(id, span);
+ } else if (clipRegions.some(r => r.id === id)) {
+ onClipSpanChange?.(id, span);
} else if (annotationRegions.some(r => r.id === id)) {
onAnnotationSpanChange?.(id, span);
} else if (audioRegions.some(r => r.id === id)) {
onAudioSpanChange?.(id, span);
}
- }, [zoomRegions, trimRegions, speedRegions, annotationRegions, audioRegions, onZoomSpanChange, onTrimSpanChange, onSpeedSpanChange, onAnnotationSpanChange, onAudioSpanChange]);
+ }, [zoomRegions, clipRegions, annotationRegions, audioRegions, onZoomSpanChange, onClipSpanChange, onAnnotationSpanChange, onAudioSpanChange]);
const panTimelineRange = useCallback((deltaMs: number) => {
if (!Number.isFinite(deltaMs) || deltaMs === 0 || totalMs <= 0) {
@@ -1518,15 +1532,6 @@ export default function TimelineEditor({
>
<WandSparkles className="w-4 h-4" />
</Button>
- <Button
- onClick={handleAddTrim}
- variant="ghost"
- size="icon"
- className="h-7 w-7 text-slate-400 hover:text-[#ef4444] hover:bg-[#ef4444]/10 transition-all"
- title="Add Trim (T)"
- >
- <Scissors className="w-4 h-4" />
- </Button>
<Button
onClick={handleAddAnnotation}
variant="ghost"
@@ -1537,22 +1542,22 @@ export default function TimelineEditor({
<MessageSquare className="w-4 h-4" />
</Button>
<Button
- onClick={handleAddSpeed}
+ onClick={handleAddAudio}
variant="ghost"
size="icon"
- className="h-7 w-7 text-slate-400 hover:text-[#d97706] hover:bg-[#d97706]/10 transition-all"
- title="Add Speed (S)"
+ className="h-7 w-7 text-slate-400 hover:text-[#a855f7] hover:bg-[#a855f7]/10 transition-all"
+ title="Add Audio"
>
- <Gauge className="w-4 h-4" />
+ <Music className="w-4 h-4" />
</Button>
<Button
- onClick={handleAddAudio}
+ onClick={handleSplitClip}
variant="ghost"
size="icon"
- className="h-7 w-7 text-slate-400 hover:text-[#a855f7] hover:bg-[#a855f7]/10 transition-all"
- title="Add Audio"
+ className="h-7 w-7 text-slate-400 hover:text-white hover:bg-white/10 transition-all"
+ title="Split Clip (C)"
>
- <Music className="w-4 h-4" />
+ <Scissors className="w-4 h-4" />
</Button>
</div>
<div className="flex items-center gap-2">
@@ -1623,7 +1628,6 @@ export default function TimelineEditor({
<span className="font-medium">{t("sections.crop", "Crop")}</span>
{isCropped ? <span className="h-1.5 w-1.5 rounded-full bg-[#2563EB]" /> : null}
</Button>
- <TutorialHelp />
</div>
<div className="flex-1" />
<div className="flex items-center gap-4 text-[10px] text-slate-500 font-medium">
@@ -1686,17 +1690,20 @@ export default function TimelineEditor({
onSeek={onSeek}
onSelectZoom={handleSelectZoom}
onSelectTrim={handleSelectTrim}
+ onSelectClip={handleSelectClip}
onSelectAnnotation={handleSelectAnnotation}
onSelectSpeed={handleSelectSpeed}
onSelectAudio={handleSelectAudio}
selectedZoomId={selectedZoomId}
selectedTrimId={selectedTrimId}
+ selectedClipId={selectedClipId}
selectedAnnotationId={selectedAnnotationId}
selectedSpeedId={selectedSpeedId}
selectedAudioId={selectedAudioId}
selectAllBlocksActive={selectAllBlocksActive}
onClearBlockSelection={clearSelectedBlocks}
keyframes={keyframes}
+ audioPeaks={audioPeaks}
/>
</TimelineWrapper>
</div>