mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
fix(cli): measure probe --normalize replaces a link at the output name (#8738)
* fix(cli): measure probe --normalize replaces a link at the output name normalize() handed the final --normalize path straight to ffmpeg, so a symbolic link already at that name was followed and the file it points at was overwritten with the encoded copy. It now encodes through ffmpegToFile(), which writes under a private name and renames over the requested one, as the other measure writers already do. A failed encode leaves nothing at the destination. Adds a test with the output name linked to a file outside the project: that file stays untouched and the output name becomes a regular file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): drop the comment the staged write no longer needs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f2087431b3
commit
f041181ebb
@@ -4,10 +4,10 @@ import { jsonArg, runMeasure, videoArg } from "../../measure/command.js";
|
||||
import {
|
||||
ffmpegBin,
|
||||
ffmpegInput,
|
||||
ffmpegToFile,
|
||||
Fix,
|
||||
probeVideo,
|
||||
round,
|
||||
runFfmpeg,
|
||||
type VideoInfo,
|
||||
} from "../../measure/media.js";
|
||||
import { toneMapReferenceNits } from "@hyperframes/core";
|
||||
@@ -62,10 +62,13 @@ function normalize(info: VideoInfo, out: string): { path: string; fps: string }
|
||||
);
|
||||
}
|
||||
makeOutputFolder(dirname(out));
|
||||
runFfmpeg([
|
||||
...["-y", ...ffmpegInput(info.path), "-vf", [...filters, "format=yuv420p"].join(",")],
|
||||
...["-c:v", "libx264", "-crf", "12", "-preset", "medium", "-c:a", "aac", "-b:a", "192k", out],
|
||||
]);
|
||||
ffmpegToFile(
|
||||
[
|
||||
...["-y", ...ffmpegInput(info.path), "-vf", [...filters, "format=yuv420p"].join(",")],
|
||||
...["-c:v", "libx264", "-crf", "12", "-preset", "medium", "-c:a", "aac", "-b:a", "192k"],
|
||||
],
|
||||
out,
|
||||
);
|
||||
return { path: out, fps };
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import {
|
||||
lstatSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readFileSync,
|
||||
rmSync,
|
||||
symlinkSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterAll, describe, expect, it } from "vitest";
|
||||
import { probeReport } from "../commands/measure/probe.js";
|
||||
|
||||
const root = mkdtempSync(join(tmpdir(), "hf-probe-test-"));
|
||||
afterAll(() => rmSync(root, { recursive: true, force: true }));
|
||||
const hasFfmpeg = spawnSync("ffmpeg", ["-version"]).status === 0;
|
||||
|
||||
describe.skipIf(!hasFfmpeg)("measure probe --normalize", () => {
|
||||
const clip = join(root, "clip.mp4");
|
||||
spawnSync("ffmpeg", [
|
||||
...["-v", "error", "-y", "-f", "lavfi", "-i", "testsrc2=s=64x64:r=10:d=1"],
|
||||
...["-pix_fmt", "yuv420p", clip],
|
||||
]);
|
||||
|
||||
it("writes the copy over a link at the output name, never through it", () => {
|
||||
const project = join(root, "project");
|
||||
mkdirSync(project);
|
||||
const elsewhere = join(root, "elsewhere.txt");
|
||||
writeFileSync(elsewhere, "keep me");
|
||||
const out = join(project, "original.mp4");
|
||||
symlinkSync(elsewhere, out);
|
||||
|
||||
const report = probeReport(clip, out) as { normalized?: string };
|
||||
|
||||
expect(readFileSync(elsewhere, "utf8")).toBe("keep me");
|
||||
expect(report.normalized).toBe(out);
|
||||
expect(lstatSync(out).isFile()).toBe(true);
|
||||
expect(lstatSync(out).size).toBeGreaterThan(0);
|
||||
}, 60_000);
|
||||
});
|
||||
Reference in New Issue
Block a user