mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-10 22:20:14 +00:00
fix(cli): align video output boundaries (#2490)
* fix(cli): align video output boundaries * test(cli): honor CI ffmpeg fixture path * test(cli): decouple duration precedence from ffmpeg * test(cli): pin half-open video boundaries * test(producer): refresh style 7 boundary golden
This commit is contained in:
@@ -4,7 +4,11 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { applyResolutionPreset, injectTailwindBrowserScript } from "./init.js";
|
||||
import {
|
||||
applyResolutionPreset,
|
||||
injectTailwindBrowserScript,
|
||||
resolveVideoDurationSeconds,
|
||||
} from "./init.js";
|
||||
|
||||
const cliEntry = resolve(fileURLToPath(import.meta.url), "..", "..", "cli.ts");
|
||||
const tailwindScript =
|
||||
@@ -177,6 +181,26 @@ describe("hyperframes init flag rename", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("uses the video stream duration when audio outlasts the final video frame", () => {
|
||||
expect(
|
||||
resolveVideoDurationSeconds({
|
||||
streamDuration: 1,
|
||||
frameDuration: 1,
|
||||
formatDuration: 1.2,
|
||||
}),
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it("falls through unusable stream durations before using the container duration", () => {
|
||||
expect(
|
||||
resolveVideoDurationSeconds({
|
||||
streamDuration: 0,
|
||||
frameDuration: Number.NaN,
|
||||
formatDuration: 1.2,
|
||||
}),
|
||||
).toBe(1.2);
|
||||
});
|
||||
|
||||
it("--audio with a missing file fails without creating the project directory", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "hf-init-test-"));
|
||||
const target = join(dir, "proj");
|
||||
|
||||
@@ -81,6 +81,22 @@ const TAILWIND_BROWSER_SRC = `https://cdn.jsdelivr.net/npm/@tailwindcss/browser@
|
||||
const TAILWIND_BROWSER_INTEGRITY =
|
||||
"sha384-v5YF9xS+gLRWdvrQ0u/WRbCkjSIH0NjHIPe8tBL1ZRrmI7PiSH6LLdzs0aAIMCuh";
|
||||
|
||||
export function resolveVideoDurationSeconds({
|
||||
streamDuration,
|
||||
frameDuration,
|
||||
formatDuration,
|
||||
}: {
|
||||
streamDuration: number;
|
||||
frameDuration: number;
|
||||
formatDuration: number;
|
||||
}): number {
|
||||
return (
|
||||
[streamDuration, frameDuration, formatDuration].find(
|
||||
(duration) => Number.isFinite(duration) && duration > 0,
|
||||
) ?? DEFAULT_META.durationSeconds
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ffprobe helper — shells out to ffprobe to avoid engine dependency
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -103,6 +119,8 @@ function probeVideo(filePath: string): VideoMeta | undefined {
|
||||
height?: number;
|
||||
r_frame_rate?: string;
|
||||
avg_frame_rate?: string;
|
||||
duration?: string;
|
||||
nb_frames?: string;
|
||||
}[];
|
||||
format?: { duration?: string };
|
||||
} = JSON.parse(raw);
|
||||
@@ -124,11 +142,18 @@ function probeVideo(filePath: string): VideoMeta | undefined {
|
||||
}
|
||||
}
|
||||
|
||||
const durationStr = parsed.format?.duration;
|
||||
const durationSeconds = durationStr !== undefined ? parseFloat(durationStr) : 5;
|
||||
const streamDuration = parseFloat(videoStream.duration ?? "");
|
||||
const frameCount = parseInt(videoStream.nb_frames ?? "", 10);
|
||||
const frameDuration = Number.isFinite(frameCount) && fps > 0 ? frameCount / fps : NaN;
|
||||
const formatDuration = parseFloat(parsed.format?.duration ?? "");
|
||||
const durationSeconds = resolveVideoDurationSeconds({
|
||||
streamDuration,
|
||||
frameDuration,
|
||||
formatDuration,
|
||||
});
|
||||
|
||||
return {
|
||||
durationSeconds: Number.isNaN(durationSeconds) ? 5 : durationSeconds,
|
||||
durationSeconds,
|
||||
width: videoStream.width ?? 1920,
|
||||
height: videoStream.height ?? 1080,
|
||||
fps,
|
||||
|
||||
Reference in New Issue
Block a user