Skip to content

Commit 50af764

Browse files
fix(producer): scale high-quality encode timeout (#3649)
1 parent 2ca4930 commit 50af764

2 files changed

Lines changed: 64 additions & 3 deletions

File tree

‎packages/producer/src/services/render/stages/encodeStage.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,65 @@ describe("runEncodeStage config plumbing", () => {
259259
});
260260
});
261261

262+
it("gives the reported long high-quality encode a 24x source-duration budget", async () => {
263+
const { runEncodeStage } = await import("./encodeStage.js");
264+
const input = makeInput();
265+
266+
await runEncodeStage(
267+
makeInput({
268+
job: {
269+
...input.job,
270+
config: { ...input.job.config, quality: "high" },
271+
duration: 331.273,
272+
},
273+
engineConfig: { ffmpegEncodeTimeout: 600_000 },
274+
}),
275+
);
276+
277+
expect(encodeFramesFromDirMock.mock.calls[0]?.[5]).toEqual({
278+
ffmpegEncodeTimeout: 7_950_552,
279+
});
280+
});
281+
282+
it("keeps the 4x budget for a standard encode", async () => {
283+
const { runEncodeStage } = await import("./encodeStage.js");
284+
const input = makeInput();
285+
286+
await runEncodeStage(
287+
makeInput({
288+
job: {
289+
...input.job,
290+
config: { ...input.job.config, quality: "standard" },
291+
duration: 331.273,
292+
},
293+
engineConfig: { ffmpegEncodeTimeout: 600_000 },
294+
}),
295+
);
296+
297+
expect(encodeFramesFromDirMock.mock.calls[0]?.[5]).toEqual({
298+
ffmpegEncodeTimeout: 1_325_092,
299+
});
300+
});
301+
302+
it("preserves a larger operator timeout for high-quality encoding", async () => {
303+
const { runEncodeStage } = await import("./encodeStage.js");
304+
const input = makeInput();
305+
const operatorConfig = { ffmpegEncodeTimeout: 9_000_000 };
306+
307+
await runEncodeStage(
308+
makeInput({
309+
job: {
310+
...input.job,
311+
config: { ...input.job.config, quality: "high" },
312+
duration: 331.273,
313+
},
314+
engineConfig: operatorConfig,
315+
}),
316+
);
317+
318+
expect(encodeFramesFromDirMock.mock.calls[0]?.[5]).toBe(operatorConfig);
319+
});
320+
262321
it("prefers engine config supplied by the orchestrator", async () => {
263322
const { runEncodeStage } = await import("./encodeStage.js");
264323
const orchestratorEngineConfig = { ffmpegEncodeTimeout: 54_321 };

‎packages/producer/src/services/render/stages/encodeStage.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,11 @@ export async function runEncodeStage(input: EncodeStageInput): Promise<EncodeSta
289289

290290
// ffmpegEncodeTimeout is a total wall-clock cap, not an inactivity timeout.
291291
// A fixed ten-minute cap reliably kills long high-quality disk-frame encodes
292-
// that are still making progress. Preserve larger operator overrides while
293-
// guaranteeing four seconds of encode budget per second of source video.
294-
const scaledEncodeTimeout = Math.ceil((job.duration ?? 0) * 4_000);
292+
// that are still making progress. High-quality CPU presets are substantially
293+
// slower, so reserve 24x source duration there while retaining the established
294+
// 4x budget for draft/standard and preserving larger operator overrides.
295+
const baseScaledEncodeTimeout = Math.ceil((job.duration ?? 0) * 4_000);
296+
const scaledEncodeTimeout = baseScaledEncodeTimeout * (job.config.quality === "high" ? 6 : 1);
295297
const videoEngineCfg =
296298
scaledEncodeTimeout > engineCfg.ffmpegEncodeTimeout
297299
? { ...engineCfg, ffmpegEncodeTimeout: scaledEncodeTimeout }

0 commit comments

Comments
 (0)