Skip to content

Commit 5d5ef88

Browse files
committed
fix(core): count one frame per grade sample on ffmpeg 8
1 parent d1cd9da commit 5d5ef88

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎packages/cli/src/media-use/lib/grade-analyzer.mjs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function readSignalStats(ffmpegPath, mediaPath, seekSeconds, frames) {
232232
"-i",
233233
mediaPath,
234234
"-vf",
235-
"format=yuv444p,signalstats,metadata=print:file=-",
235+
`trim=end_frame=${frames},format=yuv444p,signalstats,metadata=print:file=-`,
236236
"-frames:v",
237237
String(frames),
238238
"-f",
@@ -243,9 +243,12 @@ function readSignalStats(ffmpegPath, mediaPath, seekSeconds, frames) {
243243
);
244244
} catch (error) {
245245
if (error.code !== "ETIMEDOUT") throw error;
246-
const at = seekSeconds === null ? "" : ` at ${seekSeconds.toFixed(1)}s`;
246+
const target =
247+
seekSeconds === null
248+
? `the first ${frames} frames`
249+
: `the frame at ${seekSeconds.toFixed(1)}s`;
247250
throw new Error(
248-
`FFmpeg took longer than ${timeoutMs / 1000}s to decode one frame${at}; set HYPERFRAMES_ANALYZE_TIMEOUT_MS to allow more`,
251+
`FFmpeg took longer than ${timeoutMs / 1000}s to measure ${target}; set HYPERFRAMES_ANALYZE_TIMEOUT_MS to allow more`,
249252
);
250253
}
251254
}

‎packages/core/src/mediaGradeAnalyzer.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,22 @@ describe("analyzeMediaGrade", () => {
6767
vi.stubEnv("HYPERFRAMES_ANALYZE_TIMEOUT_MS", "1");
6868
try {
6969
expect(() => analyzeMediaGrade(makeLongHlgClip())).toThrow(
70-
/took longer than 0\.001s to decode one frame at 12\.0s; set HYPERFRAMES_ANALYZE_TIMEOUT_MS/,
70+
/took longer than 0\.001s to measure the frame at 12\.0s; set HYPERFRAMES_ANALYZE_TIMEOUT_MS/,
7171
);
7272
} finally {
7373
vi.unstubAllEnvs();
7474
}
7575
});
7676

77+
it("measures the clip the same way in the media-use copy", async () => {
78+
const vendored = await import(
79+
new URL("../../../packages/cli/src/media-use/lib/grade-analyzer.mjs", import.meta.url).href
80+
);
81+
expect(vendored.analyzeMediaGrade(makeLongHlgClip())).toEqual(
82+
analyzeMediaGrade(makeLongHlgClip()),
83+
);
84+
});
85+
7786
it("places one sample in the middle of each fifth of the clip", () => {
7887
expect(gradeSampleTimes(300)).toEqual([30, 90, 150, 210, 270]);
7988
});

‎packages/core/src/mediaGradeAnalyzer.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ function readSignalStats(
324324
"-i",
325325
mediaPath,
326326
"-vf",
327-
"format=yuv444p,signalstats,metadata=print:file=-",
327+
`trim=end_frame=${frames},format=yuv444p,signalstats,metadata=print:file=-`,
328328
"-frames:v",
329329
String(frames),
330330
"-f",
@@ -340,9 +340,12 @@ function readSignalStats(
340340
);
341341
} catch (error) {
342342
if ((error as NodeJS.ErrnoException).code !== "ETIMEDOUT") throw error;
343-
const at = seekSeconds === null ? "" : ` at ${seekSeconds.toFixed(1)}s`;
343+
const target =
344+
seekSeconds === null
345+
? `the first ${frames} frames`
346+
: `the frame at ${seekSeconds.toFixed(1)}s`;
344347
throw new Error(
345-
`FFmpeg took longer than ${timeoutMs / 1000}s to decode one frame${at}; set HYPERFRAMES_ANALYZE_TIMEOUT_MS to allow more`,
348+
`FFmpeg took longer than ${timeoutMs / 1000}s to measure ${target}; set HYPERFRAMES_ANALYZE_TIMEOUT_MS to allow more`,
346349
);
347350
}
348351
}

0 commit comments

Comments
 (0)