Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

merge: upstream main into feature/video-transcriptions

parse-nip5417581f0e06
diff --cc src/components/video-editor/VideoEditor.tsx
index 2edf90dc9,464370df5..c2d264dfa
--- a/src/components/video-editor/VideoEditor.tsx
+++ b/src/components/video-editor/VideoEditor.tsx
@@@ -26,15 -16,7 +26,16 @@@ import { useShortcuts } from "@/context
import { INITIAL_EDITOR_STATE, useEditorHistory } from "@/hooks/useEditorHistory";
import { type Locale } from "@/i18n/config";
import { getAvailableLocales, getLocaleName } from "@/i18n/loader";
+import {
+ captionSegmentsToAnnotationRegions,
+ extractMono16kFromVideoUrl,
+ MAX_CAPTION_AUDIO_SEC,
+ reconcileAutoCaptionTimelineGaps,
+ shiftTrimRegionsMsForCaptionBuffer,
+ transcribeMono16kToSegments,
+ trimLeadingSilenceMono16k,
+} from "@/lib/captioning";
+ import { hasNativeCursorRecordingData } from "@/lib/cursor/nativeCursor";
import {
calculateOutputDimensions,
type ExportFormat,
@@@ -94,10 -87,65 +106,67 @@@ import
type ZoomFocusMode,
type ZoomRegion,
} from "./types";
+ import { UnsavedChangesDialog } from "./UnsavedChangesDialog";
import VideoPlayback, { VideoPlaybackRef } from "./VideoPlayback";
+ function isClickInteractionType(interactionType: string | null | undefined) {
+ return (
+ interactionType === "click" ||
+ interactionType === "double-click" ||
+ interactionType === "right-click" ||
+ interactionType === "middle-click"
+ );
+ }
+
+ interface ExportDiagnostics {
+ formatLabel: "GIF" | "Video";
+ reason?: string;
+ sourcePath?: string | null;
+ width?: number;
+ height?: number;
+ frameRate?: number;
+ codec?: string;
+ bitrate?: number;
+ }
+
+ function getFileNameForDiagnostics(filePath?: string | null) {
+ if (!filePath) return "unknown";
+
+ try {
+ const url = new URL(filePath);
+ if (url.protocol === "file:") {
+ return decodeURIComponent(url.pathname).split(/[\\/]/).pop() || filePath;
+ }
+ } catch {
+ // Treat non-URL values as filesystem paths.
+ }
+
+ return filePath.split(/[\\/]/).pop() || filePath;
+ }
+
+ function buildExportDiagnosticMessage(diagnostics: ExportDiagnostics) {
+ const details = [
+ diagnostics.reason ? `Reason: ${diagnostics.reason}` : null,
+ `Source: ${getFileNameForDiagnostics(diagnostics.sourcePath)}`,
+ diagnostics.width && diagnostics.height
+ ? `Output: ${diagnostics.width}x${diagnostics.height}${
+ diagnostics.frameRate ? ` @ ${diagnostics.frameRate} fps` : ""
+ }`
+ : null,
+ diagnostics.codec ? `Codec: ${diagnostics.codec}` : null,
+ diagnostics.bitrate ? `Bitrate: ${Math.round(diagnostics.bitrate / 1_000_000)} Mbps` : null,
+ `VideoEncoder: ${"VideoEncoder" in window ? "available" : "unavailable"}`,
+ ].filter(Boolean);
+
+ return `${diagnostics.formatLabel} export failed\n${details.join("\n")}`;
+ }
+
+ function buildSaveDiagnosticMessage(formatLabel: "GIF" | "Video", reason?: string) {
+ return `${formatLabel} export save failed${reason ? `\nReason: ${reason}` : ""}`;
+ }
+
+const CAPTION_WORD_CHOICES = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] as const;
+
export default function VideoEditor() {
const {
state: editorState,
@@@ -1785,133 -1960,19 +2015,146 @@@
}
}, []);
+ const generateAutoCaptions = useCallback(
+ async (minWords: number, maxWords: number) => {
+ if (!videoPath) {
+ toast.error(t("errors.noVideoLoaded"));
+ return;
+ }
+ if (isAutoCaptioningRef.current) {
+ toast.error(t("autoCaptions.busy"));
+ return;
+ }
+ const minW = Math.max(1, Math.min(minWords, maxWords));
+ const maxW = Math.max(minW, maxWords);
+
+ isAutoCaptioningRef.current = true;
+ setIsAutoCaptioning(true);
+ const toastId = toast.loading(t("autoCaptions.generating"));
+ try {
+ const { samples, truncated, durationSec } = await extractMono16kFromVideoUrl(videoPath);
+ if (!Number.isFinite(durationSec) || durationSec <= 0 || samples.length < 800) {
+ toast.dismiss(toastId);
+ toast.error(t("autoCaptions.noAudio"));
+ return;
+ }
+
+ const { samples: speechSamples, trimSec } = trimLeadingSilenceMono16k(samples);
+ if (speechSamples.length < 800) {
+ toast.dismiss(toastId);
+ toast.error(t("autoCaptions.noAudio"));
+ return;
+ }
+
+ const trimMs = Math.round(trimSec * 1000);
+ const trimRegionsForTranscribe = shiftTrimRegionsMsForCaptionBuffer(trimRegions, trimMs);
+
+ const transcribeOptions = {
+ onStatus: (phase: "model" | "transcribe") => {
+ if (phase === "model") {
+ toast.loading(t("autoCaptions.loadingModel"), { id: toastId });
+ }
+ },
+ };
+
+ let { segments: segmentsRaw, granularity } = await transcribeMono16kToSegments(
+ speechSamples,
+ {
+ trimRegions: trimRegionsForTranscribe,
+ ...transcribeOptions,
+ },
+ );
+ let transcribedFromTrimmedBuffer = true;
+
+ // Some recordings come back empty after leading-silence trimming even though the full
+ // source has recognizable speech. Retry once against the untouched audio buffer before
+ // giving up so we do not show "no speech detected" for a spoken clip.
+ if (segmentsRaw.length === 0 && trimSec > 0) {
+ ({ segments: segmentsRaw, granularity } = await transcribeMono16kToSegments(samples, {
+ trimRegions,
+ ...transcribeOptions,
+ }));
+ transcribedFromTrimmedBuffer = false;
+ }
+
+ const segments =
+ transcribedFromTrimmedBuffer && trimSec > 0
+ ? segmentsRaw.map((s) => ({
+ ...s,
+ startSec: s.startSec + trimSec,
+ endSec: s.endSec + trimSec,
+ }))
+ : segmentsRaw;
+
+ let { regions, nextNumericId, nextZIndex } = captionSegmentsToAnnotationRegions(
+ segments,
+ nextAnnotationIdRef.current,
+ nextAnnotationZIndexRef.current,
+ {
+ minWordsPerCaption: minW,
+ maxWordsPerCaption: maxW,
+ timestampGranularity: granularity,
+ },
+ );
+
+ if (regions.length === 0 && segments.length > 0) {
+ ({ regions, nextNumericId, nextZIndex } = captionSegmentsToAnnotationRegions(
+ segments,
+ nextAnnotationIdRef.current,
+ nextAnnotationZIndexRef.current,
+ {
+ minWordsPerCaption: 1,
+ maxWordsPerCaption: Number.MAX_SAFE_INTEGER,
+ timestampGranularity: granularity,
+ },
+ ));
+ }
+
+ if (regions.length === 0) {
+ toast.dismiss(toastId);
+ toast.info(t("autoCaptions.noneHeard"));
+ return;
+ }
+
+ pushState((prev) => ({ annotationRegions: [...prev.annotationRegions, ...regions] }));
+ nextAnnotationIdRef.current = nextNumericId;
+ nextAnnotationZIndexRef.current = nextZIndex;
+
+ toast.dismiss(toastId);
+ if (truncated) {
+ toast.info(
+ t("autoCaptions.truncated", {
+ minutes: String(Math.round(MAX_CAPTION_AUDIO_SEC / 60)),
+ }),
+ );
+ }
+ toast.success(t("autoCaptions.done", { count: String(regions.length) }));
+ } catch (e) {
+ console.error(e);
+ toast.dismiss(toastId);
+ const detail = e instanceof Error ? e.message : String(e);
+ toast.error(t("autoCaptions.failed"), { description: detail });
+ } finally {
+ isAutoCaptioningRef.current = false;
+ setIsAutoCaptioning(false);
+ }
+ },
+ [videoPath, trimRegions, pushState, t],
+ );
+
+ const handleSaveDiagnostic = useCallback(async () => {
+ const result = await window.electronAPI.saveDiagnostic({
+ error: exportError ?? "Manual diagnostic export",
+ projectState: editorState,
+ logs: [],
+ });
+ if (result.success) {
+ toast.success("Diagnostic file saved");
+ } else if (!result.canceled) {
+ toast.error("Failed to save diagnostic file");
+ }
+ }, [exportError, editorState]);
+
if (loading) {
return (
<div className="flex items-center justify-center h-screen bg-background">
@@@ -1966,95 -2027,16 +2209,95 @@@
</DialogContent>
</Dialog>
+ <Dialog open={showAutoCaptionsDialog} onOpenChange={setShowAutoCaptionsDialog}>
+ <DialogContent
+ className="sm:max-w-md"
+ style={{ WebkitAppRegion: "no-drag" } as CSSProperties}
+ >
+ <DialogHeader>
+ <DialogTitle>{t("autoCaptions.dialogTitle")}</DialogTitle>
+ <DialogDescription>{t("autoCaptions.dialogDescription")}</DialogDescription>
+ </DialogHeader>
+ <div className="grid gap-4 py-2">
+ <div className="grid gap-2">
+ <Label htmlFor="caption-min-words">{t("autoCaptions.minWords")}</Label>
+ <Select
+ value={String(captionWordsMin)}
+ onValueChange={(v) => {
+ const n = Number.parseInt(v, 10);
+ setCaptionWordsMin(n);
+ if (n > captionWordsMax) setCaptionWordsMax(n);
+ }}
+ >
+ <SelectTrigger id="caption-min-words" className="h-9">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {CAPTION_WORD_CHOICES.map((n) => (
+ <SelectItem key={`min-${n}`} value={String(n)}>
+ {t("autoCaptions.wordsCount", { count: String(n) })}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+ <div className="grid gap-2">
+ <Label htmlFor="caption-max-words">{t("autoCaptions.maxWords")}</Label>
+ <Select
+ value={String(captionWordsMax)}
+ onValueChange={(v) => {
+ const n = Number.parseInt(v, 10);
+ setCaptionWordsMax(n);
+ if (n < captionWordsMin) setCaptionWordsMin(n);
+ }}
+ >
+ <SelectTrigger id="caption-max-words" className="h-9">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {CAPTION_WORD_CHOICES.map((n) => (
+ <SelectItem key={`max-${n}`} value={String(n)}>
+ {t("autoCaptions.wordsCount", { count: String(n) })}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+ </div>
+ <DialogFooter className="gap-2 sm:gap-0">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => setShowAutoCaptionsDialog(false)}
+ className="border-white/20 bg-transparent text-white hover:bg-white/10"
+ >
+ {t("autoCaptions.dialogCancel")}
+ </Button>
+ <Button
+ type="button"
+ disabled={isAutoCaptioning}
+ onClick={() => {
+ setShowAutoCaptionsDialog(false);
+ void generateAutoCaptions(captionWordsMin, captionWordsMax);
+ }}
+ className="bg-[#34B27B] text-white hover:bg-[#34B27B]/90"
+ >
+ {t("autoCaptions.generate")}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+
<div
- className="h-10 flex-shrink-0 bg-[#09090b]/80 backdrop-blur-md border-b border-white/5 flex items-center justify-between px-6 z-50"
+ className="h-11 flex-shrink-0 bg-[#070809]/85 backdrop-blur-xl border-b border-white/[0.07] flex items-center justify-between px-5 z-50 shadow-[0_1px_0_rgba(255,255,255,0.03)]"
- style={{ WebkitAppRegion: "drag" } as React.CSSProperties}
+ style={{ WebkitAppRegion: "drag" } as CSSProperties}
>
<div
className="flex-1 flex items-center gap-1"
- style={{ WebkitAppRegion: "no-drag" } as React.CSSProperties}
+ style={{ WebkitAppRegion: "no-drag" } as CSSProperties}
>
<div
- className={`flex items-center gap-1 px-2 py-1 rounded-md text-white/50 hover:text-white/90 hover:bg-white/10 transition-all duration-150 ${isMac ? "ml-14" : "ml-2"}`}
+ className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-white/50 hover:text-white/90 hover:bg-white/[0.08] transition-all duration-150 ${isMac ? "ml-14" : "ml-2"}`}
>
<Languages size={14} />
<select