@dantea/opencut 0.1.0 → 0.1.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.
Files changed (44) hide show
  1. package/dist/commands.d.ts +1 -0
  2. package/dist/commands.js +3 -1
  3. package/dist/system-probe +0 -0
  4. package/dist/video.js +7 -0
  5. package/docs/CLI.md +40 -6
  6. package/docs/INSTALL.md +13 -8
  7. package/docs/SDK.md +10 -3
  8. package/docs/VIDEO_DEFINITIONS.md +13 -8
  9. package/node_modules/@opencut/core/dist/render-plan.d.ts +1 -0
  10. package/node_modules/@opencut/core/dist/render-plan.js +5 -4
  11. package/node_modules/@opencut/core/dist/render-sources.d.ts +1 -0
  12. package/node_modules/@opencut/core/dist/video-build.js +2 -2
  13. package/node_modules/@opencut/core/dist/video-media-cache.d.ts +15 -0
  14. package/node_modules/@opencut/core/dist/{video-recipe-cache.js → video-media-cache.js} +7 -7
  15. package/node_modules/@opencut/core/dist/video-picture-cache.d.ts +3 -0
  16. package/node_modules/@opencut/core/dist/video-picture-cache.js +29 -0
  17. package/node_modules/@opencut/core/dist/video-processing.js +2 -2
  18. package/node_modules/@opencut/core/dist/video-render.d.ts +4 -1
  19. package/node_modules/@opencut/core/dist/video-render.js +6 -1
  20. package/node_modules/@opencut/core/package.json +3 -3
  21. package/node_modules/@opencut/media/dist/enhance.js +11 -3
  22. package/node_modules/@opencut/media/dist/index.d.ts +1 -0
  23. package/node_modules/@opencut/media/dist/picture-cache.d.ts +39 -0
  24. package/node_modules/@opencut/media/dist/picture-cache.js +169 -0
  25. package/node_modules/@opencut/media/dist/picture-seek.d.ts +4 -0
  26. package/node_modules/@opencut/media/dist/picture-seek.js +77 -0
  27. package/node_modules/@opencut/media/dist/process-memory +0 -0
  28. package/node_modules/@opencut/media/dist/render.d.ts +5 -1
  29. package/node_modules/@opencut/media/dist/render.js +195 -109
  30. package/node_modules/@opencut/media/dist/transform-layer.d.ts +7 -1
  31. package/node_modules/@opencut/media/dist/transform-layer.js +32 -2
  32. package/node_modules/@opencut/media/dist/video-enhance +0 -0
  33. package/node_modules/@opencut/media/dist/video-filter.d.ts +2 -0
  34. package/node_modules/@opencut/media/dist/video-filter.js +4 -0
  35. package/node_modules/@opencut/media/dist/video-interpolate +0 -0
  36. package/node_modules/@opencut/media/package.json +2 -2
  37. package/node_modules/@opencut/sdk/package.json +3 -3
  38. package/node_modules/@opencut/shared/package.json +1 -1
  39. package/package.json +5 -5
  40. package/skills/video-editor/SKILL.md +7 -1
  41. package/skills/video-editor/references/cli.md +7 -0
  42. package/skills/video-editor/references/sdk.md +5 -0
  43. package/skills/video-editor/references/video-definitions.md +7 -3
  44. package/node_modules/@opencut/core/dist/video-recipe-cache.d.ts +0 -16
