@holtjs/stage 0.17.0 → 0.17.1

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.
@@ -414,6 +414,8 @@ export interface ComposeVideoLayersOptions {
414
414
  readonly crf?: number;
415
415
  /** Audio bitrate (`default = '192k'`). */
416
416
  readonly audioBitrate?: string;
417
+ /** Extra CLI flags appended before `<outputPath>`. */
418
+ readonly extraArgs?: readonly string[];
417
419
  }
418
420
  export interface ComposeVideoLayersResult {
419
421
  readonly outputPath: string;
package/dist/headless.js CHANGED
@@ -2018,7 +2018,7 @@ function buildFfmpegCompositeArgs(options) {
2018
2018
  }
2019
2019
  let curVideo = cutLabels[0];
2020
2020
  if (cutLabels.length > 1) {
2021
- filters.push(`${cutLabels.join("")}concat=n=${cutLabels.length}:v=1:a=0[vcat]`);
2021
+ filters.push(`${cutLabels.join("")}concat=n=${cutLabels.length}:v=1:a=0,fps=${fps}[vcat]`);
2022
2022
  curVideo = "[vcat]";
2023
2023
  }
2024
2024
  const overlays = options.overlays ?? [];
@@ -2040,7 +2040,7 @@ function buildFfmpegCompositeArgs(options) {
2040
2040
  filters.push(`${curVideo}[${idx}:v]overlay=${ox}:${oy}:format=auto:eof_action=pass${enableOpt}${nextLbl}`);
2041
2041
  curVideo = nextLbl;
2042
2042
  }
2043
- filters.push(`${curVideo}format=yuv420p[vout]`);
2043
+ filters.push(`${curVideo}fps=${fps},format=yuv420p[vout]`);
2044
2044
  const voTrackLabels = [];
2045
2045
  if (options.voiceoverPath) {
2046
2046
  args.push("-i", options.voiceoverPath);
@@ -2083,13 +2083,14 @@ function buildFfmpegCompositeArgs(options) {
2083
2083
  args.push("-filter_complex", filters.join(";"), "-map", "[vout]");
2084
2084
  if (audioOut) args.push("-map", audioOut);
2085
2085
  if (options.totalDurationSec !== void 0 && options.totalDurationSec > 0) args.push("-t", options.totalDurationSec.toFixed(3));
2086
- args.push("-c:v", vCodec);
2086
+ args.push("-r", String(fps), "-c:v", vCodec);
2087
2087
  if (isVp9) args.push("-b:v", "0", "-crf", String(options.crf ?? 28), "-deadline", "good", "-cpu-used", "4", "-pix_fmt", "yuv420p");
2088
2088
  else {
2089
2089
  if (options.preset !== "") args.push("-preset", options.preset ?? "veryfast");
2090
2090
  args.push("-crf", String(options.crf ?? 19), "-pix_fmt", "yuv420p");
2091
2091
  }
2092
2092
  if (audioOut) args.push("-c:a", isWebm ? "libopus" : "aac", "-b:a", options.audioBitrate ?? "192k", "-shortest");
2093
+ if (options.extraArgs && options.extraArgs.length > 0) args.push(...options.extraArgs);
2093
2094
  if (isWebm || isVp9) {
2094
2095
  if (isWebm) args.push("-f", "webm");
2095
2096
  args.push(options.outputPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holtjs/stage",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Zero-dependency TypeScript 2D & 2.5D game and motion-compositing engine for WebGPU/WebGL2/Canvas2D, Bun, and Node.js with GPU SDF UI, deterministic coroutines, alpha-overlay export, and FFmpeg video compositing.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Botiverse, Inc.",
@@ -3,13 +3,13 @@ name: stage
3
3
  description: Build zero-dependency WebGPU/WebGL2/Canvas2D 2D & 2.5D games, GPU SDF UIs, StageKernel plugins, survival sandboxes, and zero-browser 60 FPS programmable videos/images with @holtjs/stage (RendererWebGpu, StageKernel, InputTimeline, Rig2D cutout skeletons, Dual-Grid ChunkedTilemap, Camera25D projection, DayNightCycle & 2D normal-map lighting, WorldDeltaSave, PanelObject, Flex/Wrap layout, damped springs, SurfaceTree barriers, SoaWorld ECS, SpatialHashGrid, FlowFieldGrid/A* nav, deterministic hit/knockback, ParticlePool/JuiceController, procedural audio DSP, headless 60 FPS recorder, and zero-PII buildSceneDigest tracing).
4
4
  ---
5
5
 
6
- # Building 2D/2.5D Games, WebGPU UI & 60 FPS Video with `@holtjs/stage`
6
+ # Building 2D/2.5D Games, WebGPU UI & 60 FPS Motion Compositing with `@holtjs/stage`
7
7
 
8
- Use this skill whenever creating or modifying a browser 2D/2.5D game, WebGPU/WebGL2 canvas UI, survival sandbox, automated `InputTimeline` test, or pure-Node headless image/storyboard/60 FPS video pipeline built on `@holtjs/stage` (`v0.10.1`, 21 subpaths).
8
+ Use this skill whenever creating or modifying a browser 2D/2.5D game, WebGPU/WebGL2 canvas UI, survival sandbox, automated `InputTimeline` / `CameraDirector` sequence, or headless 60 FPS alpha-overlay & video compositing pipeline built on `@holtjs/stage` (`v0.17.1`, 22 subpaths).
9
9
 
10
- For the exhaustive exported symbol list across all 21 subpaths, see [references/subpaths.md](references/subpaths.md).
10
+ For the exhaustive exported symbol list across all 22 subpaths, see [references/subpaths.md](references/subpaths.md).
11
11
 
12
- ## 1. Install & Choose from the 21 Subpaths
12
+ ## 1. Install & Choose from the 22 Subpaths
13
13
 
14
14
  ```bash
15
15
  pnpm add @holtjs/stage
@@ -22,8 +22,8 @@ pnpm add @holtjs/stage
22
22
  | Core engine (`Game`, `Scene`, `SpriteObject`, `AnimationManager`, `ShapeBatch`, `InstancedBatch`, `Panel`, `Graphics`, `Container`, `Text`) | `@holtjs/stage` | Browser (Headless via `./headless`) |
23
23
  | Sprite-sheet & 4/8-directional atlas animation (`AnimationManager`, `createFromAtlas`) | `@holtjs/stage/anims` | Yes |
24
24
  | Native WebGPU WGSL batch & analytical SDF renderer (`RendererWebGpu`, `requestWebGpuDevice`) | `@holtjs/stage/webgpu` | Browser WebGPU |
25
- | `StageKernel` plugins, `ActionMap`, semantic `createInputTimeline`, recorder/replay | `@holtjs/stage/kernel` | Yes |
26
- | Zero-browser 60 FPS Node PNG, storyboard & stereo video (`createHeadlessStage`) | `@holtjs/stage/headless` | Yes (`@napi-rs/canvas`) |
25
+ | `StageKernel` plugins, `ActionMap`, `createInputTimeline`, `createCameraDirector`, `RollbackSession` | `@holtjs/stage/kernel` | Yes |
26
+ | Headless WebGPU/Canvas2D 60 FPS PNG, Alpha Overlays, `composeVideoLayers` & `runHeadlessRollouts` | `@holtjs/stage/headless` | Yes (Bun / Node / Deno) |
27
27
  | 2D cutout skeletal rig, O(1) equipment/skin swap, 2-layer bone-masked mixer | `@holtjs/stage/rig2d` | Yes |
28
28
  | Sparse `ChunkedTilemap`, 16-tile Dual-Grid & 47-tile Blob autotilers, island generator | `@holtjs/stage/tilemap` | Yes |
29
29
  | Rotatable oblique `Camera25D` + `mountStage25D` upright cylindrical billboards | `@holtjs/stage/projection` | Yes |
@@ -245,35 +245,47 @@ scene.tweens.spring({
245
245
  scene.tweens.to({ targets: card, alpha: { from: 0, to: 1 }, duration: 180, ease: 'outCubic' });
246
246
  ```
247
247
 
248
- ## 7. Zero-Browser 60 FPS Image, Storyboard & Video Rendering (`@holtjs/stage/headless`)
248
+ ## 7. Headless 60 FPS Alpha Overlays, `CameraDirector` & `composeVideoLayers` (`@holtjs/stage/headless`)
249
249
 
250
250
  ```ts
251
- import { createCanvas, Path2D } from '@napi-rs/canvas';
252
- import { createHeadlessStage, renderStoryboard, createAudioTimeline } from '@holtjs/stage/headless';
253
- import { renderFoley, buildStepWoodFoley } from '@holtjs/stage/audio';
254
-
255
- const stage = createHeadlessStage({
256
- createCanvas,
257
- Path2D,
251
+ import { createCameraDirector } from '@holtjs/stage/kernel';
252
+ import {
253
+ composeVideoLayers,
254
+ createHeadlessStageAsync,
255
+ renderStoryboard,
256
+ } from '@holtjs/stage/headless';
257
+
258
+ const director = createCameraDirector();
259
+ const stage = await createHeadlessStageAsync({
260
+ renderer: 'auto',
258
261
  width: 1280,
259
262
  height: 720,
260
263
  fps: 60,
261
- backgroundColor: '#131722',
262
- scene: MyScene,
264
+ transparent: true, // straight-alpha RGBA readback (`unpremultiplyRgbaInPlace`)
265
+ plugins: [director],
266
+ scene: OverlayScene,
263
267
  });
264
268
 
265
- // Fast-forward simulation without rasterizing intermediate frames, or render a 3x2 storyboard PNG:
266
- const board = renderStoryboard(stage, {
267
- frames: [0, 60, 120, 180, 240, 300],
268
- columns: 3,
269
- tileScale: 0.5,
270
- createCanvas,
271
- });
269
+ // 1. Visual QA keyframe contact sheet + paired SceneDigest array:
270
+ const qa = renderStoryboard(stage, { frames: [0, 120, 240, 360], columns: 2, tileScale: 0.5 });
272
271
 
273
- const audio = createAudioTimeline({ sampleRate: 44100 });
274
- audio.addAtFrame(12, 60, renderFoley(buildStepWoodFoley(0), 44100), { pan: -0.4, gain: 0.7 });
275
- const wavBytes = audio.toWav(5000);
272
+ // 2. Encode 60 FPS transparent Alpha Overlay (`libvpx-vp9` `yuva420p` on .webm, `qtrle` on .mov):
273
+ await stage.encodeVideo({ outputPath: 'overlay.webm', frames: 600, alpha: true });
276
274
  stage.destroy();
275
+
276
+ // 3. Composite external video cuts + Stage Alpha Overlay + voiceover segments + ducked BGM:
277
+ await composeVideoLayers({
278
+ outputPath: 'final.mp4',
279
+ fps: 60,
280
+ cuts: [
281
+ { path: 'shot1.mp4', startSec: 2, durationSec: 5, zoom: 1.25, cropY: 0 },
282
+ { path: 'shot2.mp4', startSec: 0, durationSec: 5 },
283
+ ],
284
+ overlays: [{ path: 'overlay.webm', startSec: 0 }],
285
+ voiceoverSegments: [{ path: 'seg0.mp3', startSec: 0.4 }],
286
+ bgmPath: 'bgm.wav',
287
+ ducking: true,
288
+ });
277
289
  ```
278
290
 
279
291
  ## 8. High-Value Gotchas (Avoid These Mistakes!)
@@ -1,6 +1,6 @@
1
1
  # `@holtjs/stage` Subpath API Quick Reference
2
2
 
3
- All symbols verified against `src/*.ts` (`@holtjs/stage@0.17.0`, 22 subpaths).
3
+ All symbols verified against `src/*.ts` (`@holtjs/stage@0.17.1`, 22 subpaths).
4
4
 
5
5
  ## `@holtjs/stage` (~71.3 kB gz · Core Engine Barrel)
6
6
  - **Bootstrap & Lifecycle**: `Stage` / `Stage2D` (namespaces), `AUTO`, `WEBGPU`, `WEBGL`, `CANVAS`, `Scale` (`NONE`, `FIT`, `RESIZE`), `Scenes`, `Game` (`.stepSimOnly()`, `.kernel`, `.anims`), `Scene` (`.update()` simulation + `.preRender()` presentation, `.anims`), `SceneManager`, `ScaleManager` (`.fitToContainer()`), `GameLoop`, `EngineClock`, `LoaderPlugin` (`.atlas()`), `JsonCache`, `GameObjectFactory` (`scene.add.sprite`, `shapeBatch`, `instancedBatch`, `customPass`, `panel`, `blitter`, etc.), `AnimationManager` (`.create()`, `.createFromAtlas()`, `.generateFrameNames()`, `.generateFrameNumbers()`)