Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/producer/src/services/render/videoFrameCoverage.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// fallow-ignore-file code-duplication

import type { ExtractedFrames, VideoElement, VideoMetadata } from "@hyperframes/engine";
import { sourceTimeAt } from "@hyperframes/core";
import { describe, expect, it } from "vitest";
import {
assertVideoFrameCoverage,
Expand Down Expand Up @@ -177,6 +178,40 @@ describe("computeVideoFrameCoverage", () => {
expect(() => assertVideoFrameCoverage(reports, 0.95)).not.toThrow();
});

// fails without the fix: the error named only frame counts, so a field failure said nothing of the source's shape.
it("names the clip's source in the error's first sentence, so a cut report still says what the video was", () => {
const videos = [makeVideo({ id: "rec-end", start: 0, end: 34 / 30, mediaStart: 2.5 })];
const extracted = [makeExtracted("rec-end", 21, { fps: 60, durationSeconds: 4, isVFR: true })];
const reports = computeVideoFrameCoverage(videos, extracted, 30);
expect(reports[0]).toMatchObject({ expectedFrames: 34, capturedFrames: 21 });
expect(() => assertVideoFrameCoverage(reports, 0.95)).toThrow(
'Video "rec-end" captured 21 of expected 34 frames (coverage 61.8%, threshold 95.0%; ' +
"source h264, 60 fps, variable frame rate, plays to 4.000 s; clip 0.000-1.133 s reads source " +
"2.500-3.633 s at 1x).",
);
});

// fails without the fix: a ramp read as its first second's rate, and a video's lead hid inside "stream length".
it("names a speed ramp's whole source range and a lead before the video's first frame", () => {
const ramp = {
target: "rate",
points: [
{ t: 0, v: 1 },
{ t: 1, v: 3 },
],
};
const videos = [makeVideo({ id: "ramp", start: 0, end: 1, playbackRate: ramp })];
const extracted = [
makeExtracted("ramp", 10, { durationSeconds: 4, videoStreamDurationSeconds: 3.8 }),
];
extracted[0]!.metadata.videoStreamLeadSeconds = 0.2;
const reports = computeVideoFrameCoverage(videos, extracted, 30);
expect(() => assertVideoFrameCoverage(reports, 0.95)).toThrow(
"plays to 4.000 s, video from 0.200 s; clip 0.000-1.000 s reads source " +
`0.000-${sourceTimeAt(ramp, 1).toFixed(3)} s on a speed ramp).`,
);
});

it("rejects a short CFR clip missing the last output slot it covers", () => {
const videos = [makeVideo({ id: "aligned", start: 1 / 30, end: 0.28 })];
const reports = computeVideoFrameCoverage(videos, [makeExtracted("aligned", 7)], 30);
Expand Down
50 changes: 49 additions & 1 deletion packages/producer/src/services/render/videoFrameCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ export interface VideoFrameCoverageReport {
capturedFrames: number;
/** `capturedFrames / expectedFrames`; `1` when `expectedFrames === 0` (nothing to cover). */
ratio: number;
/** What the clip reads, when it was probed: the failure's message names it. */
source?: {
codec: string;
fps: number;
isVFR: boolean;
/** Where the video's last frame ends on the media timeline: the end the gate's expected frames stop at. */
playsTo: number;
/** Media time before the video's first frame, when the stream starts late. */
leadSeconds: number;
/** The span of source the clip's window reads, through its speed or ramp. */
readsFrom: number;
readsTo: number;
/** A number, or "ramp" when the speed changes over the clip. */
rate: number | "ramp";
};
}

const s3 = (seconds: number) => seconds.toFixed(3);

/** "; source h264, 60 fps, variable frame rate, plays to 4.000 s; clip 0.000-1.133 s reads source 2.500-3.633 s at 1x" */
function sourceWords(report: VideoFrameCoverageReport): string {
const s = report.source;
if (!s) return "";
const vfr = s.isVFR ? ", variable frame rate" : "";
const lead = s.leadSeconds > 0 ? `, video from ${s3(s.leadSeconds)} s` : "";
const speed = s.rate === "ramp" ? "on a speed ramp" : `at ${s.rate}x`;
return (
`; source ${s.codec}, ${s.fps} fps${vfr}, plays to ${s3(s.playsTo)} s${lead}; ` +
`clip ${s3(report.clipStart)}-${s3(report.clipEnd)} s reads source ${s3(s.readsFrom)}-${s3(s.readsTo)} s ${speed}`
);
}

/**
Expand Down Expand Up @@ -192,6 +222,23 @@ function expectedFramesForVideo(
return Math.min(slotFrames, sourceFrames);
}

function sourceOf(
video: VideoElement,
entry: ExtractedFrames,
): NonNullable<VideoFrameCoverageReport["source"]> {
const rate = normalizeRateSpec(video.playbackRate);
return {
codec: entry.metadata.videoCodec,
fps: entry.metadata.fps,
isVFR: entry.metadata.isVFR,
playsTo: resolvePlayableVideoDuration(entry.metadata),
leadSeconds: entry.metadata.videoStreamLeadSeconds ?? 0,
readsFrom: video.mediaStart,
readsTo: video.mediaStart + sourceTimeAt(rate, Math.max(0, video.end - video.start)),
rate: typeof rate === "number" ? rate : "ramp",
};
}

export function computeVideoFrameCoverage(
videos: readonly VideoElement[],
extracted: readonly ExtractedFrames[],
Expand Down Expand Up @@ -221,6 +268,7 @@ export function computeVideoFrameCoverage(
expectedFrames,
capturedFrames,
ratio,
...(entry && { source: sourceOf(video, entry) }),
});
}
return reports;
Expand Down Expand Up @@ -253,7 +301,7 @@ export function assertVideoFrameCoverage(
const suffix = sorted.length > 1 ? ` (+${sorted.length - 1} more clip(s) below threshold)` : "";
throw new VideoFrameCoverageError(
`Video "${worst.videoId}" captured ${worst.capturedFrames} of expected ${worst.expectedFrames} frames ` +
`(coverage ${pct}%, threshold ${thresholdPct}%). ` +
`(coverage ${pct}%, threshold ${thresholdPct}%${sourceWords(worst)}). ` +
`check/snapshot may pass while the encoded MP4 renders this clip blank, so the render is aborted ` +
`to prevent shipping a wrong MP4.${suffix} ` +
`Set HF_VIDEO_COVERAGE_THRESHOLD=0 to disable this gate.`,
Expand Down
15 changes: 3 additions & 12 deletions packages/producer/tests/iframe-render-compat/output/compiled.html
Git LFS file not shown
110 changes: 3 additions & 107 deletions packages/producer/tests/leaflet-adapter/output/compiled.html

Large diffs are not rendered by default.

169 changes: 3 additions & 166 deletions packages/producer/tests/mapbox-adapter/output/compiled.html

Large diffs are not rendered by default.

158 changes: 3 additions & 155 deletions packages/producer/tests/maplibre-adapter/output/compiled.html

Large diffs are not rendered by default.

128 changes: 3 additions & 125 deletions packages/producer/tests/missing-host-comp-id/output/compiled.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

34 changes: 3 additions & 31 deletions packages/producer/tests/portrait-edge-bleed/output/compiled.html

Large diffs are not rendered by default.

Binary file modified packages/producer/tests/portrait-edge-bleed/src/sample.mp4
Binary file not shown.
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=480, height=270">
<title>Video Overlay Stretch Regression</title>
<style>
* {
box-sizing: border-box;
}

html,
body {
margin: 0;
padding: 0;
width: 480px;
height: 270px;
overflow: hidden;
background: #000;
}

#root {
position: relative;
width: 480px;
height: 270px;
overflow: hidden;
background: #000;
}

.scene-video {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
object-position: center center;
}

.transition-overlay {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
opacity: 0.82;
}

.cut-label {
position: absolute;
right: 12px;
bottom: 12px;
z-index: 20;
padding: 5px 8px;
border: 2px solid rgba(255, 255, 255, 0.88);
color: #fff;
background: rgba(0, 0, 0, 0.68);
font: 700 13px Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<div id="root" data-composition-id="video-overlay-stretch" data-start="0" data-duration="4" data-width="480" data-height="270">
<video id="clip-a" class="clip scene-video" src="clip.mp4" data-start="0" data-duration="2" data-track-index="0" muted playsinline data-end="2" data-has-audio="false"></video>

<video id="clip-b" class="clip scene-video" src="clip.mp4" data-start="2" data-duration="2" data-track-index="1" muted playsinline data-end="4" data-has-audio="false"></video>

<img id="transition" class="clip transition-overlay" src="transition-overlay.png" data-start="1.6" data-duration="0.8" data-track-index="10" alt="">

<div class="clip cut-label" data-start="0" data-duration="2" data-track-index="20">
CLIP A
</div>
<div class="clip cut-label" data-start="2" data-duration="2" data-track-index="21">
CLIP B
</div>
</div>

<script>window.__timelines = window.__timelines || {};</script></body>
</html>
version https://git-lfs.github.com/spec/v1
oid sha256:5b49e97a5790955c731e273114098622a13dac4f5952cb7d5d0de5bb86e31026
size 2251
1,647 changes: 3 additions & 1,644 deletions packages/producer/tests/spanish-empire-cdn-inline/output/compiled.html

Large diffs are not rendered by default.

2,086 changes: 3 additions & 2,083 deletions packages/producer/tests/style-11-prod/output/compiled.html

Large diffs are not rendered by default.

1,827 changes: 3 additions & 1,824 deletions packages/producer/tests/style-4-prod/output/compiled.html

Large diffs are not rendered by default.

2,113 changes: 3 additions & 2,110 deletions packages/producer/tests/style-7-prod/output/compiled.html

Large diffs are not rendered by default.

Loading