Create polished demo videos without editing skills. Mac/Windows/Linux
fix: serve video files via local HTTP server to fix loading on Windows
webadderall794e2944d6a6
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.tsindex c6abd25b..4eff6ece 100644--- a/electron/electron-env.d.ts+++ b/electron/electron-env.d.ts@@ -330,6 +330,9 @@ interface Window {getCurrentVideoPath: () => Promise<{ success: boolean; path?: string }>;clearCurrentVideoPath: () => Promise<{ success: boolean }>;deleteRecordingFile: (filePath: string) => Promise<{ success: boolean; error?: string }>;+ getLocalMediaUrl: (filePath: string) => Promise<+ { success: true; url: string } | { success: false }+ >;saveProjectFile: (projectData: unknown,suggestedName?: string,diff --git a/electron/ipc/register/project.ts b/electron/ipc/register/project.tsindex cf9b6208..96b31b56 100644--- a/electron/ipc/register/project.ts+++ b/electron/ipc/register/project.ts@@ -3,6 +3,7 @@ import fs from "node:fs/promises";import path from "node:path";import { dialog, ipcMain, shell } from "electron";import { RECORDINGS_DIR } from "../../appPaths";+import { buildMediaUrl, getMediaServerBaseUrl } from "../../mediaServer";import {PROJECT_FILE_EXTENSION,LEGACY_PROJECT_FILE_EXTENSIONS,@@ -377,4 +378,12 @@ export function registerProjectHandlers() {}});+ ipcMain.handle('get-local-media-url', (_, filePath: string) => {+ const baseUrl = getMediaServerBaseUrl();+ if (!baseUrl || !filePath) {+ return { success: false as const };+ }+ return { success: true as const, url: buildMediaUrl(baseUrl, filePath) };+ });+}diff --git a/electron/main.ts b/electron/main.tsindex 04c4efa6..4a572ac4 100644--- a/electron/main.ts+++ b/electron/main.ts@@ -23,6 +23,7 @@ import {killWindowsCaptureProcess,registerIpcHandlers,} from "./ipc/handlers";+import { ensureMediaServer } from "./mediaServer";import { ensurePackagedRendererServer } from "./rendererServer";import type { UpdateToastPayload } from "./updater";import {@@ -836,6 +837,12 @@ app.whenReady().then(async () => {}}+ try {+ await ensureMediaServer();+ } catch (error) {+ console.warn("[media-server] Failed to start media server:", error);+ }+registerIpcHandlers(createEditorWindowWrapper,createSourceSelectorWindowWrapper,diff --git a/electron/mediaServer.ts b/electron/mediaServer.tsnew file mode 100644index 00000000..c2c655c6--- /dev/null+++ b/electron/mediaServer.ts@@ -0,0 +1,192 @@+import { createReadStream } from "node:fs";+import fs from "node:fs/promises";+import { createServer, type IncomingMessage, type ServerResponse } from "node:http";+import path from "node:path";+import { approvedLocalReadPaths } from "./ipc/state";++const MEDIA_MIME_TYPES: Record<string, string> = {+ ".mp4": "video/mp4",+ ".webm": "video/webm",+ ".mov": "video/quicktime",+ ".mkv": "video/x-matroska",+ ".avi": "video/x-msvideo",+ ".wav": "audio/wav",+ ".mp3": "audio/mpeg",+ ".ogg": "audio/ogg",+ ".png": "image/png",+ ".jpg": "image/jpeg",+ ".jpeg": "image/jpeg",+};++let mediaServerBaseUrl: string | null = null;+let mediaServerStartPromise: Promise<string> | null = null;++function getMediaContentType(filePath: string): string {+ return MEDIA_MIME_TYPES[path.extname(filePath).toLowerCase()] ?? "application/octet-stream";+}++function isAllowedMediaPath(filePath: string): boolean {+ try {+ const resolved = path.resolve(filePath);+ return approvedLocalReadPaths.has(resolved);+ } catch {+ return false;+ }+}++async function handleMediaRequest(+ request: IncomingMessage,+ response: ServerResponse,+): Promise<void> {+ try {+ const url = new URL(request.url ?? "/", "http://127.0.0.1");++ if (url.pathname !== "/video") {+ response.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });+ response.end("Not Found");+ return;+ }++ const rawPath = url.searchParams.get("path");+ if (!rawPath) {+ response.writeHead(400, { "Content-Type": "text/plain; charset=utf-8" });+ response.end("Missing path parameter");+ return;+ }++ const resolvedPath = path.resolve(rawPath);+ if (!isAllowedMediaPath(resolvedPath)) {+ console.warn(`[media-server] Blocked access to unapproved path: ${resolvedPath}`);+ response.writeHead(403, { "Content-Type": "text/plain; charset=utf-8" });+ response.end("Forbidden");+ return;+ }++ const stat = await fs.stat(resolvedPath);+ if (!stat.isFile()) {+ response.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });+ response.end("Not Found");+ return;+ }++ const contentType = getMediaContentType(resolvedPath);+ const fileSize = stat.size;+ const rangeHeader = request.headers.range;++ if (rangeHeader) {+ const match = rangeHeader.match(/bytes=(\d+)-(\d*)/);+ if (!match) {+ response.writeHead(416, { "Content-Range": `bytes */${fileSize}` });+ response.end();+ return;+ }++ const start = Number.parseInt(match[1], 10);+ const end = match[2] ? Number.parseInt(match[2], 10) : fileSize - 1;++ if (start >= fileSize || end >= fileSize || start > end) {+ response.writeHead(416, { "Content-Range": `bytes */${fileSize}` });+ response.end();+ return;+ }++ const chunkSize = end - start + 1;+ response.writeHead(206, {+ "Content-Range": `bytes ${start}-${end}/${fileSize}`,+ "Accept-Ranges": "bytes",+ "Content-Length": String(chunkSize),+ "Content-Type": contentType,+ "Cache-Control": "no-cache",+ });++ if (request.method === "HEAD") {+ response.end();+ return;+ }++ const stream = createReadStream(resolvedPath, { start, end });+ stream.pipe(response);+ stream.on("error", () => {+ if (!response.headersSent) {+ response.writeHead(500, { "Content-Type": "text/plain" });+ }+ response.end();+ });+ } else {+ response.writeHead(200, {+ "Accept-Ranges": "bytes",+ "Content-Length": String(fileSize),+ "Content-Type": contentType,+ "Cache-Control": "no-cache",+ });++ if (request.method === "HEAD") {+ response.end();+ return;+ }++ const stream = createReadStream(resolvedPath);+ stream.pipe(response);+ stream.on("error", () => {+ if (!response.headersSent) {+ response.writeHead(500, { "Content-Type": "text/plain" });+ }+ response.end();+ });+ }+ } catch (error) {+ if ((error as NodeJS.ErrnoException)?.code === "ENOENT") {+ response.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });+ response.end("Not Found");+ return;+ }++ console.error("[media-server] Error handling request:", error);+ response.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });+ response.end("Internal Server Error");+ }+}++export function getMediaServerBaseUrl(): string | null {+ return mediaServerBaseUrl;+}++export async function ensureMediaServer(): Promise<string> {+ if (mediaServerBaseUrl) {+ return mediaServerBaseUrl;+ }++ if (mediaServerStartPromise) {+ return mediaServerStartPromise;+ }++ mediaServerStartPromise = new Promise((resolve, reject) => {+ const server = createServer((request, response) => {+ void handleMediaRequest(request, response);+ });++ server.once("error", (error) => {+ reject(error);+ });++ server.listen(0, "127.0.0.1", () => {+ const address = server.address();+ if (!address || typeof address === "string") {+ server.close();+ reject(new Error("Media server did not expose a TCP address"));+ return;+ }++ mediaServerBaseUrl = `http://127.0.0.1:${address.port}`;+ console.log(`[media-server] Listening at ${mediaServerBaseUrl}`);+ resolve(mediaServerBaseUrl);+ });+ });++ return mediaServerStartPromise;+}++export function buildMediaUrl(baseUrl: string, filePath: string): string {+ const resolved = path.resolve(filePath);+ return `${baseUrl}/video?path=${encodeURIComponent(resolved)}`;+}diff --git a/electron/preload.ts b/electron/preload.tsindex 1c5eb6fa..4ae5d8bf 100644--- a/electron/preload.ts+++ b/electron/preload.ts@@ -388,6 +388,11 @@ contextBridge.exposeInMainWorld("electronAPI", {deleteRecordingFile: (filePath: string) => {return ipcRenderer.invoke("delete-recording-file", filePath);},+ getLocalMediaUrl: (filePath: string) => {+ return ipcRenderer.invoke("get-local-media-url", filePath) as Promise<+ { success: true; url: string } | { success: false }+ >;+ },saveProjectFile: (projectData: unknown,suggestedName?: string,diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsxindex c63d2339..4863122c 100644--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@ -110,6 +110,7 @@ import {type EditorProjectData,fromFileUrl,normalizeProjectEditor,+ resolveVideoUrl,toFileUrl,validateProjectData,} from "./projectPersistence";@@ -551,6 +552,7 @@ export default function VideoEditor() {const [webcam, setWebcam] = useState<WebcamOverlaySettings>(initialEditorPreferences.webcam ?? DEFAULT_WEBCAM_OVERLAY,);+ const [resolvedWebcamVideoUrl, setResolvedWebcamVideoUrl] = useState<string | null>(null);const [zoomRegions, setZoomRegions] = useState<ZoomRegion[]>([]);const [cursorTelemetry, setCursorTelemetry] = useState<CursorTelemetryPoint[]>([]);const [selectedZoomId, setSelectedZoomId] = useState<string | null>(null);@@ -1459,7 +1461,7 @@ export default function VideoEditor() {setError(null);setVideoSourcePath(sourcePath);- setVideoPath(toFileUrl(sourcePath));+ setVideoPath(await resolveVideoUrl(sourcePath));setCurrentProjectPath(path ?? null);pendingFreshRecordingAutoZoomPathRef.current = null;if (normalizedEditor.webcam.sourcePath) {@@ -1687,7 +1689,7 @@ export default function VideoEditor() {}const sourcePath = fromFileUrl(smokeExportConfig.inputPath);- const sourceVideoUrl = toFileUrl(sourcePath);+ const sourceVideoUrl = await resolveVideoUrl(sourcePath);const smokeWebcamSourcePath = smokeExportConfig.webcamInputPath? fromFileUrl(smokeExportConfig.webcamInputPath): null;@@ -1746,7 +1748,7 @@ export default function VideoEditor() {const sessionResult = await window.electronAPI.getCurrentRecordingSession?.();if (sessionResult?.success && sessionResult.session?.videoPath) {const sourcePath = fromFileUrl(sessionResult.session.videoPath);- const sourceVideoUrl = toFileUrl(sourcePath);+ const sourceVideoUrl = await resolveVideoUrl(sourcePath);setVideoSourcePath(sourcePath);setVideoPath(sourceVideoUrl);setCurrentProjectPath(null);@@ -1765,7 +1767,7 @@ export default function VideoEditor() {const result = await window.electronAPI.getCurrentVideoPath();if (result.success && result.path) {const sourcePath = fromFileUrl(result.path);- const sourceVideoUrl = toFileUrl(sourcePath);+ const sourceVideoUrl = await resolveVideoUrl(sourcePath);setVideoSourcePath(sourcePath);setVideoPath(sourceVideoUrl);setCurrentProjectPath(null);@@ -1798,6 +1800,20 @@ export default function VideoEditor() {smokeExportConfig.webcamSize,]);+ useEffect(() => {+ let cancelled = false;+ if (!webcam.sourcePath) {+ setResolvedWebcamVideoUrl(null);+ return;+ }+ void resolveVideoUrl(webcam.sourcePath).then((url) => {+ if (!cancelled) setResolvedWebcamVideoUrl(url);+ });+ return () => {+ cancelled = true;+ };+ }, [webcam.sourcePath]);+useEffect(() => {if (!autoApplyFreshRecordingAutoZooms) {pendingFreshRecordingAutoZoomPathRef.current = null;@@ -2016,7 +2032,7 @@ export default function VideoEditor() {if (sourcePath !== videoSourcePath) {setVideoSourcePath(sourcePath);- setVideoPath(toFileUrl(sourcePath));+ setVideoPath(await resolveVideoUrl(sourcePath));}await syncActiveVideoSource(sourcePath, webcam.sourcePath ?? null);@@ -4909,7 +4925,7 @@ export default function VideoEditor() {webcam={webcam}webcamVideoPath={webcam.sourcePath- ? toFileUrl(webcam.sourcePath)+ ? resolvedWebcamVideoUrl: null}trimRegions={trimRegions}diff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsxindex e6021d90..045d9304 100644--- a/src/components/video-editor/VideoPlayback.tsx+++ b/src/components/video-editor/VideoPlayback.tsx@@ -2441,7 +2441,26 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(onDurationChange={(e) => {onDurationChange(e.currentTarget.duration);}}- onError={() => onError("Failed to load video")}+ onError={(e) => {+ const mediaError = e.currentTarget.error;+ const code = mediaError?.code;+ const msg = mediaError?.message;+ const detail =+ code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED+ ? "format not supported"+ : code === MediaError.MEDIA_ERR_NETWORK+ ? "network error"+ : code === MediaError.MEDIA_ERR_DECODE+ ? "decode error"+ : msg || `code ${code ?? "unknown"}`;+ console.error(+ "[VideoPlayback] Video load error:",+ detail,+ "src:",+ videoPath,+ );+ onError(`Failed to load video (${detail})`);+ }}/></div>);diff --git a/src/components/video-editor/projectPersistence.ts b/src/components/video-editor/projectPersistence.tsindex 3ce02651..81c59744 100644--- a/src/components/video-editor/projectPersistence.ts+++ b/src/components/video-editor/projectPersistence.ts@@ -258,6 +258,25 @@ export function deriveNextId(prefix: string, ids: string[]): number {return max + 1;}+/**+ * Resolve a local file path to a URL the `<video>` element can load.+ *+ * Prefers the local media HTTP server (works on all platforms regardless of+ * Chromium's `file://` restrictions). Falls back to a `file://` URL if the+ * media server is unavailable.+ */+export async function resolveVideoUrl(sourcePath: string): Promise<string> {+ try {+ const result = await window.electronAPI.getLocalMediaUrl(sourcePath);+ if (result.success) {+ return result.url;+ }+ } catch {+ // Media server unavailable — fall through to file:// URL.+ }+ return toFileUrl(sourcePath);+}+export function validateProjectData(candidate: unknown): candidate is EditorProjectData {if (!candidate || typeof candidate !== "object") return false;const project = candidate as Partial<EditorProjectData>;