Skip to content

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

fix(cli): clean up an audio export's render without --out, and name the track id audioId takes

EtienneLescot729a917275a7
diff --git a/electron/cli/runnerHost.test.ts b/electron/cli/runnerHost.test.ts
index 80b760cf0..a6a046ead 100644
--- a/electron/cli/runnerHost.test.ts
+++ b/electron/cli/runnerHost.test.ts
@@ -88,7 +88,7 @@ describe("createRunnerHost", () => {
await writeFile(audioRenderPath(outPath), "mp4");
await writeFile(path.join(dir, "demo.mp4"), "mp4");
const { ipc, host } = setup();
- const exportOf = (format: "wav" | "mp4", out: string): CliRequest => ({
+ const exportOf = (format: "wav" | "mp4", out: string | null): CliRequest => ({
kind: "export",
projectPath: path.join(dir, "p.openscreen"),
outPath: out,
@@ -106,10 +106,15 @@ describe("createRunnerHost", () => {
const audio = host.start(exportOf("wav", outPath));
const video = host.start(exportOf("mp4", path.join(dir, "demo.mp4.render.mp4")));
await writeFile(path.join(dir, "demo.mp4.render.mp4.render.mp4"), "mp4");
+ // Without --out, a failed run reports no outputPath: the render beside p.wav still goes.
+ const failed = host.start(exportOf("wav", null));
+ await writeFile(audioRenderPath(path.join(dir, "p.wav")), "mp4");
ipc.call(1, "cli-done", { success: true, outputPath: outPath });
ipc.call(2, "cli-done", { success: true });
+ ipc.call(3, "cli-done", { success: false, error: "render failed" });
await audio.done;
await video.done;
+ await failed.done;
expect((await readdir(dir)).sort()).toEqual(["demo.mp4", "demo.mp4.render.mp4.render.mp4"]);
await rm(dir, { recursive: true, force: true });
});
diff --git a/electron/cli/runnerHost.ts b/electron/cli/runnerHost.ts
index 7dd6e3a90..b192e9f4e 100644
--- a/electron/cli/runnerHost.ts
+++ b/electron/cli/runnerHost.ts
@@ -12,6 +12,7 @@ import {
type CliDoneResult,
type CliProgressEvent,
type CliRequest,
+ defaultExportPath,
isAudioExportFormat,
} from "../../src/lib/cliContracts";
@@ -109,12 +110,15 @@ export function createRunnerHost<W extends RunnerWindow>(
runs.set(id, { request, handlers, resolve });
});
// An audio export renders an MP4 beside its output that the runner cannot delete.
+ const audioFormat =
+ request.kind === "export" && isAudioExportFormat(request.format) ? request.format : null;
const done =
- request.kind === "export" && isAudioExportFormat(request.format)
+ request.kind === "export" && audioFormat
? reported.then(async (result) => {
- const outPath = request.outPath ?? result.outputPath;
- if (outPath)
- await rm(audioRenderPath(outPath), { force: true }).catch(() => undefined);
+ // Derived as the runner derives it: a failed run reports no outputPath.
+ const outPath =
+ request.outPath ?? defaultExportPath(request.projectPath, audioFormat);
+ await rm(audioRenderPath(outPath), { force: true }).catch(() => undefined);
return result;
})
: reported;
diff --git a/electron/mcp/media-tools.ts b/electron/mcp/media-tools.ts
index 7bfaf9ae3..9aff90912 100644
--- a/electron/mcp/media-tools.ts
+++ b/electron/mcp/media-tools.ts
@@ -917,7 +917,7 @@ export function createMediaTools(deps: MediaToolDeps): MediaTools {
"exportAudio",
{
description:
- "Write a project's audio to a WAV or an M4A, exactly as exportVideo's MP4 mixes it: the recording's sound, the imported tracks with their offset, trims, gain and fades, through the same cuts and speed regions. With audioId (addAudio's, or an audioTracks id), only that track, alone, placed where it plays in the export: the file lasts as long as the video, silent around the track. It renders the project as an export does, so it takes about as long as exportVideo.",
+ "Write a project's audio to a WAV or an M4A, exactly as exportVideo's MP4 mixes it: the recording's sound, the imported tracks with their offset, trims, gain and fades, through the same cuts and speed regions. With audioId (addAudio's, or an audioTracks entry's trackId, its id when it has no trackId), only that track, alone, placed where it plays in the export: the file lasts as long as the video, silent around the track. It renders the project as an export does, so it takes about as long as exportVideo.",
inputSchema: z.object({
projectId: z.string(),
path: z.string().describe(AUDIO_PATH_DESCRIPTIONS[transport]),
diff --git a/src/cli/CliExportRunner.tsx b/src/cli/CliExportRunner.tsx
index e0e28dc7d..3f0041e51 100644
--- a/src/cli/CliExportRunner.tsx
+++ b/src/cli/CliExportRunner.tsx
@@ -22,6 +22,7 @@ import {
audioRenderPath,
type CliDoneResult,
type CliExportRequest,
+ defaultExportPath,
isAudioExportFormat,
} from "@/lib/cliContracts";
import { GIF_SIZE_PRESETS, type GifSizePreset } from "@/lib/exporter";
@@ -34,10 +35,6 @@ import { buildNativeClipList, buildSceneDescription } from "@/native/sceneDescri
import { type ExportProject, loadDocumentProject } from "./exportProject";
import { loadCliProject, probeVideoDimensions } from "./loadCliProject";
-function replaceExtension(filePath: string, newExtension: string): string {
- return filePath.replace(/\.(openscreen|json)$/i, "") + newExtension;
-}
-
/** Mirrors ExportDialog.gifOutputDims: from the "Source" size, cap height at the preset, keep even. */
function gifOutputDims(
preset: GifSizePreset,
@@ -92,7 +89,7 @@ async function runExport(request: CliExportRequest): Promise<CliDoneResult> {
const gifSizePreset = request.gifSizePreset ?? editor.gifSizePreset;
const gifLoop = request.gifLoop ?? editor.gifLoop;
const mp4FrameRate = request.mp4FrameRate;
- const outPath = request.outPath ?? replaceExtension(request.projectPath, `.${format}`);
+ const outPath = request.outPath ?? defaultExportPath(request.projectPath, format);
// Use the same per-clip auto-zoom suggestions as the editor, including its default span and
// anchoring behavior.
if (request.autoZoom) {
diff --git a/src/lib/cliContracts.ts b/src/lib/cliContracts.ts
index 53a38612c..c1cf7b91a 100644
--- a/src/lib/cliContracts.ts
+++ b/src/lib/cliContracts.ts
@@ -12,6 +12,11 @@ export function isAudioExportFormat(format: string | null): format is AudioExpor
return format === "wav" || format === "m4a";
}
+/** Where an export without --out lands: beside the project, with the format's extension. */
+export function defaultExportPath(projectPath: string, format: string): string {
+ return `${projectPath.replace(/\.(openscreen|json)$/i, "")}.${format}`;
+}
+
/** Where the audio export renders its MP4 before taking the audio out: beside the output. */
export function audioRenderPath(outPath: string): string {
return `${outPath}.render.mp4`;
diff --git a/website/docs/cli.md b/website/docs/cli.md
index 78974e196..f2bf6198a 100644
--- a/website/docs/cli.md
+++ b/website/docs/cli.md
@@ -139,7 +139,7 @@ openscreen export demo.openscreen -o voice.wav --track audio_1234 # one impo
|---|---|
| `-o, --out <path>` | Output file. The extension, `.mp4`, `.gif`, `.wav` or `.m4a`, sets the format. Default: the project's path with the format's extension |
| `--format <mp4\|gif\|wav\|m4a>` | Override the format stored in the project. Must agree with `--out`. `wav` and `m4a` write the project's audio only, as the MP4 mixes it |
-| `--track <audioId>` | WAV and M4A only: write this imported audio track alone, where it plays in the MP4, with its offset, trims, gain and fades. The file lasts as long as the video. The id is the track's `audioId` (from `addAudio`, or `audioTracks` in the project) |
+| `--track <audioId>` | WAV and M4A only: write this imported audio track alone, where it plays in the MP4, with its offset, trims, gain and fades. The file lasts as long as the video. The id is the track's `audioId` (from `addAudio`), or an `audioTracks` entry's `trackId` in the project, its `id` when it has no `trackId` |
| `--quality <medium\|good\|source>` | Output size: `medium` is 720p, `good` is 1080p, `source` follows the smallest clip after cropping, so it never upscales. MP4 only: a GIF starts from the source size, as in the app |
| `--fps <24\|30\|60>` | MP4 frame rate (default 60) |
| `--gif-fps <15\|20\|25\|30>` | GIF frame rate |