Skip to content

Write HTML. Render video. Built for agents.

fix(engine): sample VFR video by timestamp so it does not freeze on FFmpeg 8 (#5572)

James Russo6afcb4839563
diff --git a/packages/engine/src/services/extractionCache.test.ts b/packages/engine/src/services/extractionCache.test.ts
index 58339b923c..81b5ca54d3 100644
--- a/packages/engine/src/services/extractionCache.test.ts
+++ b/packages/engine/src/services/extractionCache.test.ts
@@ -67,8 +67,8 @@ function seedPartialDir(entry: { dir: string; keyHash: string }, frameContent: s
}
describe("extractionCache constants", () => {
- it("exposes the v6 schema prefix", () => {
- expect(SCHEMA_PREFIX).toBe("hfcache-v6-");
+ it("exposes the v7 schema prefix", () => {
+ expect(SCHEMA_PREFIX).toBe("hfcache-v7-");
});
it("exposes the frame filename prefix shared with the extractor", () => {
@@ -286,6 +286,19 @@ describe("lookupCacheEntry / markCacheEntryComplete", () => {
expect(lookup.entry.dir).toBe(join(tmpRoot, `${SCHEMA_PREFIX}${keyHash.slice(0, 16)}`));
});
+ it("does not reuse a complete v6 entry, whose VFR frames were sampled by packet duration", () => {
+ const input = base(sourceFile);
+ const keyHash = computeCacheKey(input);
+ const staleV6Dir = join(tmpRoot, `hfcache-v6-${keyHash.slice(0, 16)}`);
+ mkdirSync(staleV6Dir, { recursive: true });
+ writeFileSync(join(staleV6Dir, "frame_00001.jpg"), "old", "utf-8");
+ writeFileSync(join(staleV6Dir, COMPLETE_SENTINEL), "", "utf-8");
+
+ const lookup = lookupCacheEntry(tmpRoot, input);
+ expect(lookup.hit).toBe(false);
+ expect(lookup.entry.dir).toBe(join(tmpRoot, `${SCHEMA_PREFIX}${keyHash.slice(0, 16)}`));
+ });
+
it("misses on an empty cache root", () => {
const lookup = lookupCacheEntry(tmpRoot, base(sourceFile));
expect(lookup.hit).toBe(false);
diff --git a/packages/engine/src/services/extractionCache.ts b/packages/engine/src/services/extractionCache.ts
index ab2297404f..5990992af6 100644
--- a/packages/engine/src/services/extractionCache.ts
+++ b/packages/engine/src/services/extractionCache.ts
@@ -62,7 +62,7 @@ export const GC_MARKER = ".hf-last-gc";
* Current schema version. Bump it whenever extraction writes different frames for the same key,
* or warm entries keep serving the old frames across a deploy. Each bump's commit says why.
*/
-export const SCHEMA_PREFIX = "hfcache-v6-";
+export const SCHEMA_PREFIX = "hfcache-v7-";
/** Truncated hex chars of SHA-256 used for the entry directory name. */
const KEY_HEX_CHARS = 16;
diff --git a/packages/engine/src/services/videoFrameExtractor.concurrency.test.ts b/packages/engine/src/services/videoFrameExtractor.concurrency.test.ts
index 502aa81645..a7323debb7 100644
--- a/packages/engine/src/services/videoFrameExtractor.concurrency.test.ts
+++ b/packages/engine/src/services/videoFrameExtractor.concurrency.test.ts
@@ -91,7 +91,7 @@ describe.skipIf(process.platform === "win32")("extractAllVideoFrames ffmpeg conc
expect(Math.max(...alive)).toBe(1);
}, 120_000);
- it("gives a variable-frame-rate clip's two-process pipeline one slot", async () => {
+ it("runs a variable-frame-rate clip's ffmpeg in the one slot", async () => {
const clips = await Promise.all(
[0, 1].map((i) =>
synth(`vfr-${i}`, `color=c=0x${i ? "28C83C" : "C83C28"}:s=32x32:d=2:r=60`, [
@@ -100,8 +100,8 @@ describe.skipIf(process.platform === "win32")("extractAllVideoFrames ffmpeg conc
),
);
const alive = await aliveCounts("vfr", clips, 1, 30);
- expect(alive).toHaveLength(4);
- expect(Math.max(...alive)).toBeLessThanOrEqual(2);
+ expect(alive).toHaveLength(2);
+ expect(Math.max(...alive)).toBe(1);
}, 60_000);
it("lets a cancelled extraction leave the queue while another holds the slot", async () => {
diff --git a/packages/engine/src/services/videoFrameExtractor.test.ts b/packages/engine/src/services/videoFrameExtractor.test.ts
index 672f1cb351..921ebd18af 100644
--- a/packages/engine/src/services/videoFrameExtractor.test.ts
+++ b/packages/engine/src/services/videoFrameExtractor.test.ts
@@ -2444,6 +2444,59 @@ describe.skipIf(!HAS_FFMPEG)("extractAllVideoFrames on a VFR source", () => {
expect(result.totalFrames).toBe(3);
}, 60_000);
+ // With B-frames, mp4 packet durations are decode-order gaps, so a frame can claim 0.5s while
+ // the next one starts 17ms later. Each slot must still show the frame on screen at its time:
+ // `-fps_mode cfr` on ffmpeg 8 held such a frame for 14 slots and cut the still before a gap short.
+ it("samples a B-frame VFR source by timestamp, not by packet duration", async () => {
+ const source = join(FIXTURE_DIR, "vfr_bframes.mp4");
+ const synth = await runFfmpeg([
+ "-y",
+ "-v",
+ "error",
+ "-f",
+ "lavfi",
+ "-i",
+ "testsrc2=s=320x180:d=4:rate=60",
+ "-vf",
+ "select='not(between(n\\,30\\,89))*not(between(n\\,150\\,179))'",
+ "-fps_mode",
+ "vfr",
+ "-c:v",
+ "libx264",
+ "-preset",
+ "medium",
+ "-bf",
+ "3",
+ "-g",
+ "600",
+ "-pix_fmt",
+ "yuv420p",
+ source,
+ ]);
+ if (!synth.success) throw new Error(`fixture synthesis failed: ${synth.stderr.slice(-400)}`);
+ const distinctFrames = (paths: Iterable<string>) =>
+ new Set([...paths].map((path) => readFileSync(path).toString("base64"))).size;
+
+ // 2.5s to 3s is a still; every 30fps slot after it lands on its own 60fps source frame.
+ const afterGap = await extractVideoFramesRange(source, "vfr-bframes-after-gap", 2.5, 1.5, {
+ fps: 30,
+ outputDir: join(FIXTURE_DIR, "out-vfr-bframes-after-gap"),
+ format: "png",
+ });
+ expect(afterGap.metadata.isVFR).toBe(true);
+ expect(afterGap.totalFrames).toBe(45);
+ const slots = [...afterGap.framePaths.entries()].sort(([a], [b]) => a - b);
+ expect(distinctFrames(slots.slice(0, 15).map(([, path]) => path))).toBe(1);
+ expect(distinctFrames(slots.slice(15).map(([, path]) => path))).toBe(30);
+
+ const endsOnStill = await extractVideoFramesRange(source, "vfr-bframes-still", 0, 3, {
+ fps: 30,
+ outputDir: join(FIXTURE_DIR, "out-vfr-bframes-still"),
+ format: "png",
+ });
+ expect(endsOnStill.totalFrames).toBe(90);
+ }, 60_000);
+
it("produces the expected frame count for a mid-file segment", async () => {
const outputDir = join(FIXTURE_DIR, "out-mid-segment");
mkdirSync(outputDir, { recursive: true });
@@ -3751,7 +3804,7 @@ describe.skipIf(!HAS_ZSCALE)("forced-SDR HDR extraction", () => {
}, 60_000);
// A second process would read the frames back without the HDR10 light-level metadata the tone map uses.
- it("tone-maps a VFR HDR10 window in one process, exactly as the unfiltered resample would", async () => {
+ it("tone-maps a VFR HDR10 window in one process, as the reference tone map would", async () => {
const source = join(fixtureDir, "pq-vfr-4000nit.mp4");
const synthesized = await runFfmpeg([
"-y",
@@ -3807,7 +3860,8 @@ describe.skipIf(!HAS_ZSCALE)("forced-SDR HDR extraction", () => {
expect(result.metadata.isVFR).toBe(true);
const referenceFrames = readdirSync(referenceDir).sort();
- expect(result.totalFrames).toBe(referenceFrames.length);
+ // One slot per 30fps tick before 0.616666s; x265 packet durations cut the reference's still short.
+ expect(result.totalFrames).toBe(19);
expect(readFileSync(result.framePaths.get(0)!)).toEqual(
readFileSync(join(referenceDir, referenceFrames[0]!)),
);
diff --git a/packages/engine/src/services/videoFrameExtractor.ts b/packages/engine/src/services/videoFrameExtractor.ts
index 3a271e2efe..b2b0d71e51 100644
--- a/packages/engine/src/services/videoFrameExtractor.ts
+++ b/packages/engine/src/services/videoFrameExtractor.ts
@@ -57,7 +57,7 @@ import {
UrlDownloadError,
writeUrlDownloadTelemetry,
} from "../utils/urlDownloader.js";
-import { runFfmpeg, runFfmpegPipeline, type RunFfmpegResult } from "../utils/runFfmpeg.js";
+import { runFfmpeg, type RunFfmpegResult } from "../utils/runFfmpeg.js";
import { isFfmpegFilterAvailable } from "../utils/psnrFilterAvailability.js";
import { DEFAULT_CONFIG, type EngineConfig } from "../config.js";
import { unwrapTemplate } from "../utils/htmlTemplate.js";
@@ -127,9 +127,9 @@ export function isVideoFrameFormat(value: unknown): value is VideoFrameFormat {
/**
* Resolve the frame count produced for a requested extraction duration.
*
- * CFR extraction uses FFmpeg's fps filter, whose end boundary rounds to the
- * nearest frame. The VFR path normalizes with `-fps_mode cfr -r`, whose end
- * boundary rounds up. Keep this calculation shared by superset slicing and
+ * Both paths sample with FFmpeg's fps filter. A CFR window ends at the nearest
+ * frame boundary; a VFR window rounds up, keeping the slot a trailing still
+ * covers. Keep this calculation shared by superset slicing and
* producer coverage accounting so a complete VFR extraction cannot be
* rejected because the two paths disagree by one frame.
*/
@@ -297,8 +297,8 @@ function sdrToHdrTransformKey(transfer: HdrTransfer): string {
* reflects max-across-parallel-workers, not sum.
* - hdrPreflightMs includes its probe-time sibling (hdrProbeMs); the
* probe-only field is a finer decomposition, not a separate carve-out.
- * - vfrPreflightCount reports sources classified as VFR and routed through
- * the one-pass `-fps_mode cfr -r` extraction path. DEFINITION CHANGE:
+ * - vfrPreflightCount reports sources classified as VFR and extracted with
+ * a rounded-up frame count. DEFINITION CHANGE:
* before the one-pass refactor, vfrPreflightMs timed a per-source
* VFR-to-CFR re-encode and could reach seconds; it now times only the
* (promise-cached) classification probe and is expected to be ~0.
@@ -829,61 +829,6 @@ function chromeGuessForUntaggedMatrix(metadata: VideoMetadata): string[] {
return [`setparams=colorspace=${hd ? "bt709" : "smpte170m"}`];
}
-/** Pixel formats nut carries as raw video unchanged on ffmpeg 5.1 to 8.1 (yuvj only loses its range). */
-const NUT_RAW_PIXEL_FORMATS = new Set([
- "yuv420p",
- "yuvj420p",
- "yuv422p",
- "yuvj422p",
- "yuv444p",
- "yuvj444p",
- "yuva420p",
- "yuva444p",
- "yuv440p",
- "yuv411p",
- "yuv410p",
- "yuva422p",
- "yuv420p10le",
- "yuv422p10le",
- "yuv444p10le",
- "yuva420p10le",
- "yuva444p10le",
- "yuv420p12le",
- "nv12",
- "nv21",
- "yuyv422",
- "uyvy422",
- "gray",
- "gray10le",
- "ya8",
- "gbrp",
- "gbrap",
- "gbrp10le",
- "gbrp12le",
- "gbrap10le",
- "rgb24",
- "bgr24",
- "rgba",
- "bgra",
- "argb",
- "abgr",
- "rgb48le",
- "rgba64le",
-]);
-
-/** nut drops colour tags, so raw frames get the source's back before any other filter reads them. */
-function restoreSourceColourFilter(metadata: VideoMetadata): string[] {
- const tags = [
- ["range", metadata.colorRange],
- ["colorspace", metadata.colorSpace?.colorSpace],
- ["color_primaries", metadata.colorSpace?.colorPrimaries],
- ["color_trc", metadata.colorSpace?.colorTransfer],
- ].filter(([, value]) => value && value !== "unknown" && value !== "reserved");
- return tags.length > 0
- ? [`setparams=${tags.map(([key, value]) => `${key}=${value}`).join(":")}`]
- : [];
-}
-
/**
* Longest stretch of output one ffmpeg process extracts. `ffmpegProcessTimeout` bounds a
* single process, so one process over a long clip timed out however much time the render
@@ -1036,8 +981,8 @@ export async function extractVideoFramesRange(
const toneMappedToSdr = options.toneMapHdrToSdr === true && isHdr && (await toneMapsWithZscale());
const decodeWithVideoToolbox = isHdr && isMacOS && !toneMappedToSdr;
- const sampleCfrAtOutputFps = !options.finalFrameOnly && !metadata.isVFR;
- if (options.frameRanges && !sampleCfrAtOutputFps) {
+ const sampleAtOutputFps = !options.finalFrameOnly;
+ if (options.frameRanges && (!sampleAtOutputFps || metadata.isVFR)) {
throw new Error("frameRanges extraction needs a constant-frame-rate source");
}
@@ -1066,7 +1011,7 @@ export async function extractVideoFramesRange(
args.push("-i", videoPath, "-ss", String(startTime), "-frames:v", "1");
} else {
// An accurate seek drops the frame on screen at startTime; the fps sampling below needs it.
- if (sampleCfrAtOutputFps) args.push("-noaccurate_seek");
+ if (sampleAtOutputFps) args.push("-noaccurate_seek");
args.push("-ss", String(startTime), "-i", videoPath, "-t", String(duration));
}
@@ -1074,7 +1019,7 @@ export async function extractVideoFramesRange(
if (decodeWithVideoToolbox) {
vfFilters.push("format=nv12");
}
- if (sampleCfrAtOutputFps) {
+ if (sampleAtOutputFps) {
// Each slot takes the last frame starting at or before its time. Ticks of 2 ms or finer
// first shift half a tick, absorbing container rounding (WebM/MKV use whole ms).
vfFilters.push(
@@ -1110,59 +1055,31 @@ export async function extractVideoFramesRange(
encodeArgs.push("-y", outputPattern);
const runOptions = { signal, timeout: ffmpegProcessTimeout };
- const resampleVfrToCfr = !options.finalFrameOnly && metadata.isVFR;
- if (resampleVfrToCfr) args.push("-fps_mode", "cfr", "-r", ffmpegFps);
- let processResult: RunFfmpegResult;
- if (
- resampleVfrToCfr &&
- vfFilters.length > 0 &&
- !isHdr &&
- NUT_RAW_PIXEL_FORMATS.has(metadata.pixelFormat ?? "")
- ) {
- // ffmpeg <6.1 ignores frame durations in CFR resampling once any -vf is set,
- // cutting a trailing still short, so the SDR filters run in a second process.
- processResult = await inExtractionSlot(
- () =>
- runFfmpegPipeline(
- [...args, "-an", "-sn", "-dn", "-c:v", "rawvideo", "-f", "nut", "pipe:1"],
- [
- "-f",
- "nut",
- "-i",
- "pipe:0",
- "-vf",
- [...restoreSourceColourFilter(metadata), ...vfFilters].join(","),
- "-fps_mode",
- "passthrough",
- ...encodeArgs,
- ],
+ const filterArgs = vfFilters.length > 0 ? ["-vf", vfFilters.join(",")] : [];
+ const segmentFrames = Math.round(EXTRACTION_SEGMENT_SECONDS * fps);
+ const totalFrames = extractionFrameCountForDuration(duration, normalizedFps, metadata.isVFR);
+ // A VFR window rounds its frame count up, and only the segments' `-frames:v` bound
+ // emits that last slot: the fps filter ends a `-t` window at the nearest slot. A
+ // decimal rate counts zero frames here and keeps the `-t` window.
+ const boundVfrFrameCount = metadata.isVFR && totalFrames > 0;
+ const processResult =
+ sampleAtOutputFps && (options.frameRanges || boundVfrFrameCount || totalFrames > segmentFrames)
+ ? await runSegmentedExtraction({
+ decodeArgs,
+ filterAndEncodeArgs: [...filterArgs, ...encodeArgs],
+ videoPath,
+ startTime,
+ fps,
+ segments: splitFrameRanges(
+ options.frameRanges ?? [{ firstFrame: 0, frames: totalFrames }],
+ segmentFrames,
+ ),
runOptions,
- ),
- signal,
- );
- } else {
- const filterArgs = vfFilters.length > 0 ? ["-vf", vfFilters.join(",")] : [];
- const segmentFrames = Math.round(EXTRACTION_SEGMENT_SECONDS * fps);
- const totalFrames = extractionFrameCountForDuration(duration, normalizedFps, false);
- processResult =
- sampleCfrAtOutputFps && (options.frameRanges || totalFrames > segmentFrames)
- ? await runSegmentedExtraction({
- decodeArgs,
- filterAndEncodeArgs: [...filterArgs, ...encodeArgs],
- videoPath,
- startTime,
- fps,
- segments: splitFrameRanges(
- options.frameRanges ?? [{ firstFrame: 0, frames: totalFrames }],
- segmentFrames,
- ),
- runOptions,
- })
- : await inExtractionSlot(
- () => runFfmpeg([...args, ...filterArgs, ...encodeArgs], runOptions),
- signal,
- );
- }
+ })
+ : await inExtractionSlot(
+ () => runFfmpeg([...args, ...filterArgs, ...encodeArgs], runOptions),
+ signal,
+ );
if (processResult.failureReason === "external_interruption") {
throw new VideoSourceExtractionError(
"external_interruption",
@@ -1714,11 +1631,8 @@ function buildSupersetGroup(
): SupersetGroupPlan | null {
if (misses.length < 2) return null;
if (misses.some(({ work }) => work.finalFrameOnly)) return null;
- // VFR normalization (`-fps_mode cfr -r`) establishes its duplicate/drop
- // phase relative to each seek. A union extraction therefore cannot be
- // sliced into the same frames as independently sought member ranges, even
- // when their offsets land on an integral output-frame boundary. Keep VFR
- // ranges direct until the extractor has a proven absolute timestamp phase.
+ // VFR ranges round their frame counts up, so a union extraction's slices
+ // are not proven to match independently sought member ranges. Keep them direct.
if (misses.some(({ work }) => work.metadata.isVFR)) return null;
const baseStart = Math.min(...misses.map(({ work }) => work.video.mediaStart));
if (!misses.every(({ work }) => isIntegralFrameOffset(work.video.mediaStart - baseStart, fps))) {
diff --git a/packages/engine/src/utils/runFfmpeg.test.ts b/packages/engine/src/utils/runFfmpeg.test.ts
index 402685284e..0e6b90cb72 100644
--- a/packages/engine/src/utils/runFfmpeg.test.ts
+++ b/packages/engine/src/utils/runFfmpeg.test.ts
@@ -1,18 +1,8 @@
-import { spawnSync } from "node:child_process";
import { EventEmitter } from "node:events";
-import { mkdtempSync, readdirSync, rmSync } from "node:fs";
-import { tmpdir } from "node:os";
-import { join, resolve } from "node:path";
+import { resolve } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
-import {
- formatFfmpegError,
- isExternalFfmpegInterruption,
- runFfmpegPipeline,
- ffmpegStatsReader,
-} from "./runFfmpeg.js";
-
-const HAS_FFMPEG = spawnSync("ffmpeg", ["-version"]).status === 0;
+import { formatFfmpegError, isExternalFfmpegInterruption, ffmpegStatsReader } from "./runFfmpeg.js";
describe("isExternalFfmpegInterruption", () => {
const base = {
@@ -186,114 +176,6 @@ describe("runFfmpeg binary resolution", () => {
});
});
-describe.skipIf(!HAS_FFMPEG)("runFfmpegPipeline", () => {
- const rawFrames = (source: string) => [
- "-v",
- "error",
- "-f",
- "lavfi",
- "-i",
- source,
- "-c:v",
- "rawvideo",
- "-f",
- "nut",
- "pipe:1",
- ];
-
- it("hands every producer frame to the consumer", async () => {
- const dir = mkdtempSync(join(tmpdir(), "hf-pipeline-"));
- try {
- const result = await runFfmpegPipeline(rawFrames("testsrc2=s=64x16:d=0.2:r=30"), [
- "-v",
- "error",
- "-f",
- "nut",
- "-i",
- "pipe:0",
- "-fps_mode",
- "passthrough",
- join(dir, "f_%03d.png"),
- ]);
- expect(result.success, result.stderr).toBe(true);
- expect(readdirSync(dir)).toHaveLength(6);
- } finally {
- rmSync(dir, { recursive: true, force: true });
- }
- }, 30_000);
-
- it("fails with the producer's error when the producer cannot start its input", async () => {
- const result = await runFfmpegPipeline(
- [
- "-v",
- "error",
- "-i",
- join(tmpdir(), "hf-missing-input.mp4"),
- "-c:v",
- "rawvideo",
- "-f",
- "nut",
- "pipe:1",
- ],
- ["-v", "error", "-f", "nut", "-i", "pipe:0", "-f", "null", "-"],
- );
- expect(result.success).toBe(false);
- expect(result.stderr).toMatch(/hf-missing-input\.mp4/);
- }, 30_000);
-
- it("stops an endless producer when the consumer fails", async () => {
- const startedAt = Date.now();
- const result = await runFfmpegPipeline(
- rawFrames("testsrc2=s=320x240:r=30"),
- ["-v", "error", "-f", "nut", "-i", "pipe:0", "-vf", "hf_missing_filter", "-f", "null", "-"],
- { timeout: 20_000 },
- );
- expect(result.success).toBe(false);
- expect(result.terminationReason).toBe("exit");
- expect(result.stderr).toMatch(/hf_missing_filter/);
- expect(Date.now() - startedAt).toBeLessThan(10_000);
- }, 30_000);
-});
-
-describe("runFfmpegPipeline start failure", () => {
- afterEach(() => {
- vi.resetModules();
- vi.doUnmock("child_process");
- });
-
- it("releases a waiting consumer when the producer cannot start", async () => {
- const { PassThrough, Writable } = await import("node:stream");
- const producer = Object.assign(new EventEmitter(), {
- stdout: new PassThrough(),
- stderr: new PassThrough(),
- kill: vi.fn(),
- pid: 4242,
- });
- const consumer = Object.assign(new EventEmitter(), {
- stdout: new PassThrough(),
- stderr: new PassThrough(),
- stdin: new Writable({ write: (_chunk, _encoding, done) => done() }),
- kill: vi.fn(),
- pid: 4243,
- });
- consumer.stdin.on("finish", () => consumer.emit("close", 1, null));
- const spawn = vi.fn().mockReturnValueOnce(producer).mockReturnValueOnce(consumer);
- vi.resetModules();
- vi.doMock("child_process", () => ({ spawn }));
- const { runFfmpegPipeline: pipeline } = await import("./runFfmpeg.js");
-
- const startedAt = Date.now();
- const pending = pipeline(["-i", "in"], ["-i", "pipe:0"], { timeout: 5_000 });
- consumer.emit("spawn");
- producer.emit("error", Object.assign(new Error("spawn EMFILE"), { code: "EMFILE" }));
- const result = await pending;
-
- expect(result.success).toBe(false);
- expect(result.terminationReason).toBe("spawn_error");
- expect(Date.now() - startedAt).toBeLessThan(2_000);
- });
-});
-
describe("ffmpegStatsReader", () => {
it("reads frames and output seconds from stats lines split anywhere across chunks", () => {
const stats: unknown[] = [];
@@ -327,19 +209,15 @@ describe("a run whose signal already aborted", () => {
vi.resetModules();
});
- it("starts no ffmpeg, alone or as a pipeline", async () => {
+ it("starts no ffmpeg", async () => {
const spawn = vi.fn();
vi.resetModules();
vi.doMock("child_process", () => ({ spawn }));
- const { runFfmpeg, runFfmpegPipeline } = await import("./runFfmpeg.js");
- const signal = AbortSignal.abort();
+ const { runFfmpeg } = await import("./runFfmpeg.js");
- const single = await runFfmpeg(["-version"], { signal });
- const piped = await runFfmpegPipeline(["-i", "in"], ["-i", "pipe:0"], { signal });
+ const result = await runFfmpeg(["-version"], { signal: AbortSignal.abort() });
expect(spawn).not.toHaveBeenCalled();
- for (const result of [single, piped]) {
- expect(result).toMatchObject({ success: false, terminationReason: "abort" });
- }
+ expect(result).toMatchObject({ success: false, terminationReason: "abort" });
});
});
diff --git a/packages/engine/src/utils/runFfmpeg.ts b/packages/engine/src/utils/runFfmpeg.ts
index 4d97042410..c0d841719f 100644
--- a/packages/engine/src/utils/runFfmpeg.ts
+++ b/packages/engine/src/utils/runFfmpeg.ts
@@ -201,45 +201,3 @@ export async function runFfmpeg(args: string[], opts?: RunFfmpegOptions): Promis
});
return toResult(await managed.wait());
}
-
-/**
- * Runs `ffmpeg <producerArgs> | ffmpeg <consumerArgs>`. Fails when either side
- * fails and reports the first failure, its stderr last so error tails show it.
- */
-export async function runFfmpegPipeline(
- producerArgs: string[],
- consumerArgs: string[],
- opts?: RunFfmpegOptions,
-): Promise<RunFfmpegResult> {
- if (opts?.signal?.aborted) return { ...ABORTED_BEFORE_START };
- const deadlineAtMs = Date.now() + (opts?.timeout ?? DEFAULT_TIMEOUT);
- const producer = spawnFfmpeg(producerArgs);
- const consumer = spawnFfmpeg(consumerArgs);
- // Either side ending early, or failing to start, must release the other from the pipe.
- consumer.stdin?.on("error", () => {});
- for (const event of ["close", "error"] as const) {
- consumer.once(event, () => producer.stdout?.destroy());
- producer.once(event, () => consumer.stdin?.end());
- }
- if (consumer.stdin) producer.stdout?.pipe(consumer.stdin);
- const settleOrder: ManagedChildProcessOutcome[] = [];
- const outcomes = await Promise.all(
- [producer, consumer].map((child) =>
- new ManagedChildProcess(child, {
- signal: opts?.signal,
- deadlineAtMs,
- onStderr: opts?.onStderr,
- })
- .wait()
- .then((outcome) => {
- settleOrder.push(outcome);
- return outcome;
- }),
- ),
- );
- const reported = settleOrder.find((outcome) => !succeeded(outcome)) ?? outcomes[1]!;
- const stderr = [...outcomes.filter((outcome) => outcome !== reported), reported]
- .map((outcome) => outcome.stderr)
- .join("");
- return toResult(reported, stderr);
-}
diff --git a/packages/producer/src/services/render/videoFrameCoverage.ts b/packages/producer/src/services/render/videoFrameCoverage.ts
index 60067a01e2..a64dc88703 100644
--- a/packages/producer/src/services/render/videoFrameCoverage.ts
+++ b/packages/producer/src/services/render/videoFrameCoverage.ts
@@ -134,9 +134,9 @@ export function resolveVideoCoverageThreshold(
}
/**
- * Count frames in a clip's authored `[start,end)` window. CFR extraction uses
- * FFmpeg's `-vf fps=<fps>` and rounds to the nearest output-frame boundary;
- * VFR extraction uses `-fps_mode cfr -r <fps>` and rounds up. Missing entries
+ * Count frames in a clip's authored `[start,end)` window. CFR extraction
+ * rounds to the nearest output-frame boundary and VFR extraction rounds up,
+ * as `extractionFrameCountForDuration` does. Missing entries
* retain the fail-closed `ceil` default. Positive sub-frame clips emit one.
*/
export function expectedFramesForClip(
diff --git a/packages/producer/tests/vfr-screen-recording/output/output.mp4 b/packages/producer/tests/vfr-screen-recording/output/output.mp4
index 7821859afb..11091ff3b6 100644
--- a/packages/producer/tests/vfr-screen-recording/output/output.mp4
+++ b/packages/producer/tests/vfr-screen-recording/output/output.mp4
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:0bc043a8148f8c1f76ddeba3b76e2ddafe718981cec572c59c57dc4c076dcb49
-size 571145
+oid sha256:005a5c831c4c43d594d976581cd6ffac00c9ceb28e3020deef37fcdfda019529
+size 455962