Skip to content

Commit 3631ee3

Browse files
fix(producer): keep clip playback rate in distributed video metadata (#4736)
parsePlanVideosJson rebuilt each video from a fixed field list that had no playbackRate, so chunk workers indexed extracted frames at rate 1 while the planner mixed audio at the authored rate. A data-playback-rate="1.5" clip showed its picture at 1x in planV2/renderChunkV2/assembleV2 output, while the single-process render was correct. Carry playbackRate through the parser, accepting a finite number or a rate lane, and pin it with a JSON round-trip test that checks the chunk-side frame lookup for 1.5x, 0.5x and a rate lane.
1 parent 2eeaefb commit 3631ee3

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎packages/producer/src/services/distributed/shared.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { dirname, join } from "node:path";
99
import { existsSync, readFileSync } from "node:fs";
1010
import { fileURLToPath } from "node:url";
1111
import { promisify } from "node:util";
12-
import { type Fps } from "@hyperframes/core";
12+
import { type Fps, type RateSpec } from "@hyperframes/core";
1313
import {
1414
getFfmpegBinary,
1515
MIXED_AUDIO_FILENAME,
@@ -173,6 +173,17 @@ function readNonNegativeInteger(value: unknown, field: string): number {
173173
return value;
174174
}
175175

176+
function readRateSpec(value: unknown, field: string): RateSpec | undefined {
177+
if (value === undefined) return undefined;
178+
if (typeof value === "number") return readFiniteNumber(value, field);
179+
const lane = readRecord(value, field);
180+
if (!Array.isArray(lane.points)) {
181+
metadataError(`${field}.points`, "must be an array");
182+
}
183+
// The planner serialized this lane from the clip's parsed `data-automation` rate lane.
184+
return lane as unknown as Exclude<RateSpec, number>;
185+
}
186+
176187
function readVideoMetadata(
177188
value: unknown,
178189
field: string,
@@ -233,6 +244,7 @@ export function parsePlanVideosJson(value: unknown): PlanVideosJson {
233244
start: readFiniteNumber(video.start, `${field}.start`),
234245
end: readFiniteNumber(video.end, `${field}.end`),
235246
mediaStart: readFiniteNumber(video.mediaStart, `${field}.mediaStart`),
247+
playbackRate: readRateSpec(video.playbackRate, `${field}.playbackRate`),
236248
loop: readBoolean(video.loop, `${field}.loop`),
237249
hasAudio: readBoolean(video.hasAudio, `${field}.hasAudio`),
238250
};

‎packages/producer/src/services/distributed/videoMetadata.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,55 @@ describe("distributed video metadata", () => {
145145
);
146146
});
147147

148+
it.each([
149+
{ name: "1.5x", playbackRate: 1.5, expectedFrame: 3 },
150+
{ name: "0.5x", playbackRate: 0.5, expectedFrame: 1 },
151+
{
152+
name: "rate lane",
153+
playbackRate: {
154+
target: "rate",
155+
points: [
156+
{ t: 0, v: 1.5 },
157+
{ t: 4, v: 1.5 },
158+
],
159+
},
160+
expectedFrame: 3,
161+
},
162+
])(
163+
"keeps a $name clip's playback rate across the plan boundary",
164+
({ playbackRate, expectedFrame }) => {
165+
const metadata = extractedMetadata();
166+
const written = buildPlanVideosJson({
167+
videos: [video({ playbackRate })],
168+
extracted: [metadata],
169+
compositionEnd: 8,
170+
});
171+
const read = parsePlanVideosJson(JSON.parse(JSON.stringify(written)));
172+
const lookup = createFrameLookupTable(read.videos, [extractedFrames(metadata)]);
173+
174+
expect(read.videos[0]?.playbackRate).toEqual(playbackRate);
175+
expect(lookup.getActiveFramePayloads(3).get("hero")?.frameIndex).toBe(expectedFrame);
176+
},
177+
);
178+
179+
it("rejects a malformed playback rate", () => {
180+
const valid = buildPlanVideosJson({
181+
videos: [video()],
182+
extracted: [extractedMetadata()],
183+
compositionEnd: 8,
184+
});
185+
186+
expect(() =>
187+
parsePlanVideosJson({ ...valid, videos: [{ ...valid.videos[0], playbackRate: "1.5" }] }),
188+
).toThrow(/playbackRate must be an object/);
189+
expect(() =>
190+
parsePlanVideosJson({
191+
...valid,
192+
videos: [{ ...valid.videos[0], playbackRate: { target: "rate" } }],
193+
}),
194+
).toThrow(/playbackRate.points must be an array/);
195+
});
196+
148197
it.each([
149198
{ loop: false, expectedFrame: 3 },
150199
{ loop: true, expectedFrame: 2 },

0 commit comments

Comments
 (0)