fix(studio-server): preview copies of long clips with sound finish again

The piece join ran with ffmpeg's -xerror once it moved onto the shared concat input, which made the timestamp repair at each seam of a clip with sound fatal: the copy failed, its pieces stayed, and the clip waited for a copy that never came. The join opts out of -xerror; the video-only render joins keep it.
This commit is contained in:
Miguel Angel Simon Sierra
2026-11-19 15:37:02 -05:00
parent 98f548447e
commit 65342bf045
3 changed files with 39 additions and 5 deletions
+5 -2
View File
@@ -273,9 +273,12 @@ export function concatListText(
* Concat input for a list HyperFrames wrote: entries open only as local mov, matroska or concat
* files (an ffconcat entry is followed in safe mode), and `-xerror` fails at a refused entry.
*/
export function concatListInputArgs(concatListPath: string): string[] {
export function concatListInputArgs(
concatListPath: string,
{ exitOnError = true }: { exitOnError?: boolean } = {},
): string[] {
return [
"-xerror",
...(exitOnError ? ["-xerror"] : []),
"-protocol_whitelist",
"file",
"-f",
@@ -272,8 +272,7 @@ describe("resolveProxy on a long source", () => {
await answerAll(calls);
await result;
const joinArgs = calls.at(-1)!.args;
expect(joinArgs.slice(1, 14)).toEqual([
"-xerror",
expect(joinArgs.slice(1, 13)).toEqual([
"-protocol_whitelist",
"file",
"-f",
@@ -365,6 +364,36 @@ describe("resolveProxy on a long source", () => {
60_000,
);
it.skipIf(!realFfmpeg || !findFfBinary("ffprobe"))(
"joins the pieces of a source with sound into one copy that keeps its sound",
async () => {
vi.resetModules();
vi.doUnmock("./mediaMetadata.js");
vi.doMock("@hyperframes/core/preview-proof", () => ({ previewToken: () => "a".repeat(64) }));
const { resolveProxy } = await import("./proxyTranscoder.js");
const projectDir = realpathSync(tmpProject());
const sourcePath = join(projectDir, "talk.mp4");
execFileSync(realFfmpeg!, [
...["-v", "error", "-f", "lavfi", "-i", `color=c=blue:s=32x32:r=2:d=${LONG_SECONDS}`],
...["-f", "lavfi", "-i", `sine=frequency=440:sample_rate=48000:d=${LONG_SECONDS}`],
...["-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", sourcePath],
]);
const proxyPath = await resolveProxy(projectDir, sourcePath);
const streams = execFileSync(
findFfBinary("ffprobe")!,
[
...["-v", "error", "-show_entries", "stream=codec_type:format=duration"],
...["-of", "csv=p=0", "--", proxyPath],
],
{ encoding: "utf8" },
).split("\n");
expect(streams).toEqual(expect.arrayContaining(["video", "audio"]));
expect(Number(streams.find((line) => /^[\d.]+$/.test(line)))).toBeCloseTo(LONG_SECONDS, 0);
},
60_000,
);
it("encodes every piece again when the project shipped pieces at the names it can predict", async () => {
const { spawn, calls } = createSpawnSpy();
const { resolveProxy, getProxyCachePath } = await loadModule(
@@ -850,10 +850,12 @@ async function runFfmpeg(
}
}
const LET_FFMPEG_MOVE_SOUND_TIMESTAMPS_AT_SEAMS = { exitOnError: false };
function concatArgs(listPath: string, target: string, variant: ProxyVariant): string[] {
return [
"-y",
...concatListInputArgs(listPath),
...concatListInputArgs(listPath, LET_FFMPEG_MOVE_SOUND_TIMESTAMPS_AT_SEAMS),
"-c",
"copy",
...(variant === "h264" ? ["-movflags", "+faststart"] : []),