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
6 changes: 6 additions & 0 deletions docs/reference/lint-rules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -949,3 +949,9 @@ Source: the project lint pass in `packages/lint/src/project.ts`, `packages/lint/
**Warning.** A video's `data-media-start` sits at or past the source's playable duration, so the video holds its final frame for the whole slot.

**Fix:** Trim `data-media-start` below the source duration if the final-frame hold is unintended.

### `video_slot_outlasts_source`

**Warning.** A video's `data-duration` is longer than the source it has left to play (from `data-media-start`, at its `data-playback-rate`), so the video holds its final frame for the rest of the slot. Holds of 0.1 s or less are not reported, nor are looping videos or videos with a rate lane.

**Fix:** Shorten `data-duration` to what the source covers, add `loop`, or use a longer source if the final-frame hold is unintended.
78 changes: 64 additions & 14 deletions packages/lint/src/hevcPreviewLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { join } from "node:path";
import { rewriteAssetPath } from "@hyperframes/parsers/asset-paths";
import { parseNumeric } from "@hyperframes/parsers/composition-contract";
import { findFfBinary } from "@hyperframes/parsers/ff-binaries";
import {
readPlaybackRate,
resolveNaturalDurationSeconds,
} from "@hyperframes/parsers/media-duration";
import {
cleanAssetUrl,
isRemoteOrInlineUrl,
Expand Down Expand Up @@ -141,6 +145,8 @@ interface LocalFiniteVideoSlot {
file: string;
elementId?: string;
mediaStart: number;
duration: number;
playbackRate: number;
}

interface UnresolvedFiniteVideoSlot extends Omit<LocalFiniteVideoSlot, "src"> {
Expand Down Expand Up @@ -172,18 +178,30 @@ function readNonNegativeNumber(raw: string | null): number | null {
return value !== null && value >= 0 ? value : null;
}

/** Slots whose source position the static probe cannot follow: looping, late-bound, or rate-ramped. */
function hasUnknownSourcePosition(video: Element): boolean {
return (
video.hasAttribute("loop") ||
video.hasAttribute("data-var-src") ||
video.hasAttribute("data-playback-start") ||
video.getAttribute("data-automation")?.includes('"rate"') === true
);
}

function readFiniteVideoSlot(video: Element, file: string): UnresolvedFiniteVideoSlot | null {
if (video.hasAttribute("loop")) return null;
if (video.hasAttribute("data-var-src")) return null;
if (video.hasAttribute("data-playback-start")) return null;
if (readPositiveNumber(video.getAttribute("data-duration")) === null) return null;
const mediaStart = readNonNegativeNumber(video.getAttribute("data-media-start"));
if (hasUnknownSourcePosition(video)) return null;
const duration = readPositiveNumber(video.getAttribute("data-duration"));
if (duration === null) return null;
const mediaStartRaw = video.getAttribute("data-media-start");
const mediaStart = mediaStartRaw === null ? 0 : readNonNegativeNumber(mediaStartRaw);
if (mediaStart === null) return null;
return {
rawSrc: video.getAttribute("src") ?? "",
file,
...(video.id ? { elementId: video.id } : {}),
mediaStart,
duration,
playbackRate: readPlaybackRate((name) => video.getAttribute(name)),
};
}

Expand All @@ -204,6 +222,8 @@ function collectLocalFiniteVideoSlots(
file: slot.file,
...(slot.elementId ? { elementId: slot.elementId } : {}),
mediaStart: slot.mediaStart,
duration: slot.duration,
playbackRate: slot.playbackRate,
});
slotsByPath.set(reference.resolved, slots);
}
Expand Down Expand Up @@ -277,20 +297,50 @@ export async function lintVideoMediaStartPastEof(
const sourceDuration = durations[index];
if (sourceDuration == null) continue;
for (const slot of slots) {
if (slot.mediaStart < sourceDuration) continue;
findings.push({
code: "video_media_start_at_or_past_eof",
severity: "warning",
message: `Video "${slot.src}" starts at ${slot.mediaStart}s, at or past its ${sourceDuration}s playable source duration. The video will hold its final frame for the explicit slot.`,
file: slot.file,
...(slot.elementId ? { elementId: slot.elementId } : {}),
fixHint: `Trim data-media-start below ${sourceDuration}s if this final-frame hold is unintended.`,
});
const finding =
slot.mediaStart >= sourceDuration
? mediaStartPastEofFinding(slot, sourceDuration)
: slotOutlastsSourceFinding(slot, sourceDuration);
if (finding) findings.push(finding);
}
}
return findings;
}

function mediaStartPastEofFinding(
slot: LocalFiniteVideoSlot,
sourceDuration: number,
): HyperframeLintFinding {
return {
code: "video_media_start_at_or_past_eof",
severity: "warning",
message: `Video "${slot.src}" starts at ${slot.mediaStart}s, at or past its ${sourceDuration}s playable source duration. The video will hold its final frame for the explicit slot.`,
file: slot.file,
...(slot.elementId ? { elementId: slot.elementId } : {}),
fixHint: `Trim data-media-start below ${sourceDuration}s if this final-frame hold is unintended.`,
};
}

/** A hold this short is rounding in data-duration, not a visible freeze. */
const SLOT_HOLD_TOLERANCE_SECONDS = 0.1;

function slotOutlastsSourceFinding(
slot: LocalFiniteVideoSlot,
sourceDuration: number,
): HyperframeLintFinding | null {
const plays = resolveNaturalDurationSeconds(sourceDuration, slot.mediaStart, slot.playbackRate);
if (plays === null || slot.duration - plays <= SLOT_HOLD_TOLERANCE_SECONDS) return null;
const seconds = (value: number) => Math.round(value * 100) / 100;
return {
code: "video_slot_outlasts_source",
severity: "warning",
message: `Video "${slot.src}" runs out after ${seconds(plays)}s of its ${seconds(slot.duration)}s slot (source ${seconds(sourceDuration)}s, starting ${seconds(slot.mediaStart)}s in). It holds its final frame for the last ${seconds(slot.duration - plays)}s.`,
file: slot.file,
...(slot.elementId ? { elementId: slot.elementId } : {}),
fixHint: `Shorten data-duration to ${seconds(plays)}s, add loop, or use a longer source if this final-frame hold is unintended.`,
};
}

/**
* INFO-only finding: a locally referenced `<video>` file is encoded as
* HEVC/H.265. The render pipeline pre-decodes video with FFmpeg (never the
Expand Down
57 changes: 56 additions & 1 deletion packages/lint/src/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,10 @@ describe("hevc_preview_codec", () => {
const findings = await hevcFindings(project);

expect(findings).toHaveLength(1);
expect(mockExecFile).toHaveBeenCalledTimes(1);
const codecProbes = mockExecFile.mock.calls.filter(([, args]) =>
args?.includes("stream=codec_name"),
);
expect(codecProbes).toHaveLength(1);
});
});

Expand Down Expand Up @@ -1048,6 +1051,58 @@ describe("video_media_start_at_or_past_eof", () => {

expect(await mediaStartFindings(project)).toEqual([]);
});

async function outlastsFindings(project: string): Promise<HyperframeLintFinding[]> {
const { results } = await lintProject(project);
return results
.flatMap((entry) => entry.result.findings)
.filter((finding) => finding.code === "video_slot_outlasts_source");
}

it("warns when a slot outlasts the source it plays from the start", async () => {
const { project } = videoProject(
'<video id="clip" src="clip.mp4" data-start="0" data-duration="9.019" muted></video>',
);
mockDurationProbe(1.9);

const findings = await outlastsFindings(project);

expect(findings).toHaveLength(1);
expect(findings[0]).toMatchObject({
severity: "warning",
file: "index.html",
elementId: "clip",
});
expect(findings[0]?.message).toContain("runs out after 1.9s of its 9.02s slot");
expect(findings[0]?.message).toContain("holds its final frame for the last 7.12s");
expect(findings[0]?.fixHint).toContain("Shorten data-duration to 1.9s");
});

it("counts data-media-start and data-playback-rate against the source", async () => {
const { project } = videoProject(`
<video id="late" src="clip.mp4" data-start="0" data-duration="4" data-media-start="3" muted></video>
<video id="fast" src="clip.mp4" data-start="0" data-duration="4" data-playback-rate="2" muted></video>
<video id="fits" src="clip.mp4" data-start="0" data-duration="3" data-playback-rate="2" muted></video>
`);
mockDurationProbe(6);

const ids = (await outlastsFindings(project)).map((finding) => finding.elementId);

expect(ids).toEqual(["late", "fast"]);
});

it("stays quiet for a hold inside rounding, a loop, a rate lane, or a start past EOF", async () => {
const { project } = videoProject(`
<video src="clip.mp4" data-start="0" data-duration="2.05" muted></video>
<video src="clip.mp4" data-start="0" data-duration="9" loop muted></video>
<video src="clip.mp4" data-start="0" data-duration="9" data-automation='{"lanes":[{"target":"rate","points":[[0,1],[1,0.5]]}]}' muted></video>
<video src="clip.mp4" data-start="0" data-duration="9" data-media-start="3" muted></video>
`);
mockDurationProbe(2);

expect(await outlastsFindings(project)).toEqual([]);
expect(await mediaStartFindings(project)).toHaveLength(1);
});
});

describe("missing asset findings name the file that references them", () => {
Expand Down