Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions electron/ipc/handlers/__tests__/demo.handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const fsMock = vi.hoisted(() => ({
vi.mock("fs/promises", () => fsMock);

vi.mock("fs", () => ({
readdirSync: vi.fn(() => ["frame_0001.png", "frame_0002.png", "frame_0003.png"]),
readdirSync: vi.fn(() => ["frame-000001.png", "frame-000002.png", "frame-000003.png"]),
mkdirSync: vi.fn(),
}));

Expand Down Expand Up @@ -196,7 +196,27 @@ describe("registerDemoHandlers", () => {
outputPath: "/tmp/out.mp4",
preset: "youtube-4k",
})
).rejects.toThrow("No PNG frames matching frame_NNNN.png found");
).rejects.toThrow("No PNG frames matching frame-NNNNNN.png found");
});

it("rejects old underscore-format frame names", async () => {
const fsMod = await import("fs");
(fsMod.readdirSync as ReturnType<typeof vi.fn>).mockReturnValueOnce([
"frame_0001.png",
"frame_0002.png",
"frame_0003.png",
]);

const handler = getEncodeHandler();
const event = makeEvent();

await expect(
handler(event, {
framesDir: "/tmp/old-format",
outputPath: "/tmp/out.mp4",
preset: "youtube-4k",
})
).rejects.toThrow("No PNG frames matching frame-NNNNNN.png found");
});

it("rejects on spawn error event", async () => {
Expand Down Expand Up @@ -303,7 +323,7 @@ describe("registerDemoHandlers", () => {

expect(spawnMock).toHaveBeenCalledWith(
expect.any(String),
expect.arrayContaining(["-c:v", "libx264"]),
expect.arrayContaining(["-i", "/tmp/frames/frame-%06d.png", "-c:v", "libx264"]),
expect.any(Object)
);
});
Expand Down
6 changes: 3 additions & 3 deletions electron/ipc/handlers/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,20 @@ export function registerDemoHandlers(deps: HandlerDependencies): () => void {
const { framesDir, outputPath, preset, fps = 30 } = payload;
const presetConfig = ENCODE_PRESETS[preset];

const framePattern = /^frame_\d{4}\.png$/;
const framePattern = /^frame-\d{6}\.png$/;
const pngFiles = fs
.readdirSync(framesDir)
.filter((f) => framePattern.test(f))
.sort();
if (pngFiles.length === 0) {
throw new Error(`No PNG frames matching frame_NNNN.png found in ${framesDir}`);
throw new Error(`No PNG frames matching frame-NNNNNN.png found in ${framesDir}`);
}
const totalFrames = pngFiles.length;

fs.mkdirSync(path.dirname(outputPath), { recursive: true });

const startTime = Date.now();
const inputPattern = path.join(framesDir, "frame_%04d.png");
const inputPattern = path.join(framesDir, "frame-%06d.png");

const args = [
"-y",
Expand Down