@@ -103,6 +103,7 @@ declare const commands: {
103
103
  type Command = keyof typeof commands;
104
104
  export declare function parseCommandLine(args: string[]): {
105
105
  values: {
106
+ 'picture-cache'?: string;
106
107
  output?: string;
107
108
  root?: string;
108
109
  resource?: string[];
package/dist/commands.js CHANGED
@@ -5,6 +5,7 @@ import { UsageError } from './usage.js';
5
5
  const optionTypes = {
6
6
  ...processingOptionTypes,
7
7
  ...renderOptionTypes,
8
+ 'picture-cache': { type: 'string' },
8
9
  output: { type: 'string', short: 'o' },
9
10
  root: { type: 'string' },
10
11
  resource: { type: 'string', multiple: true },
@@ -65,10 +66,11 @@ const commands = {
65
66
  options: ['frame', 'timestamp', 'quality', 'params'],
66
67
  },
67
68
  render: {
68
- args: `${definition} --output <new.mp4> ${qualityOption} ${params}`,
69
+ args: `${definition} --output <new.mp4> [--picture-cache <directory>] ${qualityOption} ${params}`,
69
70
  options: [
70
71
  'output',
71
72
  'params',
73
+ 'picture-cache',
72
74
  ...Object.keys(renderOptionTypes),
73
75
  ...Object.keys(processingOptionTypes),
74
76
  ],
package/dist/system-probe CHANGED
Binary file
package/dist/video.js CHANGED
@@ -26,6 +26,9 @@ export async function runVideoCommand(command, file, values) {
26
26
  const { output } = values;
27
27
  if (command === 'render' && !output?.toLowerCase().endsWith('.mp4'))
28
28
  throw new UsageError(`Usage: ${commandUsage(command)}`);
29
+ const pictureCacheDirectory = values['picture-cache'];
30
+ if (pictureCacheDirectory !== undefined && !pictureCacheDirectory.trim())
31
+ throw new UsageError('--picture-cache requires a directory.');
29
32
  const controls = command === 'render' ? parseRenderControls(values) : {};
30
33
  await withCommandCancellation(async (signal) => {
31
34
  const params = await readParams(values.params, signal);
@@ -81,6 +84,7 @@ export async function runVideoCommand(command, file, values) {
81
84
  else {
82
85
  const result = await renderCompiledVideo(video, output, {
83
86
  ...controls,
87
+ pictureCacheDirectory,
84
88
  signal,
85
89
  ...(!values.json && {
86
90
  onProgress: (event) => {
@@ -97,6 +101,9 @@ export async function runVideoCommand(command, file, values) {
97
101
  else {
98
102
  for (const warning of result.warnings ?? [])
99
103
  process.stderr.write(`Warning: ${warning}\n`);
104
+ for (const { startFrame, endFrame, status } of result.pictureRanges ??
105
+ [])
106
+ console.log(`Picture [${startFrame}, ${endFrame}): ${status}`);
100
107
  console.log(`Saved ${result.frameCount} frames to ${result.path}`);
101
108
  }
102
109
  }
package/docs/CLI.md CHANGED
@@ -17,8 +17,40 @@ opencut subtitles export edit.video.ts --output captions.srt
17
17
 
18
18
  Use `opencut render --help` for quality, resolution, codec, frame rate and
19
19
  audio settings. Outputs are new files unless a supported render explicitly
20
- requests `--overwrite`. Use `--json` for machine output and SIGINT or SIGTERM
21
- to cancel foreground work. Render runs in the CLI with FFmpeg subprocesses.
20
+ requests `--overwrite`. OpenCut protects source files and their aliases,
21
+ including when picture is cached. Use `--json` for machine output and SIGINT
22
+ or SIGTERM to cancel foreground work. Render runs in the CLI with FFmpeg
23
+ subprocesses.
24
+
25
+ ## Reuse picture between exports
26
+
27
+ ```sh
28
+ opencut render edit.video.ts --picture-cache ./render-cache -o first.mp4
29
+ # Edit the definition, then pass the same cache directory.
30
+ opencut render edit.video.ts --picture-cache ./render-cache -o revision.mp4
31
+ ```
32
+
33
+ The picture cache uses the FFV1 encoder in FFmpeg to store lossless composited
34
+ picture on the project frame grid. Shots, overlays, subtitles and transitions
35
+ set the range boundaries. A range can move to a different timeline frame and
36
+ reuse its picture if its source samples and visual layers stay the same.
37
+ Edits to visual sources, framing, grades, captions and transitions rebuild
38
+ the ranges they affect. Edits to audio tracks and mix settings reuse
39
+ unchanged picture. Each export mixes audio on the current timeline and
40
+ encodes a new MP4 at the requested output frame rate. The [recipe cache](#media-recipes)
41
+ stores upstream processing such as frame interpolation.
42
+
43
+ Render prints `Picture [start, end): reused` or `rendered` for each range.
44
+ With `--json`, `pictureRanges` contains `startFrame`, `endFrame` and `status`.
45
+ Ranges use zero-based project frames with an exclusive end, even when the
46
+ output frame rate differs.
47
+
48
+ Use a private local cache directory with room for lossless video. Cache files
49
+ are kept under `picture-v1` until removed. Stop active renders before clearing
50
+ the cache. The first render can take longer while it populates the cache.
51
+ For eligible MP4 and MOV footage, cache misses can seek into the source.
52
+ OpenCut falls back to sequential decoding when a seek cannot preserve frame
53
+ selection.
22
54
 
23
55
  ## Check the installation
24
56
 
@@ -114,8 +146,9 @@ recipes.
114
146
 
115
147
  Processing limits apply to fresh recipe work. Cached media and composition
116
148
  outputs have their own disk usage. Matching inputs, effective AI profiles,
117
- algorithm settings, and backend versions reuse completed entries. A backend version change rebuilds affected
118
- steps and their dependents on the next run. Older entries stay on disk until
149
+ algorithm settings, and backend fingerprints reuse completed entries. A change
150
+ to the worker, encoder settings or system version can rebuild affected steps
151
+ and their dependents on the next run. Older entries stay on disk until
119
152
  removed. Stop active builds before clearing the cache directory.
120
153
 
121
154
  Foreground rendering reports step starts, media time, completions, and cache
@@ -217,8 +250,9 @@ Caches, native models, system frameworks and third-party Node packages
217
250
  are not copied. Choose a compatible OpenCut build and FFmpeg
218
251
  installation. VideoToolbox recipes still require supported Apple Silicon
219
252
  hardware and macOS; Apple does not expose a separate model version, so
220
- results can vary with the OS. OpenCut requires the recorded backend
221
- version and does not substitute another algorithm.
253
+ results can vary with the OS. The recorded backend version identifies the
254
+ required processing behavior. A compatible worker or encoder update can
255
+ invalidate cached media while preserving compatibility with existing packages.
222
256
 
223
257
  Packaging needs space for the listed payload once, plus small manifest
224
258
  and filesystem overhead. Sources shared by clips are copied once per path;
package/docs/INSTALL.md CHANGED
@@ -4,7 +4,9 @@ The first distribution target is Apple Silicon with macOS 15 or later. The CLI n
4
4
 
5
5
  ## pnpm
6
6
 
7
- Install the CLI from the npm registry or run it on demand.
7
+ Install the CLI from the npm registry or run it on demand. If pnpm's global
8
+ bin directory is missing from `PATH`, run `pnpm setup` and open a new shell
9
+ before using `pnpm add -g`.
8
10
 
9
11
  ```sh
10
12
  pnpm add -g @dantea/opencut
@@ -15,7 +17,7 @@ pnpm dlx @dantea/opencut --help
15
17
  You can also install the packed archive directly.
16
18
 
17
19
  ```sh
18
- pnpm add -g ./opencut-cli-0.1.0-macos-arm64.tgz
20
+ pnpm add -g ./opencut-cli-0.1.3-macos-arm64.tgz
19
21
  ```
20
22
 
21
23
  Run the CLI from any directory. A definition can import `@opencut/sdk` and
@@ -25,8 +27,8 @@ reports the import error. Repair or reinstall the project's SDK. Third-party
25
27
  imports resolve from the definition's project as usual.
26
28
 
27
29
  For editor type checking or SDK use from a separate Node program, install
28
- `@dantea/opencut` locally and import from `@dantea/opencut/sdk`. Use ESM and
29
- TypeScript syntax supported by Node's type stripping.
30
+ locally with `pnpm add @dantea/opencut` and import from `@dantea/opencut/sdk`.
31
+ Use ESM and TypeScript syntax supported by Node's type stripping.
30
32
 
31
33
  The package includes the official [Agent Skill](../skills/video-editor/SKILL.md),
32
34
  its references, the CLI and SDK guides, and the authoring examples. In a
@@ -109,9 +111,12 @@ add Apple-issued timestamps and a stapled ticket to the distribution app.
109
111
  Before cutting a release, synchronize the version in the root and workspace
110
112
  package manifests. Run the manually dispatched [release workflow](https://github.com/dante-teo/opencut/actions/workflows/release.yml)
111
113
  on the matching `vMAJOR.MINOR.PATCH` tag with `publish` off to generate
112
- test artifacts. The workflow tests the CLI archive in isolated npm installs,
113
- a temporary Homebrew tap and an unpacked review app. A Homebrew upgrade
114
- test uses the same archive under a simulated older keg version for the first release.
114
+ test artifacts. The workflow tests the CLI with pnpm, a temporary Homebrew
115
+ tap and an unpacked review app. The pnpm smoke test installs the tarball
116
+ offline, then serves the same archive from a local test registry to exercise
117
+ global install, `pnpm dlx`, local SDK import and uninstall. A Homebrew
118
+ upgrade test uses the same archive under a simulated older keg version for
119
+ the first release.
115
120
  The two CLI installation checks render the bundled opening card and run the
116
121
  installed-runtime workflow suite with Python 3.11+, FFmpeg and ffprobe.
117
122
  Software rendering, Lanczos upscaling, and failure handling run on every host.
@@ -126,7 +131,7 @@ work="$(mktemp -d)"
126
131
  bash scripts/release/test-workflows.sh "$(command -v opencut)" "$work/project"
127
132
  ```
128
133
 
129
- To keep results from a local npm or Homebrew installation check, set
134
+ To keep results from a local pnpm or Homebrew installation check, set
130
135
  `OPENCUT_RELEASE_EVALUATION_DIR` to the absolute path of a new directory
131
136
  outside the checkout before running the check.
132
137
 
package/docs/SDK.md CHANGED
@@ -4,7 +4,7 @@ The installed CLI and review app include the authoring SDK. A `.video.ts`
4
4
  definition can import `@opencut/sdk` without setting up a Node project.
5
5
  For TypeScript editor support or SDK usage from a separate Node program,
6
6
  install `@dantea/opencut` locally and use the `@dantea/opencut/sdk` export in the
7
- examples below. See the [installation guide](INSTALL.md#npm).
7
+ examples below. See the [installation guide](INSTALL.md#pnpm).
8
8
 
9
9
  Use Node 24.12+ (within 24.x). The CLI resolves bundled SDK imports from
10
10
  trusted `.video.ts` definitions, which should default-export
@@ -28,10 +28,17 @@ await renderCompiledVideo(video, 'delivery.mp4', {
28
28
  ```
29
29
 
30
30
  Use `renderVideo(file, output, options)` to compile and render in one call.
31
- A compiled render checks the identity of each source it uses before copying
32
- it for the render. If a source has changed, compile the definition again.
31
+ A compiled render checks source identities before decoding or reusing
32
+ picture. It copies media on first decode. If a source has changed, compile
33
+ the definition again.
33
34
  Pass an `AbortSignal` to cancel a foreground render.
34
35
 
36
+ Pass the same `pictureCacheDirectory` to `renderVideo` or
37
+ `renderCompiledVideo` on the initial export and revisions. The result
38
+ includes `pictureRanges` with zero-based project frames in `startFrame`
39
+ and `endFrame` (exclusive) and a `status` of `reused` or `rendered`.
40
+ See [picture cache behavior and storage](CLI.md#reuse-picture-between-exports).
41
+
35
42
  Final renders default to `quality`. Preview frames, clips, contact sheets
36
43
  and watches default to `fast`. Pass `quality: 'fast' | 'quality' | 'maximum'`
37
44
  to set the profile. You can choose the same profile when calling
@@ -348,8 +348,11 @@ file's clock. For example, if an unselected track starts at 0 s, the selected
348
348
  video at 2 s, and the selected audio at 2.25 s, the derived video starts at 0 s
349
349
  and the audio at 0.25 s. Timeline clip offsets use the final recipe output.
350
350
 
351
- When both operations fit the shot, interpolate before super-resolution to
352
- keep the interpolation surfaces at source resolution.
351
+ OpenCut runs the steps in recipe order. Denoising before upscaling keeps
352
+ denoising at the smaller dimensions. For 30 → 60 fps, upscaling first
353
+ enhances half as many frames, but interpolation then has to support and
354
+ process the larger frames. Interpolating first keeps interpolation at the
355
+ original dimensions and doubles the number of frames sent to enhancement.
353
356
 
354
357
  | Step and preset | Processor | Supported geometry and settings |
355
358
  | ----------------------------------------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -359,8 +362,14 @@ keep the interpolation surfaces at source resolution.
359
362
 
360
363
  The accepted `backend` value is `videotoolbox`, also the default. Both
361
364
  super-resolution presets run AI inference and use Lanczos to reduce the
362
- model output to the target size when needed. Temporal denoising may help
363
- with compression noise. Apple exposes no separate deblocking control here.
365
+ model output to the target size when needed. The requested size controls the
366
+ result. The temporal model still computes its full 4× output. Its input size
367
+ limit applies to the frame reaching the step, after any explicit crop or
368
+ resize. OpenCut reports unsupported dimensions and leaves any source resize
369
+ to the recipe author.
370
+
371
+ Temporal denoising may help with compression noise. Apple exposes no
372
+ separate deblocking control here.
364
373
 
365
374
  Use Apple Silicon with macOS 26 or later and an OpenCut build made with the
366
375
  macOS 26+ SDK. Run `opencut system inspect --json` and look for
@@ -383,10 +392,6 @@ interpreted as video range. HDR, full-range, higher-bit-depth, alpha, and
383
392
  unsupported model configurations produce errors. The preview and final MP4
384
393
  use the timeline renderer's BT.709 output space.
385
394
 
386
- Recipe order is processing order. Denoising before upscaling keeps its
387
- work at the smaller dimensions. Interpolating first runs enhancement over
388
- more frames, but keeps interpolation at the original dimensions. Upscaling
389
- first may take the picture outside the interpolation processor’s limits.
390
395
  Check `system inspect` for both processors when chaining them. For a
391
396
  comparison, use `resize` with `"method": "lanczos"` at the same target
392
397
  dimensions. Review several consecutive frames with fine text, faces,
@@ -13,6 +13,7 @@ interface VisualRenderProperties {
13
13
  sourceStartFrame: number;
14
14
  retiming?: RenderTimeMapping & {
15
15
  sourceOriginNs: number;
16
+ localSourceOriginNs: number;
16
17
  };
17
18
  frameCount: number;
18
19
  x: number;
@@ -2,7 +2,7 @@ import { maximumVisualScale } from '@opencut/shared';
2
2
  import { clipSourcePosition, clipSourceTime, clipSpeed, } from './clip-timing.js';
3
3
  import { continuesMediaRun, resolveTimeline } from './evaluation.js';
4
4
  import { resolveAudioFade } from './audio.js';
5
- import { compareTimes } from './time.js';
5
+ import { compareTimes, frameTime } from './time.js';
6
6
  export class RenderError extends Error {
7
7
  name = 'RenderError';
8
8
  }
@@ -21,9 +21,8 @@ function exactFrame(time, rate, label) {
21
21
  throw new RenderError(`${label} exceeds the supported frame range.`);
22
22
  return Number(frame);
23
23
  }
24
- /** The affine source origin stays identical for every piece of a split. */
25
- function sourceOriginNanoseconds(clip) {
26
- const origin = clipSourcePosition(clip, { numerator: 0, denominator: 1 });
24
+ function sourceOriginNanoseconds(clip, time = { numerator: 0, denominator: 1 }) {
25
+ const origin = clipSourcePosition(clip, time);
27
26
  return Number((origin.numerator * 1000000000n) / origin.denominator);
28
27
  }
29
28
  /** Pure compilation from saved-model semantics to ordered, integer-frame segments. */
@@ -177,6 +176,7 @@ export function planProjectRender(project, { burnSubtitles = true } = {}) {
177
176
  retiming: {
178
177
  ...retiming,
179
178
  sourceOriginNs: sourceOriginNanoseconds(clip),
179
+ localSourceOriginNs: sourceOriginNanoseconds(clip, frameTime(start, frameRate)),
180
180
  },
181
181
  }),
182
182
  ...visual,
@@ -210,6 +210,7 @@ export function planProjectRender(project, { burnSubtitles = true } = {}) {
210
210
  sourceOut,
211
211
  speed: clipSpeed(clip),
212
212
  sourceOriginNs: sourceOriginNanoseconds(clip),
213
+ localSourceOriginNs: sourceOriginNanoseconds(clip, frameTime(startFrame, frameRate)),
213
214
  },
214
215
  };
215
216
  }),
@@ -17,6 +17,7 @@ export declare function bindRenderSources({ visualClips, audioClips, visualTrans
17
17
  sourceStartFrame: number;
18
18
  retiming?: import("@opencut/shared").RenderTimeMapping & {
19
19
  sourceOriginNs: number;
20
+ localSourceOriginNs: number;
20
21
  };
21
22
  frameCount: number;
22
23
  x: number;
@@ -5,7 +5,7 @@ import { parseVideoDefinition, VideoDefinitionError, } from './video-definition.
5
5
  import { fileLease, fingerprintFile, hashJson, missing, syncPath, writeCheckpoint, } from './video-integrity.js';
6
6
  import { videoInputIdentity } from './video-input.js';
7
7
  import { processingSettings } from './video-processing.js';
8
- import { findRecipeEntry } from './video-recipe-cache.js';
8
+ import { findMediaEntry } from './video-media-cache.js';
9
9
  import { inheritsRenderQuality, recipeFormatSchema, } from './video-recipe-schema.js';
10
10
  const sha256 = z.string().regex(/^[a-f0-9]{64}$/);
11
11
  const fingerprint = z.object({ sha256, bytes: z.int().nonnegative() });
@@ -311,7 +311,7 @@ export async function inspectBuildCheckpoint(build, signal) {
311
311
  : compile.state;
312
312
  const steps = [];
313
313
  for (const step of compile.steps) {
314
- const result = await findRecipeEntry(cache, step.key, step.format, signal);
314
+ const result = await findMediaEntry(cache, step.key, step.format, signal);
315
315
  const entry = result?.entry;
316
316
  steps.push({
317
317
  ...step,
@@ -0,0 +1,15 @@
1
+ import type { MediaMetadata } from '@opencut/media';
2
+ import type { IdentifiedMedia } from './video-input.js';
3
+ type MediaEntry = IdentifiedMedia & {
4
+ sha256: string;
5
+ };
6
+ export declare function materializeMediaEntry(directory: string, key: string, format: string, signal: AbortSignal, encode: (output: string) => Promise<MediaMetadata>): Promise<{
7
+ entry: MediaEntry;
8
+ reused: boolean;
9
+ }>;
10
+ /** Find validated media without publishing or removing anything. */
11
+ export declare function findMediaEntry(directory: string, key: string, format: string, signal?: AbortSignal): Promise<{
12
+ directory: string;
13
+ entry: MediaEntry;
14
+ } | undefined>;
15
+ export {};
@@ -15,7 +15,7 @@ const receipt = z.strictObject({
15
15
  Array.isArray(value.streams) &&
16
16
  !('path' in value)),
17
17
  });
18
- export async function materializeRecipeEntry(directory, key, format, signal, encode) {
18
+ export async function materializeMediaEntry(directory, key, format, signal, encode) {
19
19
  const release = await fileLease(join(directory, `.lock-${key.slice(0, 2)}.sqlite`), signal);
20
20
  const staging = stageDirectory(directory, key);
21
21
  try {
@@ -34,7 +34,7 @@ export async function materializeRecipeEntry(directory, key, format, signal, enc
34
34
  reused,
35
35
  };
36
36
  };
37
- const cached = await findRecipeEntry(directory, key, format, signal);
37
+ const cached = await findMediaEntry(directory, key, format, signal);
38
38
  if (cached?.directory === target)
39
39
  return { entry: cached.entry, reused: true };
40
40
  await rm(target, { recursive: true, force: true });
@@ -70,10 +70,10 @@ export async function materializeRecipeEntry(directory, key, format, signal, enc
70
70
  }
71
71
  }
72
72
  /** Find validated media without publishing or removing anything. */
73
- export async function findRecipeEntry(directory, key, format, signal) {
73
+ export async function findMediaEntry(directory, key, format, signal) {
74
74
  const target = join(directory, key);
75
75
  const published = async () => {
76
- const entry = await readRecipeEntry(target, key, format, signal);
76
+ const entry = await readMediaEntry(target, key, format, signal);
77
77
  return entry && { directory: target, entry };
78
78
  };
79
79
  const cached = await published();
@@ -92,7 +92,7 @@ export async function findRecipeEntry(directory, key, format, signal) {
92
92
  if (!/^attempt-[a-zA-Z0-9]{6}$/.test(name))
93
93
  continue;
94
94
  const attempt = join(staging, name);
95
- const entry = await readRecipeEntry(attempt, key, format, signal).catch(async (error) => {
95
+ const entry = await readMediaEntry(attempt, key, format, signal).catch(async (error) => {
96
96
  // An inspector can race a writer moving the attempt to its final location.
97
97
  if (signal?.aborted || (await statIfPresent(attempt)))
98
98
  throw error;
@@ -108,7 +108,7 @@ async function statIfPresent(path) {
108
108
  throw error;
109
109
  });
110
110
  }
111
- async function readRecipeEntry(target, key, format, signal) {
111
+ async function readMediaEntry(target, key, format, signal) {
112
112
  const path = join(target, `media.${format}`);
113
113
  const manifest = join(target, 'result.json');
114
114
  try {
@@ -134,4 +134,4 @@ async function readRecipeEntry(target, key, format, signal) {
134
134
  throw error;
135
135
  }
136
136
  }
137
- //# sourceMappingURL=video-recipe-cache.js.map
137
+ //# sourceMappingURL=video-media-cache.js.map
@@ -0,0 +1,3 @@
1
+ import type { PictureCache } from '@opencut/media';
2
+ import type { CompiledVideo } from './video-compiler.js';
3
+ export declare function openPictureCache(directory: string, video: CompiledVideo, signal?: AbortSignal): Promise<PictureCache>;
@@ -0,0 +1,29 @@
1
+ import { mkdir, realpath } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { MediaError, recipeBackendVersion } from '@opencut/media';
4
+ import { videoInputIdentity } from './video-input.js';
5
+ import { materializeMediaEntry } from './video-media-cache.js';
6
+ export async function openPictureCache(directory, video, signal = new AbortController().signal) {
7
+ if (!directory.trim())
8
+ throw new MediaError('Choose a picture cache directory.');
9
+ const root = resolve(directory, 'picture-v1');
10
+ await mkdir(root, { recursive: true, mode: 0o700 });
11
+ const cache = await realpath(root);
12
+ if (/[\r\n]/.test(cache))
13
+ throw new MediaError('Picture cache paths cannot contain line breaks.');
14
+ return {
15
+ backend: await recipeBackendVersion(signal),
16
+ sourceIdentity(path) {
17
+ signal.throwIfAborted();
18
+ const identity = video.sourceIdentity(path);
19
+ if (!identity || videoInputIdentity(path) !== identity)
20
+ throw new MediaError(`Media '${path}' changed after it was read. Compile the definition again.`);
21
+ return identity;
22
+ },
23
+ async materialize(key, encode) {
24
+ const { entry, reused } = await materializeMediaEntry(cache, key, 'nut', signal, encode);
25
+ return { path: entry.metadata.path, reused };
26
+ },
27
+ };
28
+ }
29
+ //# sourceMappingURL=video-picture-cache.js.map
@@ -6,7 +6,7 @@ import { MediaError, enhancementBackendVersion, hostRenderResources, interpolati
6
6
  import { fingerprintFile, hashJson } from './video-integrity.js';
7
7
  import { videoInputIdentity } from './video-input.js';
8
8
  import { isEnhancementStep, isInterpolationStep, } from './video-recipe-schema.js';
9
- import { materializeRecipeEntry } from './video-recipe-cache.js';
9
+ import { materializeMediaEntry } from './video-media-cache.js';
10
10
  import { recipeArguments, recipeMedia, recipeStepError, resolveRecipeStep, validateRecipeOutput, } from './video-recipe.js';
11
11
  const MiB = 1024 * 1024;
12
12
  function recipeAdmission(budget, signal) {
@@ -126,7 +126,7 @@ async function processRecipe({ input, inspection: { assetId, steps } }, director
126
126
  key,
127
127
  format: step.format,
128
128
  });
129
- const { entry, reused } = await materializeRecipeEntry(directory, key, step.format, signal, async (output) => {
129
+ const { entry, reused } = await materializeMediaEntry(directory, key, step.format, signal, async (output) => {
130
130
  assertCurrent(current);
131
131
  if (step.media.kind !== 'audio' &&
132
132
  [inputMedia, step.media].some((media) => pixels(media) > limits.maxPixels))
@@ -4,6 +4,7 @@ import type { VideoProcessingOptions } from './video-processing.js';
4
4
  import type { VideoBuild, VideoCompileOptions } from './video-files.js';
5
5
  export type VideoRenderOptions = Omit<RenderControls, 'range' | 'maxDimension'> & {
6
6
  burnSubtitles?: boolean;
7
+ pictureCacheDirectory?: string | undefined;
7
8
  processing?: VideoProcessingOptions | undefined;
8
9
  params?: VideoCompileOptions['params'];
9
10
  };
@@ -14,7 +15,7 @@ export interface VideoRenderBuild extends VideoBuild {
14
15
  readonly render: Readonly<VideoRenderConfiguration>;
15
16
  }
16
17
  /** Render one compiled revision using the shared media engine. */
17
- export declare function renderCompiledVideo(video: CompiledVideo, output: string, { burnSubtitles, quality, ...options }?: CompiledVideoRenderOptions): Promise<{
18
+ export declare function renderCompiledVideo(video: CompiledVideo, output: string, { burnSubtitles, quality, pictureCacheDirectory, ...options }?: CompiledVideoRenderOptions): Promise<{
18
19
  build?: VideoRenderBuild;
19
20
  codec: import("@opencut/media").RenderCodec;
20
21
  quality: import("@opencut/media").RenderQuality;
@@ -30,6 +31,7 @@ export declare function renderCompiledVideo(video: CompiledVideo, output: string
30
31
  durationSeconds: number;
31
32
  metadata: import("@opencut/media").MediaMetadata;
32
33
  warnings?: string[];
34
+ pictureRanges?: import("@opencut/media").PictureRange[];
33
35
  }>;
34
36
  /** Compile and render in the calling process. Subprocesses are scoped to this call. */
35
37
  export declare function renderVideo(file: string, output: string, { params, processing, ...options }?: VideoRenderOptions): Promise<{
@@ -48,4 +50,5 @@ export declare function renderVideo(file: string, output: string, { params, proc
48
50
  durationSeconds: number;
49
51
  metadata: import("@opencut/media").MediaMetadata;
50
52
  warnings?: string[];
53
+ pictureRanges?: import("@opencut/media").PictureRange[];
51
54
  }>;
@@ -5,6 +5,7 @@ import { authoredInputs, checkpointRender } from './video-build.js';
5
5
  import { withRenderSources } from './render-sources.js';
6
6
  import { compileVideo } from './video-files.js';
7
7
  import { isInterpolationStep } from './video-recipe-schema.js';
8
+ import { openPictureCache } from './video-picture-cache.js';
8
9
  async function statIfPresent(path) {
9
10
  try {
10
11
  return await stat(path);
@@ -33,7 +34,7 @@ async function protectInputs(video, output, boundSources, signal) {
33
34
  }
34
35
  }
35
36
  /** Render one compiled revision using the shared media engine. */
36
- export async function renderCompiledVideo(video, output, { burnSubtitles = true, quality = 'quality', ...options } = {}) {
37
+ export async function renderCompiledVideo(video, output, { burnSubtitles = true, quality = 'quality', pictureCacheDirectory, ...options } = {}) {
37
38
  const { onProgress, signal, overwrite, ...settings } = options;
38
39
  video = await video.forQuality(quality, !burnSubtitles, signal);
39
40
  // Record the controls the shared renderer receives, including runtime callers.
@@ -69,12 +70,16 @@ export async function renderCompiledVideo(video, output, { burnSubtitles = true,
69
70
  await protectInputs(video, output, plan.sourceMetadata.keys(), signal);
70
71
  if (!burnSubtitles)
71
72
  plan.visualClips = plan.visualClips.filter((clip) => !clip.subtitle);
73
+ const pictureCache = pictureCacheDirectory === undefined
74
+ ? undefined
75
+ : await openPictureCache(pictureCacheDirectory, video, signal);
72
76
  const result = await renderVideoTimeline({
73
77
  ...plan,
74
78
  ...settings,
75
79
  quality,
76
80
  signal,
77
81
  overwrite,
82
+ pictureCache,
78
83
  ...(onProgress && { onProgress }),
79
84
  ...(buildMetadata && { buildMetadata }),
80
85
  ...(scratchDirectory && { scratchDirectory }),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencut/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -13,8 +13,8 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@opencut/media": "0.1.0",
17
- "@opencut/shared": "0.1.0",
16
+ "@opencut/media": "0.1.3",
17
+ "@opencut/shared": "0.1.3",
18
18
  "typescript": "6.0.3",
19
19
  "zod": "4.6.7"
20
20
  },
@@ -1,4 +1,4 @@
1
- import { release } from 'node:os';
1
+ import { availableParallelism, release } from 'node:os';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { sourceColorMatrix } from '@opencut/shared';
4
4
  import { interpolationTiming } from './interpolate.js';
@@ -6,13 +6,15 @@ import { recipeInputArguments, videoSourceDuration } from './probe.js';
6
6
  import { MediaError } from './process.js';
7
7
  import { nativeRecipeFingerprint, runRecipeProcess } from './recipe-process.js';
8
8
  export const enhancementBackendId = 'videotoolbox-enhancement-v4';
9
+ // Encoder changes invalidate cached artifacts without changing the package contract.
10
+ const enhancementCacheVersion = `${enhancementBackendId}:encoder-v2`;
9
11
  const worker = fileURLToPath(new URL('./video-enhance', import.meta.url));
10
12
  export async function enhancementBackendVersion(signal) {
11
13
  if (process.platform !== 'darwin' ||
12
14
  process.arch !== 'arm64' ||
13
15
  Number(release().split('.')[0]) < 25)
14
16
  throw new MediaError('AI enhancement requires Apple Silicon and macOS 26 or later. Run opencut system inspect --json.');
15
- return nativeRecipeFingerprint(worker, enhancementBackendId, 'enhancement', signal);
17
+ return nativeRecipeFingerprint(worker, enhancementCacheVersion, 'enhancement', signal);
16
18
  }
17
19
  function enhancementTiming(input) {
18
20
  const video = input.video;
@@ -178,6 +180,8 @@ export async function runEnhancement(input, operation, output, limits, signal, o
178
180
  `settb=1/${scale}`,
179
181
  `setpts=PTS+${offset}`,
180
182
  ];
183
+ // Keep the lossless encoder at zero frame delay while bounding CPU work.
184
+ const encodeThreads = String(Math.min(4, availableParallelism()));
181
185
  const colors = [
182
186
  '-color_range',
183
187
  'tv',
@@ -255,6 +259,8 @@ export async function runEnhancement(input, operation, output, limits, signal, o
255
259
  : []),
256
260
  '-map',
257
261
  '0:v:0',
262
+ '-filter_threads',
263
+ encodeThreads,
258
264
  '-vf',
259
265
  encodeFilters.join(','),
260
266
  '-enc_time_base:v',
@@ -270,7 +276,9 @@ export async function runEnhancement(input, operation, output, limits, signal, o
270
276
  '-qp',
271
277
  '0',
272
278
  '-threads:v',
273
- '1',
279
+ encodeThreads,
280
+ '-thread_type:v',
281
+ 'slice',
274
282
  '-pix_fmt',
275
283
  'yuv420p',
276
284
  ...colors,
@@ -11,6 +11,7 @@ export { renderVideoTimeline, renderTimelineFrame, validateVideoTimeline, valida
11
11
  export type { VisualTimelineClip, VideoTimelineOptions, VideoTimelineResult, RenderControls, RenderCodec, RenderResolution, } from './render.js';
12
12
  export { renderQualities, renderQualityProfiles } from '@opencut/shared';
13
13
  export type { RenderQuality } from '@opencut/shared';
14
+ export type { PictureCache, PictureRange } from './picture-cache.js';
14
15
  export type { RenderProgress } from './render-progress.js';
15
16
  export { renderContactSheet } from './contact-sheet.js';
16
17
  export { rasterizeTextLayer, validateEmbeddedFont } from './text.js';
@@ -0,0 +1,39 @@
1
+ import type { TextLayer } from '@opencut/shared';
2
+ import type { MediaMetadata } from './probe.js';
3
+ import type { TextRaster } from './text.js';
4
+ import type { VideoTimelineOptions, VisualTimelineClip } from './render.js';
5
+ export interface PictureRange {
6
+ startFrame: number;
7
+ endFrame: number;
8
+ status: 'reused' | 'rendered';
9
+ }
10
+ export interface PictureCache {
11
+ backend: string;
12
+ sourceIdentity(path: string): string;
13
+ materialize(key: string, encode: (path: string) => Promise<MediaMetadata>): Promise<{
14
+ path: string;
15
+ reused: boolean;
16
+ }>;
17
+ }
18
+ type Transition = NonNullable<VideoTimelineOptions['visualTransitions']>[number];
19
+ interface CachePlan {
20
+ options: VideoTimelineOptions;
21
+ cache: PictureCache;
22
+ visualClips: VisualTimelineClip[];
23
+ byOwner: ReadonlyMap<string, Transition[]>;
24
+ startFrame: number;
25
+ endFrame: number;
26
+ outputWidth: number;
27
+ outputHeight: number;
28
+ warnings: string[];
29
+ rasterize(clip: VisualTimelineClip & {
30
+ text: TextLayer;
31
+ }): Promise<TextRaster>;
32
+ encode(startFrame: number, endFrame: number, destination: string): Promise<void>;
33
+ }
34
+ /** Use render inputs and clip-local sample positions as the identity of a range. */
35
+ export declare function cachePicture({ options, cache, visualClips, byOwner, startFrame, endFrame, outputWidth, outputHeight, warnings, rasterize, encode, }: CachePlan): Promise<{
36
+ concat: string;
37
+ ranges: PictureRange[];
38
+ }>;
39
+ export {};