@nodaro/shared 3.27.0 → 3.30.0
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/dist/index.cjs +317 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +301 -11
- package/dist/index.d.ts +301 -11
- package/dist/index.js +278 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/pitch-tempo-pricing.test.ts +62 -0
- package/src/__tests__/render-nodes.test.ts +38 -4
- package/src/__tests__/video-depth.test.ts +146 -0
- package/src/__tests__/video-mask.test.ts +77 -0
- package/src/credit-estimators/index.ts +10 -0
- package/src/credit-estimators/pitch-tempo.ts +68 -0
- package/src/credit-identifiers.ts +32 -7
- package/src/fan-out-rows.ts +2 -0
- package/src/index.ts +7 -0
- package/src/mask-composite.ts +108 -0
- package/src/model-catalog.ts +40 -0
- package/src/model-tree.ts +2 -0
- package/src/node-mappable-fields.ts +2 -0
- package/src/presentation-utils.ts +3 -2
- package/src/producer-types.ts +9 -0
- package/src/render-nodes.ts +14 -5
- package/src/video-depth.ts +151 -0
- package/src/video-mask.ts +96 -0
package/src/model-catalog.ts
CHANGED
|
@@ -48,6 +48,7 @@ export type ModelMode =
|
|
|
48
48
|
| "motion-transfer"
|
|
49
49
|
| "lip-sync"
|
|
50
50
|
| "video-upscale"
|
|
51
|
+
| "video-depth"
|
|
51
52
|
// audio
|
|
52
53
|
| "tts"
|
|
53
54
|
| "music"
|
|
@@ -2450,6 +2451,45 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
|
|
|
2450
2451
|
{ identifier: "volcengine-lipsync:300s", credits: 6000, note: "5-min ceiling" },
|
|
2451
2452
|
],
|
|
2452
2453
|
},
|
|
2454
|
+
// ── Video Depth ── (video-depth node; billed per duration bucket via
|
|
2455
|
+
// videoDepthCreditId in video-depth.ts — `<provider>:<bucket>s`, bare row =
|
|
2456
|
+
// the 300 s ceiling, same shape as volcengine-lipsync.)
|
|
2457
|
+
"video-depth-anything": {
|
|
2458
|
+
id: "video-depth-anything",
|
|
2459
|
+
kind: "video",
|
|
2460
|
+
modes: ["video-depth"] as const,
|
|
2461
|
+
family: "Depth Anything",
|
|
2462
|
+
label: "Video Depth Anything",
|
|
2463
|
+
series: "Depth Anything",
|
|
2464
|
+
description: "Temporally consistent depth video from any clip. Grayscale or colormapped, up to 2,400 frames or 300 seconds.",
|
|
2465
|
+
useCases: ["depth", "video-to-video", "compositing"],
|
|
2466
|
+
pricing: [
|
|
2467
|
+
{ identifier: "video-depth-anything", credits: 6000, note: "5-min ceiling (no duration given)" },
|
|
2468
|
+
{ identifier: "video-depth-anything:15s", credits: 300 },
|
|
2469
|
+
{ identifier: "video-depth-anything:30s", credits: 600 },
|
|
2470
|
+
{ identifier: "video-depth-anything:60s", credits: 1200 },
|
|
2471
|
+
{ identifier: "video-depth-anything:120s", credits: 2400 },
|
|
2472
|
+
{ identifier: "video-depth-anything:300s", credits: 6000, note: "5-min ceiling" },
|
|
2473
|
+
],
|
|
2474
|
+
},
|
|
2475
|
+
"depth-anything-frames": {
|
|
2476
|
+
id: "depth-anything-frames",
|
|
2477
|
+
kind: "video",
|
|
2478
|
+
modes: ["video-depth"] as const,
|
|
2479
|
+
family: "Depth Anything",
|
|
2480
|
+
label: "Depth Anything (per frame)",
|
|
2481
|
+
series: "Depth Anything",
|
|
2482
|
+
description: "Depth Anything v1 run on each frame. Grayscale or inferno colormap; may flicker between frames. Up to 80 s.",
|
|
2483
|
+
useCases: ["depth", "video-to-video"],
|
|
2484
|
+
pricing: [
|
|
2485
|
+
{ identifier: "depth-anything-frames", credits: 600, note: "5-min ceiling (no duration given)" },
|
|
2486
|
+
{ identifier: "depth-anything-frames:15s", credits: 30 },
|
|
2487
|
+
{ identifier: "depth-anything-frames:30s", credits: 60 },
|
|
2488
|
+
{ identifier: "depth-anything-frames:60s", credits: 120 },
|
|
2489
|
+
{ identifier: "depth-anything-frames:120s", credits: 240 },
|
|
2490
|
+
{ identifier: "depth-anything-frames:300s", credits: 600, note: "5-min ceiling" },
|
|
2491
|
+
],
|
|
2492
|
+
},
|
|
2453
2493
|
// ── Gemini video analysis ── (Gemini-only; billed per duration bucket — the
|
|
2454
2494
|
// structural credit formula lives in video-analysis-pricing.ts. Composite id
|
|
2455
2495
|
// shape `video-analysis:<model>:<bucket>s` mirrors volcengine-lipsync: bare
|
package/src/model-tree.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
VIDEO_TO_VIDEO_PROVIDERS, EXTEND_VIDEO_PROVIDERS, MOTION_TRANSFER_PROVIDERS, LIP_SYNC_PROVIDERS,
|
|
13
13
|
FACE_SWAP_PROVIDERS, TTS_PROVIDERS, DIALOGUE_PROVIDERS, TEXT_TO_AUDIO_PROVIDERS, TRANSCRIBE_PROVIDERS, MUSIC_PROVIDERS,
|
|
14
14
|
} from "./model-constants.js"
|
|
15
|
+
import { VIDEO_DEPTH_PROVIDERS } from "./video-depth.js"
|
|
15
16
|
|
|
16
17
|
export interface ModelNodeTarget {
|
|
17
18
|
nodeType: string
|
|
@@ -38,6 +39,7 @@ const ENUM_TARGETS: ReadonlyArray<readonly [readonly string[], string]> = [
|
|
|
38
39
|
[TEXT_TO_VIDEO_PROVIDERS, "generate-video"],
|
|
39
40
|
[UPSCALE_IMAGE_PROVIDERS, "upscale-image"],
|
|
40
41
|
[VIDEO_UPSCALE_PROVIDERS, "video-upscale"],
|
|
42
|
+
[VIDEO_DEPTH_PROVIDERS, "video-depth"],
|
|
41
43
|
[MODIFY_IMAGE_PROVIDERS, "modify-image"],
|
|
42
44
|
[IMAGE_EDIT_PROVIDERS, "modify-image"],
|
|
43
45
|
[VIDEO_TO_VIDEO_PROVIDERS, "video-to-video"],
|
|
@@ -27,6 +27,8 @@ export const NODE_MAPPABLE_FIELDS: Readonly<Record<string, readonly string[]>> =
|
|
|
27
27
|
// Span-replace sibling of generate-video-pro — prompt only, no
|
|
28
28
|
// negativePrompt field on the node.
|
|
29
29
|
"edit-video-pro": ["prompt"],
|
|
30
|
+
// The subject to track — a {Label} reference or a mapping writes it.
|
|
31
|
+
"video-mask": ["prompt"],
|
|
30
32
|
"video-analysis": ["analysisFocus", "youtubeUrl"],
|
|
31
33
|
"video-to-video": ["prompt"],
|
|
32
34
|
// + the two neighbour-text fields (continuity across clips): a wired Text node can feed
|
|
@@ -127,6 +127,7 @@ const MEDIA_PRODUCING_TYPES = new Set([
|
|
|
127
127
|
"lip-sync",
|
|
128
128
|
"motion-transfer",
|
|
129
129
|
"video-upscale",
|
|
130
|
+
"video-depth",
|
|
130
131
|
])
|
|
131
132
|
|
|
132
133
|
// Output type categorizations
|
|
@@ -147,7 +148,7 @@ const VIDEO_OUTPUT_TYPES = new Set([
|
|
|
147
148
|
"combine-videos", "merge-video-audio", "resize-video", "trim-video",
|
|
148
149
|
"speed-ramp", "loop-video", "fade-video", "transcode-video",
|
|
149
150
|
"upload-video",
|
|
150
|
-
"lip-sync", "motion-transfer", "video-upscale", "add-captions",
|
|
151
|
+
"lip-sync", "motion-transfer", "video-upscale", "video-depth", "add-captions",
|
|
151
152
|
"social-media-format",
|
|
152
153
|
// A render (Apply EDL) renders an EDL into video OR audio. Its medium is
|
|
153
154
|
// decided at run time (DYNAMIC_PRODUCER_TYPES), so getOutputType would answer
|
|
@@ -162,7 +163,7 @@ const VIDEO_OUTPUT_TYPES = new Set([
|
|
|
162
163
|
const AUDIO_OUTPUT_TYPES = new Set([
|
|
163
164
|
"text-to-speech", "generate-music", "text-to-audio",
|
|
164
165
|
"text-to-dialogue", "voice-changer", "dubbing", "voice-remix",
|
|
165
|
-
"voice-design", "mix-audio", "adjust-volume", "audio-fx", "trim-audio",
|
|
166
|
+
"voice-design", "mix-audio", "adjust-volume", "audio-fx", "pitch-tempo", "trim-audio",
|
|
166
167
|
"audio-isolation",
|
|
167
168
|
"audio-separation",
|
|
168
169
|
"upload-audio",
|
package/src/producer-types.ts
CHANGED
|
@@ -47,6 +47,7 @@ export const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
|
|
|
47
47
|
"speech-to-video",
|
|
48
48
|
"motion-transfer",
|
|
49
49
|
"video-upscale",
|
|
50
|
+
"video-depth",
|
|
50
51
|
"extend-video",
|
|
51
52
|
// face-swap output is video (writes generatedVideoUrl, per-result `url`).
|
|
52
53
|
// Frontend execution-graph already includes it in VIDEO_SOURCE_TYPES; this
|
|
@@ -72,6 +73,9 @@ export const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
|
|
|
72
73
|
"speed-ramp",
|
|
73
74
|
"loop-video",
|
|
74
75
|
"fade-video",
|
|
76
|
+
// Video Mask emits its mask as a video; Mask Composite its composite.
|
|
77
|
+
"video-mask",
|
|
78
|
+
"mask-composite",
|
|
75
79
|
"transcode-video",
|
|
76
80
|
"manual-edit",
|
|
77
81
|
// Remove Audio: strips the audio track, emits a silent video.
|
|
@@ -132,6 +136,10 @@ export const DYNAMIC_PRODUCER_TYPES: ReadonlySet<string> = new Set([
|
|
|
132
136
|
"list",
|
|
133
137
|
"sub-workflow",
|
|
134
138
|
"adjust-volume",
|
|
139
|
+
// Pitch & Tempo: audio in → audio out, video in → video out (picture
|
|
140
|
+
// copied). Dual-mode like adjust-volume; stays in AUDIO_PRODUCER_TYPES as
|
|
141
|
+
// its default.
|
|
142
|
+
"pitch-tempo",
|
|
135
143
|
// Dual-mode: audio in → audio out; video in → video out (+ revoiced audio).
|
|
136
144
|
// Listed here so canvas validators accept its output on BOTH audio and video
|
|
137
145
|
// input handles (it also stays in AUDIO_PRODUCER_TYPES as its default).
|
|
@@ -196,6 +204,7 @@ export const AUDIO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
|
|
|
196
204
|
"combine-audio",
|
|
197
205
|
"adjust-volume",
|
|
198
206
|
"audio-fx",
|
|
207
|
+
"pitch-tempo",
|
|
199
208
|
"reference-audio",
|
|
200
209
|
"audio-isolation",
|
|
201
210
|
"text-to-dialogue",
|
package/src/render-nodes.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* (by quality or otherwise — only its credit id changes), so the same key
|
|
16
16
|
* answers for `node.type` and for `jobs.job_type`.
|
|
17
17
|
*/
|
|
18
|
-
import { applyEdlCreditId, speakerViewCreditId } from "./credit-identifiers.js"
|
|
18
|
+
import { applyEdlCreditId, speakerViewCreditId, SPEAKER_VIEW_CREDIT_IDS } from "./credit-identifiers.js"
|
|
19
19
|
import type { RenderMedium } from "./render-output.js"
|
|
20
20
|
|
|
21
21
|
/** Where a render's player maps the output clock back to the master clock
|
|
@@ -46,8 +46,15 @@ export interface RenderNodeDescriptor {
|
|
|
46
46
|
/** The medium the render's order asks for (its node data, or its job's
|
|
47
47
|
* `input_data`) — before any output exists to say. */
|
|
48
48
|
readonly mediumOf: (data: Readonly<Record<string, unknown>>) => RenderMedium
|
|
49
|
-
/** The credit id a render
|
|
50
|
-
|
|
49
|
+
/** The credit id a render reserves on — a per-OUTPUT-MINUTE row: every
|
|
50
|
+
* render is charged its row × the minutes it renders. Chosen from the
|
|
51
|
+
* render's `quality` and `output` (as its node data or its job's request
|
|
52
|
+
* carries them) and, for a render priced in tiers, the `priceTier` the
|
|
53
|
+
* render rule judged it to be in (Speaker View's, decided 2026-10-10). A
|
|
54
|
+
* tiered render given no tier names its dearer row. */
|
|
55
|
+
readonly creditId: (quality: unknown, output?: unknown, priceTier?: unknown) => string
|
|
56
|
+
/** Every id `creditId` can name (each must have a price row). */
|
|
57
|
+
readonly creditIds: readonly string[]
|
|
51
58
|
readonly clockMapFrom: RenderClockSource
|
|
52
59
|
/** Listed in its owner's own views only, never in a public one (decided
|
|
53
60
|
* 2026-10-06): a Preview is private, and a public final would be exposure
|
|
@@ -68,12 +75,13 @@ type Data = Readonly<Record<string, unknown>>
|
|
|
68
75
|
const outputSettingMedium = (data: Data): RenderMedium => (data.output === "audio" ? "audio" : "video")
|
|
69
76
|
|
|
70
77
|
const descriptor = (d: RenderNodeDescriptor): RenderNodeDescriptor =>
|
|
71
|
-
Object.freeze({ ...d, transcriptOutput: Object.freeze({ ...d.transcriptOutput }) })
|
|
78
|
+
Object.freeze({ ...d, creditIds: Object.freeze([...d.creditIds]), transcriptOutput: Object.freeze({ ...d.transcriptOutput }) })
|
|
72
79
|
|
|
73
80
|
export const RENDER_NODE_TYPES: Readonly<Record<string, RenderNodeDescriptor>> = Object.freeze({
|
|
74
81
|
"apply-edl": descriptor({
|
|
75
82
|
mediumOf: outputSettingMedium,
|
|
76
83
|
creditId: (quality) => applyEdlCreditId(quality),
|
|
84
|
+
creditIds: ["apply-edl", "apply-edl:proxy"],
|
|
77
85
|
clockMapFrom: "input",
|
|
78
86
|
ownerOnlyListing: true,
|
|
79
87
|
latestBatch: true,
|
|
@@ -87,7 +95,8 @@ export const RENDER_NODE_TYPES: Readonly<Record<string, RenderNodeDescriptor>> =
|
|
|
87
95
|
// `transcript` pip (decided 2026-10-08) — what a caption step reads.
|
|
88
96
|
"speaker-view": descriptor({
|
|
89
97
|
mediumOf: () => "video",
|
|
90
|
-
creditId: (quality) => speakerViewCreditId(quality),
|
|
98
|
+
creditId: (quality, _output, priceTier) => speakerViewCreditId(quality, priceTier),
|
|
99
|
+
creditIds: SPEAKER_VIEW_CREDIT_IDS,
|
|
91
100
|
clockMapFrom: "output-json",
|
|
92
101
|
ownerOnlyListing: true,
|
|
93
102
|
latestBatch: true,
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Video Depth — the one contract every layer reads: which providers exist and
|
|
3
|
+
* which lane serves each, which optional levers a provider honours, how long a
|
|
4
|
+
* clip may be, and which price row a run is charged from.
|
|
5
|
+
*
|
|
6
|
+
* Colormaps: fal renders every `VIDEO_DEPTH_COLORMAPS` entry natively. The
|
|
7
|
+
* Replicate model's native output is inferno-colorized, so it offers only
|
|
8
|
+
* `inferno` (passed through as-is) and `grayscale`, which a worker ffmpeg pass
|
|
9
|
+
* produces from the inferno output (`videoDepthNeedsGrayscalePass`).
|
|
10
|
+
*
|
|
11
|
+
* Price rows are `model_pricing` rows (`<provider>:<n>s`); the credit amounts
|
|
12
|
+
* live there, never here. Worked examples (repeated in
|
|
13
|
+
* docs/nodes/processing-video/video-depth.md):
|
|
14
|
+
* 5 s → `:15s`, 15 s → `:15s`, 15.01 s → `:30s`, 61 s → `:120s`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const VIDEO_DEPTH_PROVIDERS = ["video-depth-anything", "depth-anything-frames"] as const
|
|
18
|
+
export type VideoDepthProvider = (typeof VIDEO_DEPTH_PROVIDERS)[number]
|
|
19
|
+
|
|
20
|
+
export const FAL_VIDEO_DEPTH_PROVIDERS: ReadonlySet<string> = new Set(["video-depth-anything"])
|
|
21
|
+
export const REPLICATE_VIDEO_DEPTH_PROVIDERS: ReadonlySet<string> = new Set(["depth-anything-frames"])
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The provider a run uses: `raw` when it is a Video Depth provider, else the
|
|
25
|
+
* default (the first entry). Raw workflow JSON or a FieldMapping can carry any
|
|
26
|
+
* value; the dispatch, the model deny and the price row all read this one
|
|
27
|
+
* resolution, so an unknown id never reaches a price row or slips the deny.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveVideoDepthProvider(raw: unknown): VideoDepthProvider {
|
|
30
|
+
return typeof raw === "string" && (VIDEO_DEPTH_PROVIDERS as readonly string[]).includes(raw)
|
|
31
|
+
? (raw as VideoDepthProvider)
|
|
32
|
+
: VIDEO_DEPTH_PROVIDERS[0]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const VIDEO_DEPTH_MODEL_SIZES = ["small", "base", "large"] as const
|
|
36
|
+
export type VideoDepthModelSize = (typeof VIDEO_DEPTH_MODEL_SIZES)[number]
|
|
37
|
+
|
|
38
|
+
/** The model size a run uses: `raw` when it is one, else `large` (the providers index lookup tables with it). */
|
|
39
|
+
export function resolveVideoDepthModelSize(raw: unknown): VideoDepthModelSize {
|
|
40
|
+
return typeof raw === "string" && (VIDEO_DEPTH_MODEL_SIZES as readonly string[]).includes(raw)
|
|
41
|
+
? (raw as VideoDepthModelSize)
|
|
42
|
+
: "large"
|
|
43
|
+
}
|
|
44
|
+
export const VIDEO_DEPTH_COLORMAPS = ["grayscale", "turbo", "inferno", "magma", "viridis"] as const
|
|
45
|
+
export type VideoDepthColormap = (typeof VIDEO_DEPTH_COLORMAPS)[number]
|
|
46
|
+
export const VIDEO_DEPTH_RESOLUTIONS = ["auto", "360p", "480p", "720p", "1080p"] as const
|
|
47
|
+
export type VideoDepthResolution = (typeof VIDEO_DEPTH_RESOLUTIONS)[number]
|
|
48
|
+
|
|
49
|
+
export type VideoDepthLever = "colormap" | "resolution" | "sideBySide"
|
|
50
|
+
const ALL_LEVERS: ReadonlySet<VideoDepthLever> = new Set(["colormap", "resolution", "sideBySide"])
|
|
51
|
+
const COLORMAP_ONLY: ReadonlySet<VideoDepthLever> = new Set(["colormap"])
|
|
52
|
+
const NO_LEVERS: ReadonlySet<VideoDepthLever> = new Set()
|
|
53
|
+
|
|
54
|
+
/** The optional levers `provider` honours. A lever absent here is dropped, never sent. */
|
|
55
|
+
export function videoDepthLevers(provider: string): ReadonlySet<VideoDepthLever> {
|
|
56
|
+
if (FAL_VIDEO_DEPTH_PROVIDERS.has(provider)) return ALL_LEVERS
|
|
57
|
+
if (REPLICATE_VIDEO_DEPTH_PROVIDERS.has(provider)) return COLORMAP_ONLY
|
|
58
|
+
return NO_LEVERS
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const REPLICATE_COLORMAPS: readonly VideoDepthColormap[] = ["grayscale", "inferno"]
|
|
62
|
+
|
|
63
|
+
/** The colormaps `provider` can deliver, in display order; empty when it has no colormap lever. */
|
|
64
|
+
export function videoDepthColormaps(provider: string): readonly VideoDepthColormap[] {
|
|
65
|
+
if (FAL_VIDEO_DEPTH_PROVIDERS.has(provider)) return VIDEO_DEPTH_COLORMAPS
|
|
66
|
+
if (REPLICATE_VIDEO_DEPTH_PROVIDERS.has(provider)) return REPLICATE_COLORMAPS
|
|
67
|
+
return []
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The colormap a run uses: the requested one when `provider` offers it, else `grayscale`; `undefined` when the provider has no colormap lever. Coerces, never throws. */
|
|
71
|
+
export function resolveVideoDepthColormap(provider: string, requested: unknown): VideoDepthColormap | undefined {
|
|
72
|
+
if (!videoDepthLevers(provider).has("colormap")) return undefined
|
|
73
|
+
const offered = videoDepthColormaps(provider)
|
|
74
|
+
return typeof requested === "string" && (offered as readonly string[]).includes(requested)
|
|
75
|
+
? (requested as VideoDepthColormap)
|
|
76
|
+
: "grayscale"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** True when the worker must turn the Replicate model's native inferno output into grayscale with ffmpeg. */
|
|
80
|
+
export function videoDepthNeedsGrayscalePass(provider: string, colormap: VideoDepthColormap | undefined): boolean {
|
|
81
|
+
return REPLICATE_VIDEO_DEPTH_PROVIDERS.has(provider) && resolveVideoDepthColormap(provider, colormap) === "grayscale"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const VIDEO_DEPTH_LIMITS = {
|
|
85
|
+
/** fal `max_frames` ceiling. */
|
|
86
|
+
FAL_MAX_FRAMES: 2400,
|
|
87
|
+
/** Longest clip the fal lane accepts, whatever its frame rate: the top price bucket (a low-fps clip under the frame limit can otherwise run past every price row). */
|
|
88
|
+
FAL_MAX_SECONDS: 300,
|
|
89
|
+
/** Frame rate assumed when the clip reports none (variable-rate or missing). */
|
|
90
|
+
ASSUMED_FPS: 30,
|
|
91
|
+
/** Longest clip the Replicate lane accepts. */
|
|
92
|
+
REPLICATE_MAX_SECONDS: 80,
|
|
93
|
+
} as const
|
|
94
|
+
|
|
95
|
+
const fmt = (n: number): string => n.toLocaleString("en-US")
|
|
96
|
+
|
|
97
|
+
/** Refuse a clip the provider cannot take — run BEFORE any credit reservation. */
|
|
98
|
+
export function checkVideoDepthLength(
|
|
99
|
+
provider: string,
|
|
100
|
+
probe: { durationSec: number; fps?: number },
|
|
101
|
+
): { ok: true } | { ok: false; message: string } {
|
|
102
|
+
if (REPLICATE_VIDEO_DEPTH_PROVIDERS.has(provider)) {
|
|
103
|
+
if (probe.durationSec <= VIDEO_DEPTH_LIMITS.REPLICATE_MAX_SECONDS) return { ok: true }
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
message: `Video is ${Math.ceil(probe.durationSec)} s. This provider accepts at most ${VIDEO_DEPTH_LIMITS.REPLICATE_MAX_SECONDS} s.`,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (probe.durationSec > VIDEO_DEPTH_LIMITS.FAL_MAX_SECONDS) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
message: `Video is ${Math.ceil(probe.durationSec)} s. This provider accepts at most ${VIDEO_DEPTH_LIMITS.FAL_MAX_SECONDS} s. Trim the clip and run again.`,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const assumed = !(typeof probe.fps === "number" && probe.fps > 0)
|
|
116
|
+
const fps = assumed ? VIDEO_DEPTH_LIMITS.ASSUMED_FPS : (probe.fps as number)
|
|
117
|
+
const frames = Math.ceil(probe.durationSec * fps - 1e-9)
|
|
118
|
+
if (frames <= VIDEO_DEPTH_LIMITS.FAL_MAX_FRAMES) return { ok: true }
|
|
119
|
+
const maxSec = Math.floor(VIDEO_DEPTH_LIMITS.FAL_MAX_FRAMES / fps)
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
message:
|
|
123
|
+
`Video is ${fmt(frames)} frames; the limit is ${fmt(VIDEO_DEPTH_LIMITS.FAL_MAX_FRAMES)} ` +
|
|
124
|
+
`(about ${maxSec} s at ${Math.round(fps)} fps${assumed ? ", assumed 30 fps because the clip reports no frame rate" : ""}). Trim the clip and run again.`,
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const VIDEO_DEPTH_BUCKETS = [15, 30, 60, 120, 300] as const
|
|
129
|
+
|
|
130
|
+
/** The longest clip `provider` accepts (`checkVideoDepthLength`); the fal limit for anything else. */
|
|
131
|
+
function videoDepthMaxSeconds(provider: string): number {
|
|
132
|
+
return REPLICATE_VIDEO_DEPTH_PROVIDERS.has(provider)
|
|
133
|
+
? VIDEO_DEPTH_LIMITS.REPLICATE_MAX_SECONDS
|
|
134
|
+
: VIDEO_DEPTH_LIMITS.FAL_MAX_SECONDS
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The price row for a clip of `durationSec`. Unknown, non-positive or longer
|
|
139
|
+
* than the provider accepts → the provider's highest REACHABLE row: the
|
|
140
|
+
* smallest bucket at or above its longest clip (Replicate 80 s → `:120s`,
|
|
141
|
+
* fal 300 s → `:300s`) — the most a run on it can be charged, never a row a
|
|
142
|
+
* run could not reach.
|
|
143
|
+
*/
|
|
144
|
+
export function videoDepthCreditId(provider: string, durationSec: number | null | undefined): string {
|
|
145
|
+
const top = VIDEO_DEPTH_BUCKETS[VIDEO_DEPTH_BUCKETS.length - 1]
|
|
146
|
+
const maxSec = videoDepthMaxSeconds(provider)
|
|
147
|
+
const reachableCeiling = VIDEO_DEPTH_BUCKETS.find((b) => b >= maxSec) ?? top
|
|
148
|
+
const known = typeof durationSec === "number" && Number.isFinite(durationSec) && durationSec > 0 && durationSec <= maxSec
|
|
149
|
+
const bucket = known ? (VIDEO_DEPTH_BUCKETS.find((b) => durationSec <= b) ?? top) : reachableCeiling
|
|
150
|
+
return `${provider}:${bucket}s`
|
|
151
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Video Mask — text-prompted video segmentation (SAM 3.1 / SAM 3). The wire contract of
|
|
3
|
+
* the `video-mask` node, `POST /v1/video-mask`, the `video_mask` MCP verb,
|
|
4
|
+
* `client.media.videoMask` and `nodaro media video-mask`, defined ONCE:
|
|
5
|
+
* - every bound the route schema, the node panel and the MCP verb read;
|
|
6
|
+
* - `videoMaskBilledSeconds`: the length a run is priced at — the clip's
|
|
7
|
+
* length at the 30 fps basis, so a 60 fps clip is priced at twice its
|
|
8
|
+
* length (the segmentation works per FRAME);
|
|
9
|
+
* - `videoMaskCreditId`: which price row (`model_pricing`) that length is
|
|
10
|
+
* charged from. The credit amounts live in the rows, never here.
|
|
11
|
+
*
|
|
12
|
+
* Worked examples (repeated in docs/nodes/ai-video/video-mask.md):
|
|
13
|
+
* 4 s at 30 fps → `sam-3.1-video:5s`, 12 s at 24 fps → `sam-3.1-video:15s`,
|
|
14
|
+
* 10 s at 60 fps (priced as 20 s) → `sam-3.1-video:30s`, 45 s at 30 fps → `sam-3.1-video:60s`,
|
|
15
|
+
* 100 s at 30 fps → `sam-3.1-video:120s`, 4 min at 30 fps on SAM 3 → `sam-3-video:240s`.
|
|
16
|
+
*
|
|
17
|
+
* Wire contract only — no I/O.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** Segmentation models a Video Mask run can use. SAM 3.1 (the default)
|
|
21
|
+
* tracks several objects in one pass and runs faster; SAM 3 costs half. */
|
|
22
|
+
export const VIDEO_MASK_PROVIDERS = ["sam-3.1", "sam-3"] as const
|
|
23
|
+
export type VideoMaskProvider = (typeof VIDEO_MASK_PROVIDERS)[number]
|
|
24
|
+
export const DEFAULT_VIDEO_MASK_PROVIDER: VideoMaskProvider = "sam-3.1"
|
|
25
|
+
|
|
26
|
+
/** A new Video Mask node's settings — spread into its node definition. */
|
|
27
|
+
export const VIDEO_MASK_DEFAULTS = {
|
|
28
|
+
threshold: 0.5,
|
|
29
|
+
provider: "sam-3.1" as VideoMaskProvider,
|
|
30
|
+
} as const
|
|
31
|
+
|
|
32
|
+
export const VIDEO_MASK_LIMITS = {
|
|
33
|
+
/** The longest input clip a run accepts, in seconds of PRICED length (see `videoMaskBilledSeconds`). */
|
|
34
|
+
MAX_BILLED_SEC: 300,
|
|
35
|
+
/** Frame rate the price rows assume. A faster clip is priced proportionally longer. */
|
|
36
|
+
FPS_BASIS: 30,
|
|
37
|
+
/** Subject description length cap. */
|
|
38
|
+
PROMPT_MAX_LENGTH: 500,
|
|
39
|
+
/** Detection confidence bounds (the model's own range, narrowed to useful values). */
|
|
40
|
+
THRESHOLD_MIN: 0.05,
|
|
41
|
+
THRESHOLD_MAX: 0.95,
|
|
42
|
+
THRESHOLD_STEP: 0.05,
|
|
43
|
+
/** Default detection confidence. Lower finds more (and less precise) regions. */
|
|
44
|
+
THRESHOLD_DEFAULT: VIDEO_MASK_DEFAULTS.threshold,
|
|
45
|
+
} as const
|
|
46
|
+
|
|
47
|
+
const VIDEO_MASK_BUCKETS_SEC = [5, 10, 15, 30, 60, 90, 120, 180, 240, 300] as const
|
|
48
|
+
|
|
49
|
+
/** Every price row a provider can be charged from, smallest first. */
|
|
50
|
+
export function videoMaskCreditIds(provider: VideoMaskProvider = DEFAULT_VIDEO_MASK_PROVIDER): string[] {
|
|
51
|
+
return VIDEO_MASK_BUCKETS_SEC.map((sec) => `${provider}-video:${sec}s`)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The length a clip is priced at: its duration at the 30 fps basis. A clip
|
|
56
|
+
* at or under 30 fps is priced at its own length; a 60 fps clip at twice it.
|
|
57
|
+
* An unknown frame rate counts as the basis.
|
|
58
|
+
*/
|
|
59
|
+
export function videoMaskBilledSeconds(durationSec: number, fps?: number | null): number {
|
|
60
|
+
const rate = typeof fps === "number" && Number.isFinite(fps) && fps > 0 ? fps : VIDEO_MASK_LIMITS.FPS_BASIS
|
|
61
|
+
return durationSec * Math.max(1, rate / VIDEO_MASK_LIMITS.FPS_BASIS)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The price row for a clip priced at `billedSec` seconds. An unknown or
|
|
66
|
+
* non-positive length prices the LONGEST row (a clip the route could not
|
|
67
|
+
* measure is refused, so this is only the pre-run quote for a clip whose
|
|
68
|
+
* length is not known yet); anything past the cap prices the last row.
|
|
69
|
+
*/
|
|
70
|
+
export function videoMaskCreditId(
|
|
71
|
+
billedSec: number | null | undefined,
|
|
72
|
+
provider: VideoMaskProvider = DEFAULT_VIDEO_MASK_PROVIDER,
|
|
73
|
+
): string {
|
|
74
|
+
const ids = videoMaskCreditIds(provider)
|
|
75
|
+
if (typeof billedSec !== "number" || !Number.isFinite(billedSec) || billedSec <= 0) return ids[ids.length - 1]!
|
|
76
|
+
const i = VIDEO_MASK_BUCKETS_SEC.findIndex((b) => billedSec <= b)
|
|
77
|
+
return ids[i === -1 ? ids.length - 1 : i]!
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Narrow an arbitrary value to a known provider, falling back to the default. */
|
|
81
|
+
export function resolveVideoMaskProvider(value: unknown): VideoMaskProvider {
|
|
82
|
+
return (VIDEO_MASK_PROVIDERS as readonly string[]).includes(value as string)
|
|
83
|
+
? (value as VideoMaskProvider)
|
|
84
|
+
: DEFAULT_VIDEO_MASK_PROVIDER
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `POST /v1/video-mask` request body. */
|
|
88
|
+
export interface VideoMaskRequest {
|
|
89
|
+
/** The clip to segment. */
|
|
90
|
+
readonly videoUrl: string
|
|
91
|
+
/** What to track: a short noun phrase; separate several with commas. */
|
|
92
|
+
readonly prompt: string
|
|
93
|
+
/** Detection confidence, `VIDEO_MASK_LIMITS.THRESHOLD_MIN`–`THRESHOLD_MAX` (default 0.5). */
|
|
94
|
+
readonly threshold?: number
|
|
95
|
+
readonly provider?: VideoMaskProvider
|
|
96
|
+
}
|