Public: anyone can read this; the crew can change it.

Video-edit timelines open as a cut list: .otio and .edl show tracks, clips, in and out times and the total length #12780

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/12768-video-edit-timelines-open-as-a-cut-list → main 7 commits fork 4 threads · 4 unresolved

  • Merged. scout/12768-video-edit-timelines-open-as-a-cut-list was merged into main as c5e8d23.

Review

Sign in to review this change.
12 files changed +476 −1
docs/features/README.md +1
@@ -233,6 +233,7 @@ Read with the guide page [Your apps](../guide-your-apps.md).
233233 - [Config files as a form](config-form.md)
234234 - [Contacts files (.vcf) as a list of people](vcf-view.md)
235235 - [CSV and TSV as a table](csv-view.md)
236 - [Video-edit timelines (.otio, .edl) as a cut list](timeline-cut-list.md)
236237 - [Files in the browser: the media route and the kind registry](file-media.md)
237238 - [Font specimens](font.md)
238239 - [G-code layers](gcode.md)
docs/features/timeline-cut-list.md added +17
@@ -0,0 +1,17 @@
1 # Video-edit timelines as a cut list
2
3 Open a `.otio` (OpenTimelineIO) or `.edl` (CMX3600 edit decision list) file in a repository's file view and read it as a cut list instead of raw text.
4
5 ## What you see
6
7 - The timeline's title, its track count and its total length.
8 - One table per track, in file order: clip number, clip name, source (the media path or URL), in, out and duration, as `HH:MM:SS:FF` timecode. Tables scroll sideways on a narrow screen.
9 - Up to 50 tracks and 500 clips per track are drawn; the rest are counted and left to the raw file.
10 - In the terminal's file view the same clips show as one table with a Track column first; `s` toggles to the source.
11
12 ## Limits
13
14 - **1 MB is the render cap.** A larger file is shown as its source, never drawn.
15 - A file that is cut off, is not a Timeline, or has no events also keeps its source, with the reason above it.
16 - **Frame rate.** An `.otio` carries its own rates. An `.edl` is read at the rate its header names (`FRAME RATE: 25`); with none, the page says it assumed one: 30 fps for a list marked `FCM: DROP FRAME`, 24 otherwise.
17 - **Drop-frame.** Timecode is counted by nominal frames, so a drop-frame duration can be a frame or two off the editor's own figure. Treat totals as a guide, not a conform.
src/tui/screens/workspace.ts +29 −1
@@ -50,7 +50,7 @@ import { canAdmin, canWrite, DECISIONS_BY, getRepoById, type Repo } from "../../
5050 import type { TreeEntry } from "../../git/read.ts";
5151 import { parseUnifiedDiff, type Diff } from "../../git/diff.ts";
5252 import { renderDiff as renderPatch } from "../ui/diff.ts";
53 import { fileKind, isEnvExample, kindByName, NO_BYTES } from "../../web/render/kinds.ts";
53 import { fileKind, isEnvExample, kindByName, NO_BYTES, RENDER_CAP } from "../../web/render/kinds.ts";
5454 import { downloadHref } from "../../web/pages/media.ts";
5555 import { isModelPath, modelFacts } from "../../web/render/model-facts.ts";
5656 import type { RepoFacts, RepoSource } from "../../view/source.ts";
@@ -58,6 +58,9 @@ import { detectLanguage, highlightLines } from "../../web/highlight.ts";
5858 import { MAX_COLUMNS, parseCsv, type Table } from "../../text/csv.ts";
5959 import { parseGeoJson, propertyRows } from "../../web/render/geojson.ts";
6060 import { gcodeFacts, parseGcode } from "../../web/render/gcode.ts";
61 import { parseOtio } from "../../web/render/otio.ts";
62 import { parseEdl } from "../../web/render/edl.ts";
63 import { ROW_CAP as TIMELINE_ROW_CAP } from "../../web/render/timeline-table.ts";
6164 import { parseHar, ROW_CAP as HAR_ROW_CAP, duration as harDuration } from "../../web/render/har.ts";
6265 import { gpxFacts, parseGpx } from "../../web/render/gpx.ts";
6366 import { CASE_CAP, parseJunit } from "../../web/render/junit.ts";
@@ -480,6 +483,26 @@ export function harTable(source: string): Table | null {
480483 };
481484 }
482485
486 /** `.otio` / `.edl`: a video-edit timeline, drawn as a cut list. */
487 function isTimelinePath(path: string): boolean {
488 const k = kindByName(path);
489 return k === "otio" || k === "edl";
490 }
491
492 /**
493 * The clips of a timeline as one table, a track column first; the reason, as the page words
494 * it, when it is not drawn. Shares the web's parsers and 1 MB cap.
495 */
496 export function timelineTable(source: Uint8Array, path: string): Table | string {
497 if (source.length > RENDER_CAP.otio) return "not drawn as a cut list: it is over 1 MB";
498 const text = new TextDecoder().decode(source);
499 const parsed = kindByName(path) === "otio" ? parseOtio(text) : parseEdl(text);
500 if ("error" in parsed) return `not drawn as a cut list: ${parsed.error}`;
501 const all = parsed.timeline.tracks.flatMap((t) => t.cuts.map((c, i) => [t.name, String(i + 1), c.name, c.source, c.in, c.out, c.duration]));
502 const rows = all.slice(0, TIMELINE_ROW_CAP);
503 return { header: ["Track", "#", "Clip", "Source", "In", "Out", "Duration"], rows, more: all.length - rows.length, delimiter: ",", columns: 7 };
504 }
505
483506 /** `.sarif`: a scanner's findings, drawn as a table of level, rule, location and message. */
484507 function isSarifPath(path: string): boolean {
485508 return /\.sarif$/i.test(path);
@@ -864,6 +887,11 @@ class Tab {
864887 } else if (isHarPath(this.path)) {
865888 this.table = harTable(new TextDecoder().decode(source));
866889 if (this.table !== null) this.grid = layoutTable(this.table);
890 } else if (isTimelinePath(this.path)) {
891 const cuts = timelineTable(source, this.path);
892 this.table = typeof cuts === "string" ? null : cuts;
893 this.fault = typeof cuts === "string" ? cuts : "";
894 if (this.table !== null) this.grid = layoutTable(this.table);
867895 } else if (isSarifPath(this.path)) {
868896 const findings = sarifTable(new TextDecoder().decode(source));
869897 this.table = typeof findings === "string" ? null : findings;
src/web/render/edl.ts added +97
@@ -0,0 +1,97 @@
1 /**
2 * A CMX3600 edit decision list (`.edl`) as a cut list: one table per track
3 * (V, A, A2 …) with clip name, source, source in and out, and duration, and
4 * the total record length. The frame rate is read from the header
5 * (`FRAME RATE: 25`, or `FPS`); without one, drop-frame lists are 30 and the
6 * rest 24, and the page says it assumed. Timecode is counted by nominal
7 * frames, so a drop-frame duration can be off by a frame or two. A list with
8 * a cut-off event, or no events, falls back to its source.
9 */
10
11 import { html } from "../html.ts";
12 import { drawTimeline, timecode, type Cut, type Timeline } from "./timeline-table.ts";
13 import type { Rendered, RenderInput } from "./renderers.ts";
14
15 const TC = /^(\d{2}):(\d{2}):(\d{2})[:;](\d{2})$/;
16 const EVENT_START = /^\d{1,6}\s/;
17
18 export type Parsed = { readonly timeline: Timeline } | { readonly error: string };
19
20 export function parseEdl(text: string): Parsed {
21 const lines = text.replace(/^/, "").split(/\r\n|\n|\r/);
22 let title = "";
23 let drop = false;
24 let rate = 0;
25 for (const line of lines) {
26 const t = /^TITLE:\s*(.*)$/i.exec(line);
27 if (t) title ||= t[1]!.trim();
28 if (/^FCM:\s*DROP/i.test(line)) drop = true;
29 const r = /^\*?\s*(?:FRAME RATE|FPS|FRAMERATE)\s*[:=]\s*(\d+(?:\.\d+)?)/i.exec(line);
30 if (r && rate === 0) rate = Number(r[1]);
31 }
32 if (!Number.isFinite(rate) || rate <= 0 || rate > 1000) rate = 0;
33 const assumed = rate === 0;
34 const fps = assumed ? (drop ? 30 : 24) : rate;
35 const nominal = Math.round(fps);
36
37 const frames = (s: string): number | undefined => {
38 const m = TC.exec(s);
39 if (m === null || Number(m[4]) >= nominal) return undefined;
40 return ((Number(m[1]) * 60 + Number(m[2])) * 60 + Number(m[3])) * nominal + Number(m[4]);
41 };
42
43 interface Ev { track: string; reel: string; name: string; file: string; srcIn: number; srcOut: number; recIn: number; recOut: number }
44 const events: Ev[] = [];
45 for (const line of lines) {
46 const trim = line.trim();
47 if (trim.startsWith("*")) {
48 const last = events[events.length - 1];
49 const c = /^\*\s*(FROM CLIP NAME|SOURCE FILE)\s*:\s*(.*)$/i.exec(trim);
50 if (last && c) {
51 if (c[1]!.toUpperCase() === "SOURCE FILE") last.file = c[2]!.trim();
52 else last.name = c[2]!.trim();
53 }
54 continue;
55 }
56 if (!EVENT_START.test(trim)) continue;
57 const tok = trim.split(/\s+/);
58 const tcs = tok.slice(-4).map(frames);
59 if (tok.length < 8 || tcs.some((v) => v === undefined))
60 return { error: `event ${tok[0]} is cut off or unreadable` };
61 const [srcIn, srcOut, recIn, recOut] = tcs as number[];
62 events.push({ track: tok[2]!, reel: tok[1]!, name: "", file: "", srcIn: srcIn!, srcOut: srcOut!, recIn: recIn!, recOut: recOut! });
63 }
64 if (events.length === 0) return { error: "it holds no events" };
65
66 const byTrack = new Map<string, Cut[]>();
67 let first = Infinity;
68 let last = -Infinity;
69 for (const e of events) {
70 first = Math.min(first, e.recIn);
71 last = Math.max(last, e.recOut);
72 const cuts = byTrack.get(e.track) ?? [];
73 cuts.push({
74 name: e.name || e.reel,
75 source: e.file || e.reel,
76 in: timecode(e.srcIn, fps),
77 out: timecode(e.srcOut, fps),
78 duration: timecode(e.srcOut - e.srcIn, fps),
79 });
80 byTrack.set(e.track, cuts);
81 }
82 const length = Math.max(0, last - first);
83 return {
84 timeline: {
85 title: title || "Untitled list",
86 tracks: [...byTrack].map(([name, cuts]) => ({ name, cuts })),
87 total: `${timecode(length, fps)} (${(Math.round((length / nominal) * 100) / 100).toLocaleString()} s at ${Math.round(fps * 1000) / 1000} fps)`,
88 ...(assumed ? { note: `The header names no frame rate; ${fps} fps is assumed${drop ? " from FCM: DROP FRAME" : ""}.` } : {}),
89 },
90 };
91 }
92
93 export function edl(input: RenderInput): Rendered {
94 const p = parseEdl(new TextDecoder().decode(input.body));
95 if ("error" in p) return { content: html``, lines: 0, fallback: `This file is not drawn as a cut list: ${p.error}.` };
96 return drawTimeline(input, p.timeline);
97 }
src/web/render/kinds.ts +8
@@ -35,6 +35,8 @@ export type FileKind =
3535 | "har"
3636 | "geojson"
3737 | "calendar"
38 | "otio"
39 | "edl"
3840 | "contacts"
3941 | "mail"
4042 | "gcode"
@@ -84,6 +86,10 @@ export const RENDER_CAP: Readonly<Record<FileKind, number>> = {
8486 har: 5 * MB,
8587 geojson: 5 * MB,
8688 calendar: 5 * MB,
89 // 1 MB is the render cap for a timeline: a larger .otio or .edl is shown as its source,
90 // not drawn.
91 otio: 1 * MB,
92 edl: 1 * MB,
8793 contacts: 5 * MB,
8894 mail: 5 * MB,
8995 gcode: 50 * MB,
@@ -217,6 +223,8 @@ const TEXTUAL: Readonly<Record<string, FileKind>> = {
217223 har: "har",
218224 geojson: "geojson",
219225 ics: "calendar",
226 otio: "otio",
227 edl: "edl",
220228 vcf: "contacts",
221229 vcard: "contacts",
222230 eml: "mail",
src/web/render/otio.ts added +108
@@ -0,0 +1,108 @@
1 /**
2 * An OpenTimelineIO file (`.otio`, JSON) as a cut list: each track's clips
3 * with name, source, in, out and duration, and the timeline's total length.
4 * Times are RationalTime (`value` at `rate`), shown as timecode. Only the
5 * top-level tracks are read; a nested stack shows as one row. A file that is
6 * not a timeline, or is cut off, falls back to its source.
7 */
8
9 import { html } from "../html.ts";
10 import { drawTimeline, timecode, type Cut, type Timeline, type Track } from "./timeline-table.ts";
11 import type { Rendered, RenderInput } from "./renderers.ts";
12
13 type Obj = Readonly<Record<string, unknown>>;
14 const obj = (v: unknown): Obj | undefined =>
15 typeof v === "object" && v !== null && !Array.isArray(v) ? (v as Obj) : undefined;
16 const str = (v: unknown): string => (typeof v === "string" ? v : "");
17 const schema = (v: unknown): string => str(obj(v)?.["OTIO_SCHEMA"]).replace(/\.\d+$/, "");
18
19 interface Time {
20 readonly value: number;
21 readonly rate: number;
22 }
23 function rational(v: unknown): Time | undefined {
24 const o = obj(v);
25 if (o === undefined) return undefined;
26 const { value, rate } = o;
27 if (typeof value !== "number" || typeof rate !== "number") return undefined;
28 if (!Number.isFinite(value) || !Number.isFinite(rate) || rate <= 0) return undefined;
29 return { value, rate };
30 }
31 const seconds = (t: Time): number => t.value / t.rate;
32 const tc = (t: Time): string => timecode(t.value, t.rate);
33
34 function range(v: unknown): { start: Time; duration: Time } | undefined {
35 const o = obj(v);
36 const start = rational(o?.["start_time"]);
37 const duration = rational(o?.["duration"]);
38 return start === undefined || duration === undefined ? undefined : { start, duration };
39 }
40
41 /** Where a clip's media lives: the active reference's address, else its name. */
42 function source(clip: Obj): string {
43 const refs = obj(clip["media_references"]);
44 const key = str(clip["active_media_reference_key"]);
45 const ref = obj(refs?.[key]) ?? obj(clip["media_reference"]);
46 const target = str(ref?.["target_url"]);
47 return target !== "" ? target : str(ref?.["name"]);
48 }
49
50 export type Parsed = { readonly timeline: Timeline } | { readonly error: string };
51
52 export function parseOtio(text: string): Parsed {
53 let root: unknown;

Redundant type: use Timeline.

54 try {
55 root = JSON.parse(text);
56 } catch {
57 return { error: "it is not complete JSON (cut off or malformed)" };
58 }
59 const tl = obj(root);
60 if (tl === undefined || schema(tl) !== "Timeline") return { error: "it is not an OpenTimelineIO Timeline" };
61 const stack = obj(tl["tracks"]);
62 const children = stack?.["children"];
63 if (!Array.isArray(children)) return { error: "the timeline has no tracks" };
64 let longest = 0;
65 let rate = 0;
66 const tracks: Track[] = [];
67 children.forEach((raw, ti) => {
68 const t = obj(raw);
69 if (t === undefined || !Array.isArray(t["children"])) return;
70 const cuts: Cut[] = [];
71 let length = 0;
72 for (const item of t["children"] as unknown[]) {
73 const o = obj(item);
74 const kind = schema(o);
75 if (o === undefined || kind === "Transition") continue;
76 const r = range(o["source_range"]);
77 let dur = r?.duration;
78 if (dur === undefined && kind === "Clip") {
79 const avail = range(obj(obj(o["media_reference"]))?.["available_range"]);
80 dur = avail?.duration;
81 }
82 if (dur !== undefined) {
83 length += seconds(dur);
84 rate = Math.max(rate, dur.rate);
85 }
86 const label = kind === "Gap" ? "(gap)" : str(o["name"]) || `(${kind.toLowerCase() || "item"})`;
87 cuts.push({
88 name: label,
89 source: kind === "Clip" ? source(o) : "",
90 in: r !== undefined ? tc(r.start) : "",
91 out: r !== undefined ? tc({ value: r.start.value + r.duration.value, rate: r.start.rate }) : "",
92 duration: dur !== undefined ? tc(dur) : "",
93 });
94 }
95 longest = Math.max(longest, length);
96 tracks.push({ name: `${str(t["name"]) || `Track ${ti + 1}`}${str(t["kind"]) ? ` (${str(t["kind"])})` : ""}`, cuts });
97 });
98 if (tracks.length === 0) return { error: "the timeline has no tracks" };
99 const fps = rate > 0 ? rate : 24;
100 const total = `${timecode(longest * fps, fps)} (${(Math.round(longest * 100) / 100).toLocaleString()} s at ${Math.round(fps * 1000) / 1000} fps)`;
101 return { timeline: { title: str(tl["name"]) || "Untitled timeline", tracks, total } };
102 }
103
104 export function otio(input: RenderInput): Rendered {
105 const p = parseOtio(new TextDecoder().decode(input.body));
106 if ("error" in p) return { content: html``, lines: 0, fallback: `This file is not drawn as a timeline: ${p.error}.` };
107 return drawTimeline(input, p.timeline);
108 }
src/web/render/renderers.ts +4
@@ -22,6 +22,8 @@ import { gpx } from "./gpx.ts";
2222 import { har } from "./har.ts";
2323 import { font } from "./font.ts";
2424 import { ics } from "./ics.ts";
25 import { otio } from "./otio.ts";
26 import { edl } from "./edl.ts";
2527 import { junit } from "./junit.ts";
2628 import { vcf } from "./vcf.ts";
2729 import { htmlPreview } from "./html_preview.ts";
@@ -108,6 +110,8 @@ export const RENDERERS: Partial<Readonly<Record<FileKind, Renderer>>> = {
108110 dxf,
109111 geojson,
110112 calendar: ics,
113 otio,
114 edl,
111115 contacts: vcf,
112116 sarif,
113117 lcov,
src/web/render/timeline-table.ts added +71
@@ -0,0 +1,71 @@
1 /**
2 * A cut list as plain tables, one per track, for the timeline formats
3 * (`otio.ts`, `edl.ts`). Plain data in, escaped HTML out; readable with no
4 * script. Every value is escaped here, once.
5 */
6
7 import { html, type Html } from "../html.ts";
8 import { fileSize } from "../ui.ts";
9 import type { Rendered, RenderInput } from "./renderers.ts";
10
11 /** Tracks and rows drawn, whatever the file holds. */
12 export const TRACK_CAP = 50;
13 export const ROW_CAP = 500;
14
15 export interface Cut {
16 readonly name: string;
17 readonly source: string;
18 readonly in: string;
19 readonly out: string;
20 readonly duration: string;
21 }
22
23 export interface Track {
24 readonly name: string;
25 readonly cuts: readonly Cut[];
26 }
27
28 export interface Timeline {
29 readonly title: string;
30 readonly tracks: readonly Track[];
31 /** Already worded, e.g. `00:01:30:00 at 24 fps`. */
32 readonly total: string;
33 /** A note on how the numbers were read (an assumed frame rate). */
34 readonly note?: string;
35 }
36
37 /** Frames as `HH:MM:SS:FF` at a nominal whole frame rate. */
38 export function timecode(frames: number, rate: number): string {
39 const fps = Math.max(1, Math.round(rate));
40 const sign = frames < 0 ? "-" : "";
41 const f = Math.abs(Math.round(frames));
42 const p = (n: number): string => String(n).padStart(2, "0");
43 const s = Math.floor(f / fps);
44 return `${sign}${p(Math.floor(s / 3600))}:${p(Math.floor(s / 60) % 60)}:${p(s % 60)}:${p(f % fps)}`;
45 }
46
47 const HEAD = ["#", "Clip", "Source", "In", "Out", "Duration"];
48
49 function trackTable(t: Track): Html {
50 const shown = t.cuts.slice(0, ROW_CAP);
51 const hidden = t.cuts.length - shown.length;
52 return html`<div class="table-scroll"><table class="table" data-dense><caption>${t.name}</caption>
53 <thead><tr>${HEAD.map((h) => html`<th scope="col">${h}</th>`)}</tr></thead>
54 <tbody>${shown.map((c, i) => html`<tr><td>${i + 1}</td><td>${c.name}</td><td>${c.source}</td><td>${c.in}</td><td>${c.out}</td><td>${c.duration}</td></tr>`)}${
55 hidden > 0 ? html`<tr><td colspan="6" class="muted small">${hidden.toLocaleString()} more clips are in the raw file.</td></tr>` : ""
outdated

Principle 1: the aria-label repeats the caption. Drop it. Also check the 6-column table scrolls on a 360px phone.

56 }</tbody></table></div>`;
57 }
58
59 export function drawTimeline(input: RenderInput, tl: Timeline): Rendered {
60 const clips = tl.tracks.reduce((n, t) => n + t.cuts.length, 0);
61 const content = html`<p><strong>${tl.title}</strong> · ${tl.tracks.length.toLocaleString()} ${tl.tracks.length === 1 ? "track" : "tracks"} · total length ${tl.total}</p>${
62 tl.note ? html`<p class="muted small">${tl.note}</p>` : ""
63 }${tl.tracks.slice(0, TRACK_CAP).map(trackTable)}${
64 tl.tracks.length > TRACK_CAP ? html`<p class="muted small">Showing ${TRACK_CAP} of ${tl.tracks.length.toLocaleString()} tracks.</p>` : ""
65 }`;
outdated

Build the output with the html helper instead of raw() over concatenated strings, so escaping is by construction.

66 return {
67 content,
68 lines: 0,
69 summary: `${clips.toLocaleString()} ${clips === 1 ? "clip" : "clips"} · ${tl.total} · ${fileSize(input.size)}`,
70 };
71 }
test/fixtures/timelines/cut.edl added +11
@@ -0,0 +1,11 @@
1 TITLE: Teaser
2 FCM: NON-DROP FRAME
3 FRAME RATE: 25
4
5 001 AX V C 01:00:00:00 01:00:05:00 00:00:00:00 00:00:05:00
6 * FROM CLIP NAME: Opening
7 * SOURCE FILE: media/open.mov
8 002 AX V C 02:00:00:00 02:00:03:00 00:00:05:00 00:00:08:00
9 * FROM CLIP NAME: <b>Closer</b>
10 003 BL A C 00:00:00:00 00:00:08:00 00:00:00:00 00:00:08:00
11 * FROM CLIP NAME: Score
test/fixtures/timelines/cut.otio added +26
@@ -0,0 +1,26 @@
1 {
2 "OTIO_SCHEMA": "Timeline.1",
3 "name": "Teaser",
4 "tracks": {
5 "OTIO_SCHEMA": "Stack.1",
6 "children": [
7 {
8 "OTIO_SCHEMA": "Track.1", "name": "V1", "kind": "Video",
9 "children": [
10 {"OTIO_SCHEMA": "Clip.1", "name": "Opening", "media_reference": {"OTIO_SCHEMA": "ExternalReference.1", "target_url": "media/open.mov"},
11 "source_range": {"OTIO_SCHEMA": "TimeRange.1", "start_time": {"OTIO_SCHEMA": "RationalTime.1", "value": 24, "rate": 24}, "duration": {"OTIO_SCHEMA": "RationalTime.1", "value": 120, "rate": 24}}},
12 {"OTIO_SCHEMA": "Gap.1", "source_range": {"OTIO_SCHEMA": "TimeRange.1", "start_time": {"OTIO_SCHEMA": "RationalTime.1", "value": 0, "rate": 24}, "duration": {"OTIO_SCHEMA": "RationalTime.1", "value": 24, "rate": 24}}},
13 {"OTIO_SCHEMA": "Clip.1", "name": "<b>Closer</b>", "media_reference": {"OTIO_SCHEMA": "ExternalReference.1", "target_url": "media/close.mov"},
14 "source_range": {"OTIO_SCHEMA": "TimeRange.1", "start_time": {"OTIO_SCHEMA": "RationalTime.1", "value": 0, "rate": 24}, "duration": {"OTIO_SCHEMA": "RationalTime.1", "value": 72, "rate": 24}}}
15 ]
16 },
17 {
18 "OTIO_SCHEMA": "Track.1", "name": "A1", "kind": "Audio",
19 "children": [
20 {"OTIO_SCHEMA": "Clip.1", "name": "Score", "media_reference": {"OTIO_SCHEMA": "ExternalReference.1", "target_url": "media/score.wav"},
21 "source_range": {"OTIO_SCHEMA": "TimeRange.1", "start_time": {"OTIO_SCHEMA": "RationalTime.1", "value": 0, "rate": 24}, "duration": {"OTIO_SCHEMA": "RationalTime.1", "value": 192, "rate": 24}}}
22 ]
23 }
24 ]
25 }
26 }
test/render-kinds.test.ts +2
@@ -79,6 +79,8 @@ const SAMPLES: Record<string, [Uint8Array, FileKind, string]> = {
7979 eml: [enc("From: [email protected]\n\nhi\n"), "mail", "application/octet-stream"],
8080 geojson: [enc('{"type":"FeatureCollection","features":[]}'), "geojson", "application/octet-stream"],
8181 ics: [enc("BEGIN:VCALENDAR\nEND:VCALENDAR\n"), "calendar", "application/octet-stream"],
82 otio: [enc('{"OTIO_SCHEMA":"Timeline.1"}'), "otio", "application/octet-stream"],
83 edl: [enc("TITLE: a\n"), "edl", "application/octet-stream"],
8284 gcode: [enc("G28\nG1 X1 E1\n"), "gcode", "application/octet-stream"],
8385 gco: [enc("G28\n"), "gcode", "application/octet-stream"],
8486 dxf: [enc("0\nSECTION\n2\nENTITIES\n0\nENDSEC\n0\nEOF\n"), "dxf", "application/octet-stream"],
test/render-timelines.test.ts added +102
@@ -0,0 +1,102 @@
1 /** Timeline files (.otio, .edl) as cut lists: good, truncated, 5 MB, hostile text. */
2 import { describe, expect, test } from "bun:test";
3 import { readFileSync } from "node:fs";
4 import { edl, parseEdl } from "../src/web/render/edl.ts";
5 import { otio } from "../src/web/render/otio.ts";
6 import { fileKind } from "../src/web/render/kinds.ts";
7 import { timelineTable } from "../src/tui/screens/workspace.ts";
8 import { RENDERERS, rendererFor } from "../src/web/render/renderers.ts";
9
10 const fixture = (n: string): string => readFileSync(new URL(`./fixtures/timelines/${n}`, import.meta.url), "utf8");
11 const enc = (s: string): Uint8Array => new TextEncoder().encode(s);
12 const input = (path: string, text: string) => ({ path, size: text.length, body: enc(text), media: "/m", download: "/d" });
13
14 describe("timelines", () => {
15 test("the registry names both and a renderer draws each", () => {
16 expect(fileKind("a/x.OTIO", enc("{}"))).toBe("otio");
17 expect(fileKind("a/x.edl", enc("TITLE: x\n"))).toBe("edl");
18 expect(RENDERERS.otio).toBe(otio);
19 expect(RENDERERS.edl).toBe(edl);
20 });
21
22 test("otio: a table per track, in, out, duration, total length, escaped", () => {
23 const r = otio(input("cut.otio", fixture("cut.otio")));
24 const out = String(r.content);
25 expect(r.fallback).toBeUndefined();
26 expect(out.match(/<table/g)?.length).toBe(2);
27 expect(out).toContain("<caption>V1 (Video)</caption>");
28 expect(out).toContain("<td>Opening</td><td>media/open.mov</td><td>00:00:01:00</td><td>00:00:06:00</td><td>00:00:05:00</td>");
29 expect(out).toContain("(gap)");
30 expect(out).toContain("&lt;b&gt;Closer");
31 expect(out).not.toContain("<b>");
32 // V1 = 5 s + 1 s + 3 s = 9 s; A1 = 8 s.
33 expect(out).toContain("total length 00:00:09:00");
34 expect(r.summary).toContain("4 clips");
35 });
36
37 test("edl: a table per track, frame rate from the header, total length", () => {
38 const r = edl(input("cut.edl", fixture("cut.edl")));
39 const out = String(r.content);
40 expect(r.fallback).toBeUndefined();
41 expect(out.match(/<table/g)?.length).toBe(2);
42 expect(out).toContain("<td>Opening</td><td>media/open.mov</td><td>01:00:00:00</td><td>01:00:05:00</td><td>00:00:05:00</td>");
43 expect(out).toContain("25 fps");
44 expect(out).not.toContain("assumed");
45 expect(out).toContain("total length 00:00:08:00");
46 expect(out).not.toContain("<b>");
47 });
48
49 test("edl: no frame rate in the header is said to be assumed", () => {
50 const p = parseEdl("TITLE: x\nFCM: DROP FRAME\n001 AX V C 00:00:00;00 00:00:01;00 00:00:00;00 00:00:01;00\n");
51 if ("error" in p) throw new Error(p.error);
52 expect(p.timeline.note).toContain("30 fps is assumed");
53 });
54
55 test("a truncated file shows the source view, never a throw", () => {
56 const o = fixture("cut.otio");
57 expect(otio(input("a.otio", o.slice(0, o.length >> 1))).fallback).toContain("not drawn");
58 expect(otio(input("a.otio", '{"OTIO_SCHEMA":"Clip.1"}')).fallback).toBeDefined();
59 expect(otio(input("a.otio", "")).fallback).toBeDefined();
60 const e = fixture("cut.edl");
61 expect(edl(input("a.edl", e.slice(0, e.indexOf("02:00:00:00") + 6))).fallback).toContain("cut off");
62 expect(edl(input("a.edl", "TITLE: only\n")).fallback).toContain("no events");
63 });
64
65 test("a 5 MB file is refused for the source view", () => {
66 for (const [path, text] of [
67 ["big.otio", fixture("cut.otio") + " ".repeat(5_000_000)],
outdated

This only checks rendererFor is undefined. Assert the source-view outcome for both kinds; add the checks box 3 asks for.

68 ["big.edl", fixture("cut.edl") + "\n".repeat(5_000_000)],
69 ] as const) {
70 const body = enc(text);
71 const got = rendererFor(path, { kind: "text", body, size: body.length });
72 // No renderer: the file page falls to its source view, in the browser and the terminal alike.
73 expect(got).toBeUndefined();
74 expect(timelineTable(body, path)).toContain("over 1 MB");
75 }
76 });
77
78 test("a file just under the cap is still drawn; just over keeps its source", () => {
79 const pad = (n: number): string => fixture("cut.edl") + "\n".repeat(n);
80 const under = enc(pad(1_000_000 - fixture("cut.edl").length - 1));
81 const over = enc(pad(1_000_000 - fixture("cut.edl").length + 10));
82 expect(rendererFor("a.edl", { kind: "text", body: under, size: under.length })).toBeDefined();
83 expect(rendererFor("a.edl", { kind: "text", body: over, size: over.length })).toBeUndefined();
84 });
85
86 test("the tables scroll sideways and name themselves once, by caption", () => {
87 const out = String(otio(input("cut.otio", fixture("cut.otio"))).content);
88 expect(out).toContain('<div class="table-scroll"><table class="table" data-dense><caption>');
89 expect(out).not.toContain("aria-label");
90 });
91
92 test("the terminal draws the same cut list, one table with a track column", () => {
93 for (const path of ["cut.otio", "cut.edl"]) {
94 const t = timelineTable(enc(fixture(path)), path);
95 if (typeof t === "string") throw new Error(t);
96 expect(t.header).toEqual(["Track", "#", "Clip", "Source", "In", "Out", "Duration"]);
97 expect(t.rows.length).toBeGreaterThan(0);
98 }
99 expect(timelineTable(enc("not json"), "a.otio")).toContain("not drawn as a cut list");
100 expect(timelineTable(enc("TITLE: only\n"), "a.edl")).toContain("no events");
101 });
102 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs