vizmatic 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PROMPT.md +25 -1
- package/ROADMAP.md +1 -1
- package/dist/{chunk-DTD35LPT.js → chunk-F6QI6QJY.js} +60 -2
- package/dist/chunk-QVYHYC7T.js +88 -0
- package/dist/cli.js +10 -9
- package/dist/index.cjs +70 -3
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +14 -3
- package/dist/scene-cli.js +1 -1
- package/dist/stage-browser/browser.d.ts +144 -5
- package/dist/stage-browser/stage.js +5 -5
- package/dist/stage-export.cjs +67 -1
- package/dist/stage-export.d.cts +5 -1
- package/dist/stage-export.d.ts +5 -1
- package/dist/stage-export.js +11 -1
- package/dist/stage.cjs +286 -22
- package/dist/stage.d.cts +146 -7
- package/dist/stage.d.ts +146 -7
- package/dist/stage.js +268 -9
- package/dist/{svg-import-Djj2q7Pc.d.cts → svg-import-5_oTbEJR.d.cts} +2 -2
- package/dist/{svg-import-Djj2q7Pc.d.ts → svg-import-5_oTbEJR.d.ts} +2 -2
- package/dist/{video-CcHW1qhV.d.cts → video-BSwNJZkn.d.cts} +25 -1
- package/dist/{video-CcHW1qhV.d.ts → video-BSwNJZkn.d.ts} +25 -1
- package/examples/_teaching/categorical-tail-loss.ts +3 -3
- package/examples/_teaching/teaching-byte-diff.ts +3 -3
- package/examples/_teaching/teaching-routed-transfer.ts +3 -3
- package/examples/_teaching/teaching-token-history.ts +2 -2
- package/examples/_teaching/teaching-weighted-vector.ts +3 -3
- package/examples/films/attention.ts +5 -4
- package/examples/films/fourier-epicycles.ts +5 -2
- package/examples/films/pythagoras.ts +2 -2
- package/examples/films/taylor-series.ts +3 -2
- package/package.json +1 -1
- package/dist/chunk-3LQLKLGH.js +0 -79
package/dist/stage-export.cjs
CHANGED
|
@@ -1753,6 +1753,35 @@ async function renderToSvgInContext(element, width, height, options) {
|
|
|
1753
1753
|
}
|
|
1754
1754
|
|
|
1755
1755
|
// src/video.ts
|
|
1756
|
+
function chapterMetadata(title, chapters, duration) {
|
|
1757
|
+
const escape = (value) => value.replace(/[\\=;#]/g, (c) => `\\${c}`).replace(/\r?\n/g, " ");
|
|
1758
|
+
const marks = chapters.filter((chapter) => Number.isFinite(chapter.time) && chapter.time < duration).map((chapter) => ({ title: chapter.title, time: Math.max(0, chapter.time) })).sort((a, b) => a.time - b.time);
|
|
1759
|
+
if (marks.length > 0) marks[0].time = 0;
|
|
1760
|
+
let out = ";FFMETADATA1\n";
|
|
1761
|
+
if (title) out += `title=${escape(title)}
|
|
1762
|
+
`;
|
|
1763
|
+
marks.forEach((mark, index) => {
|
|
1764
|
+
const end = index + 1 < marks.length ? marks[index + 1].time : duration;
|
|
1765
|
+
out += `[CHAPTER]
|
|
1766
|
+
TIMEBASE=1/1000
|
|
1767
|
+
START=${Math.round(mark.time * 1e3)}
|
|
1768
|
+
END=${Math.round(end * 1e3)}
|
|
1769
|
+
title=${escape(mark.title)}
|
|
1770
|
+
`;
|
|
1771
|
+
});
|
|
1772
|
+
return out;
|
|
1773
|
+
}
|
|
1774
|
+
function captionsToSrt(captions, duration) {
|
|
1775
|
+
const stamp = (seconds) => {
|
|
1776
|
+
const ms = Math.round(seconds * 1e3);
|
|
1777
|
+
const pad = (value, size = 2) => String(value).padStart(size, "0");
|
|
1778
|
+
return `${pad(Math.floor(ms / 36e5))}:${pad(Math.floor(ms / 6e4) % 60)}:${pad(Math.floor(ms / 1e3) % 60)},${pad(ms % 1e3, 3)}`;
|
|
1779
|
+
};
|
|
1780
|
+
return captions.filter((cue) => cue.t1 > 0 && cue.t0 < duration && cue.t1 > cue.t0 && cue.text.trim().length > 0).sort((a, b) => a.t0 - b.t0).map((cue, index) => `${index + 1}
|
|
1781
|
+
${stamp(Math.max(0, cue.t0))} --> ${stamp(Math.min(duration, cue.t1))}
|
|
1782
|
+
${cue.text.trim()}
|
|
1783
|
+
`).join("\n");
|
|
1784
|
+
}
|
|
1756
1785
|
var MAX_STDERR_CHARS = 8192;
|
|
1757
1786
|
var COLOR_FILTER = "scale=in_range=pc:out_range=tv:out_color_matrix=bt709:flags=lanczos+accurate_rnd+full_chroma_int,format=yuv420p,setparams=range=tv:color_primaries=bt709:color_trc=bt709:colorspace=bt709";
|
|
1758
1787
|
var COLOR_TAGS = ["-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709", "-color_range", "tv"];
|
|
@@ -1899,12 +1928,37 @@ async function renderRgbaVideo(renderFrame, options) {
|
|
|
1899
1928
|
"-i",
|
|
1900
1929
|
"pipe:0"
|
|
1901
1930
|
];
|
|
1931
|
+
let inputs = 1;
|
|
1932
|
+
let audioInput = -1;
|
|
1902
1933
|
if (options.audioPath) {
|
|
1903
1934
|
if (options.audioOffset) args.push("-ss", String(options.audioOffset));
|
|
1904
1935
|
args.push("-i", (0, import_path2.resolve)(options.audioPath));
|
|
1936
|
+
audioInput = inputs++;
|
|
1937
|
+
}
|
|
1938
|
+
const sidecars = [];
|
|
1939
|
+
let metadataInput = -1, captionInput = -1;
|
|
1940
|
+
if (codec === "h264") {
|
|
1941
|
+
const chapters = options.chapters ?? [];
|
|
1942
|
+
if (options.title || chapters.length > 0) {
|
|
1943
|
+
const path = (0, import_path2.join)(outputDirectory, `.${(0, import_path2.basename)(outputPath)}.${(0, import_crypto.randomUUID)()}.tmp.ffmeta`);
|
|
1944
|
+
await (0, import_promises2.writeFile)(path, chapterMetadata(options.title, chapters, schedule.duration), { mode: 384 });
|
|
1945
|
+
sidecars.push(path);
|
|
1946
|
+
args.push("-f", "ffmetadata", "-i", path);
|
|
1947
|
+
metadataInput = inputs++;
|
|
1948
|
+
}
|
|
1949
|
+
const srt = captionsToSrt(options.captions ?? [], schedule.duration);
|
|
1950
|
+
if (srt) {
|
|
1951
|
+
const path = (0, import_path2.join)(outputDirectory, `.${(0, import_path2.basename)(outputPath)}.${(0, import_crypto.randomUUID)()}.tmp.srt`);
|
|
1952
|
+
await (0, import_promises2.writeFile)(path, srt, { mode: 384 });
|
|
1953
|
+
sidecars.push(path);
|
|
1954
|
+
args.push("-f", "srt", "-i", path);
|
|
1955
|
+
captionInput = inputs++;
|
|
1956
|
+
}
|
|
1905
1957
|
}
|
|
1906
1958
|
args.push("-map", "0:v:0");
|
|
1907
|
-
if (options.audioPath) args.push("-map",
|
|
1959
|
+
if (options.audioPath) args.push("-map", `${audioInput}:a:0`, "-af", `asetpts=PTS-STARTPTS,apad,atrim=duration=${seconds}`);
|
|
1960
|
+
if (captionInput >= 0) args.push("-map", `${captionInput}:0`, "-c:s", "mov_text", "-metadata:s:s:0", "language=eng");
|
|
1961
|
+
if (metadataInput >= 0) args.push("-map_metadata", String(metadataInput), "-map_chapters", String(metadataInput));
|
|
1908
1962
|
args.push("-frames:v", String(schedule.count), "-t", seconds, "-vf", COLOR_FILTER);
|
|
1909
1963
|
if (codec === "vp9") {
|
|
1910
1964
|
args.push("-c:v", "libvpx-vp9", "-crf", String(crf), "-b:v", "0", "-deadline", "good", "-cpu-used", "2", "-row-mt", "1", "-threads:v", String(threads));
|
|
@@ -1928,6 +1982,7 @@ async function renderRgbaVideo(renderFrame, options) {
|
|
|
1928
1982
|
child = (0, import_child_process.spawn)(ffmpegPath, args, { stdio: ["pipe", "ignore", "pipe"] });
|
|
1929
1983
|
} catch (error) {
|
|
1930
1984
|
await (0, import_promises2.rm)(tempPath, { force: true });
|
|
1985
|
+
for (const path of sidecars) await (0, import_promises2.rm)(path, { force: true });
|
|
1931
1986
|
throw error;
|
|
1932
1987
|
}
|
|
1933
1988
|
child.stderr?.on("data", (chunk) => {
|
|
@@ -2029,6 +2084,7 @@ async function renderRgbaVideo(renderFrame, options) {
|
|
|
2029
2084
|
throw error;
|
|
2030
2085
|
} finally {
|
|
2031
2086
|
await (0, import_promises2.rm)(tempPath, { force: true });
|
|
2087
|
+
for (const path of sidecars) await (0, import_promises2.rm)(path, { force: true });
|
|
2032
2088
|
}
|
|
2033
2089
|
}
|
|
2034
2090
|
|
|
@@ -4800,6 +4856,10 @@ async function renderFilmVideo(film, outputPath, options = {}) {
|
|
|
4800
4856
|
audioPath: options.audioPath,
|
|
4801
4857
|
audioOffset: from > 0 ? from : void 0,
|
|
4802
4858
|
ffmpegPath: options.ffmpegPath,
|
|
4859
|
+
// An MP4 carries the film's title, chapters, and captions. A range render shifts them to its own start.
|
|
4860
|
+
title: compiled.title,
|
|
4861
|
+
chapters: options.chapters === false ? [] : shiftedChapters(compiled, from),
|
|
4862
|
+
captions: options.embedCaptions === false ? [] : compiled.captions.map((cue) => ({ t0: cue.t0 - from, t1: cue.t1 - from, text: cue.text })),
|
|
4803
4863
|
signal: options.signal,
|
|
4804
4864
|
onProgress: options.onProgress
|
|
4805
4865
|
});
|
|
@@ -4808,6 +4868,12 @@ async function renderFilmVideo(film, outputPath, options = {}) {
|
|
|
4808
4868
|
await pool.close();
|
|
4809
4869
|
}
|
|
4810
4870
|
}
|
|
4871
|
+
function shiftedChapters(film, from) {
|
|
4872
|
+
const sorted = [...film.chapters].sort((a, b) => a.time - b.time);
|
|
4873
|
+
const running = sorted.filter((chapter) => chapter.time <= from).pop();
|
|
4874
|
+
const later = sorted.filter((chapter) => chapter.time > from).map((chapter) => ({ title: chapter.title, time: chapter.time - from }));
|
|
4875
|
+
return running ? [{ title: running.title, time: 0 }, ...later] : later;
|
|
4876
|
+
}
|
|
4811
4877
|
var gifApi = typeof gifenc.GIFEncoder === "function" ? gifenc : gifenc.default;
|
|
4812
4878
|
function changedRegion(previous, current, width, height) {
|
|
4813
4879
|
let minX = width, minY = height, maxX = -1, maxY = -1;
|
package/dist/stage-export.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { V as VideoCodec } from './video-
|
|
1
|
+
import { V as VideoCodec } from './video-BSwNJZkn.cjs';
|
|
2
2
|
import { ThemeMode, RenderBackground, VideoFrameInfo, RgbaVideoOutput } from './index.cjs';
|
|
3
3
|
import { FromSvgOptions, SvgNode, CompileOverrides, CompiledFilm, FilmDefinition } from './stage.cjs';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
@@ -38,6 +38,10 @@ interface FilmRenderOptions extends CompileOverrides {
|
|
|
38
38
|
memoryBudget?: number;
|
|
39
39
|
from?: number;
|
|
40
40
|
to?: number;
|
|
41
|
+
/** Set to false to leave chapter markers out of an MP4. */
|
|
42
|
+
chapters?: boolean;
|
|
43
|
+
/** Set to false to leave the caption track out of an MP4. The WebVTT sidecar is not affected. */
|
|
44
|
+
embedCaptions?: boolean;
|
|
41
45
|
audioPath?: string;
|
|
42
46
|
ffmpegPath?: string;
|
|
43
47
|
/** Encoder threads. Rasterizing is usually the slower step, so a few are enough. */
|
package/dist/stage-export.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { V as VideoCodec } from './video-
|
|
1
|
+
import { V as VideoCodec } from './video-BSwNJZkn.js';
|
|
2
2
|
import { ThemeMode, RenderBackground, VideoFrameInfo, RgbaVideoOutput } from './index.js';
|
|
3
3
|
import { FromSvgOptions, SvgNode, CompileOverrides, CompiledFilm, FilmDefinition } from './stage.js';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
@@ -38,6 +38,10 @@ interface FilmRenderOptions extends CompileOverrides {
|
|
|
38
38
|
memoryBudget?: number;
|
|
39
39
|
from?: number;
|
|
40
40
|
to?: number;
|
|
41
|
+
/** Set to false to leave chapter markers out of an MP4. */
|
|
42
|
+
chapters?: boolean;
|
|
43
|
+
/** Set to false to leave the caption track out of an MP4. The WebVTT sidecar is not affected. */
|
|
44
|
+
embedCaptions?: boolean;
|
|
41
45
|
audioPath?: string;
|
|
42
46
|
ffmpegPath?: string;
|
|
43
47
|
/** Encoder threads. Rasterizing is usually the slower step, so a few are enough. */
|
package/dist/stage-export.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
encodePng,
|
|
3
3
|
renderRgbaVideo,
|
|
4
4
|
renderToSvg
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-F6QI6QJY.js";
|
|
6
6
|
import "./chunk-RPAHMKAR.js";
|
|
7
7
|
import {
|
|
8
8
|
frameToSvg,
|
|
@@ -347,6 +347,10 @@ async function renderFilmVideo(film, outputPath, options = {}) {
|
|
|
347
347
|
audioPath: options.audioPath,
|
|
348
348
|
audioOffset: from > 0 ? from : void 0,
|
|
349
349
|
ffmpegPath: options.ffmpegPath,
|
|
350
|
+
// An MP4 carries the film's title, chapters, and captions. A range render shifts them to its own start.
|
|
351
|
+
title: compiled.title,
|
|
352
|
+
chapters: options.chapters === false ? [] : shiftedChapters(compiled, from),
|
|
353
|
+
captions: options.embedCaptions === false ? [] : compiled.captions.map((cue) => ({ t0: cue.t0 - from, t1: cue.t1 - from, text: cue.text })),
|
|
350
354
|
signal: options.signal,
|
|
351
355
|
onProgress: options.onProgress
|
|
352
356
|
});
|
|
@@ -355,6 +359,12 @@ async function renderFilmVideo(film, outputPath, options = {}) {
|
|
|
355
359
|
await pool.close();
|
|
356
360
|
}
|
|
357
361
|
}
|
|
362
|
+
function shiftedChapters(film, from) {
|
|
363
|
+
const sorted = [...film.chapters].sort((a, b) => a.time - b.time);
|
|
364
|
+
const running = sorted.filter((chapter) => chapter.time <= from).pop();
|
|
365
|
+
const later = sorted.filter((chapter) => chapter.time > from).map((chapter) => ({ title: chapter.title, time: chapter.time - from }));
|
|
366
|
+
return running ? [{ title: running.title, time: 0 }, ...later] : later;
|
|
367
|
+
}
|
|
358
368
|
var gifApi = typeof gifenc.GIFEncoder === "function" ? gifenc : gifenc.default;
|
|
359
369
|
function changedRegion(previous, current, width, height) {
|
|
360
370
|
let minX = width, minY = height, maxX = -1, maxY = -1;
|