Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(media-server): skip the zero-length closing entry in Loom DASH timelines
Richie McIlroy2a747ff81b5c
diff --git a/apps/media-server/src/__tests__/lib/media-video.integration.test.ts b/apps/media-server/src/__tests__/lib/media-video.integration.test.tsindex f7234458a..e3b8d3e7f 100644--- a/apps/media-server/src/__tests__/lib/media-video.integration.test.ts+++ b/apps/media-server/src/__tests__/lib/media-video.integration.test.ts@@ -811,6 +811,57 @@ describe("processVideo integration tests", () => {}});+ test("skips the zero-length closing entry Loom adds to DASH timelines", async () => {+ const originalFetch = globalThis.fetch;+ const manifestDir = mkdtempSync(join(tmpdir(), "cap-mpd-zero-"));++ globalThis.fetch = (async () =>+ new Response(+ `<MPD mediaPresentationDuration="PT7.001S">+ <Period id="0">+ <AdaptationSet id="1" contentType="video">+ <Representation id="1" bandwidth="500000" codecs="vp9" mimeType="video/webm" width="1280" height="720">+ <SegmentTemplate timescale="1000000" initialization="loom-video-init.webm" media="loom-video-$Number$.webm" startNumber="0">+ <SegmentTimeline>+ <S t="0" d="3539000"/>+ <S t="3522000" d="3479000"/>+ <S t="7001000" d="0"/>+ </SegmentTimeline>+ </SegmentTemplate>+ </Representation>+ </AdaptationSet>+ </Period>+ </MPD>`,+ { status: 200, statusText: "OK" },+ )) as unknown as typeof fetch;++ try {+ const masterPath = await materializeMpdAsHlsPlaylist(+ "https://luna.example/id/x/resource/dash/playlist.mpd?Signature=s",+ manifestDir,+ );+ const masterLines = readFileSync(masterPath, "utf8").split("\n");+ const videoPlaylist = readFileSync(+ masterLines[+ masterLines.findIndex((line) =>+ line.startsWith("#EXT-X-STREAM-INF:"),+ ) + 1+ ] ?? "",+ "utf8",+ );++ expect(videoPlaylist).toContain("loom-video-0.webm?Signature=s");+ expect(videoPlaylist).toContain("loom-video-1.webm?Signature=s");+ expect(videoPlaylist).not.toContain("loom-video-2.webm");+ expect(videoPlaylist.match(/#EXTINF:/g)?.length).toBe(2);+ expect(videoPlaylist).toContain("#EXTINF:3.539000,");+ expect(videoPlaylist).toContain("#EXTINF:3.479000,");+ } finally {+ globalThis.fetch = originalFetch;+ rmSync(manifestDir, { recursive: true, force: true });+ }+ });+test("falls back to generic DASH manifest materialization for unsupported MPD shapes", async () => {const originalFetch = globalThis.fetch;const manifestDir = mkdtempSync(join(tmpdir(), "cap-mpd-fallback-"));diff --git a/apps/media-server/src/lib/media-video.ts b/apps/media-server/src/lib/media-video.tsindex 61b2bd52e..ce0cbd2ad 100644--- a/apps/media-server/src/lib/media-video.ts+++ b/apps/media-server/src/lib/media-video.ts@@ -621,8 +621,13 @@ function buildDashSegments(if (timeline) {const timelineSegments = getXmlElementBlocks(timeline.content, "S");let currentTime = 0;+ let number = startNumber;for (const [index, segment] of timelineSegments.entries()) {+ if (parseNumber(segment.attributes.d) === 0) {+ number++;+ continue;+ }const duration = parsePositiveNumber(segment.attributes.d);if (!duration) {throw new Error("DASH SegmentTimeline entry is missing duration");@@ -647,10 +652,9 @@ function buildDashSegments(for (let offset = 0; offset < count; offset++) {const time = currentTime + duration * offset;- const number = startNumber + segments.length;const resource = substituteDashTemplate(media, {bandwidth,- number,+ number: number++,representationId,time,});