@uploadfilm/sdk 0.0.0-stage → 0.2.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.
Files changed (267) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +529 -2
  3. package/dist/ai/embed.d.ts +58 -0
  4. package/dist/ai/fake.d.ts +41 -0
  5. package/dist/ai/http.d.ts +17 -0
  6. package/dist/ai/index.d.ts +27 -0
  7. package/dist/ai/languages.d.ts +2 -0
  8. package/dist/ai/ollama.d.ts +23 -0
  9. package/dist/ai/openaiCompatible.d.ts +54 -0
  10. package/dist/ai/passages.d.ts +28 -0
  11. package/dist/ai/transcribe.d.ts +84 -0
  12. package/dist/ai/types.d.ts +141 -0
  13. package/dist/ai/usage.d.ts +66 -0
  14. package/dist/ai/whisperJson.d.ts +15 -0
  15. package/dist/ai/workersAi.d.ts +56 -0
  16. package/dist/ai.js +1 -0
  17. package/dist/ai.mjs +1 -0
  18. package/dist/cards/files.d.ts +91 -0
  19. package/dist/cards/index.d.ts +15 -0
  20. package/dist/cards/layouts.d.ts +121 -0
  21. package/dist/cards/probe.d.ts +69 -0
  22. package/dist/cards/proxies.d.ts +70 -0
  23. package/dist/cards/select.d.ts +68 -0
  24. package/dist/cards/volumes.d.ts +170 -0
  25. package/dist/cards/xml.d.ts +80 -0
  26. package/dist/cards.js +1 -0
  27. package/dist/cards.mjs +1 -0
  28. package/dist/copy/checksums.d.ts +66 -0
  29. package/dist/copy/engine.d.ts +24 -0
  30. package/dist/copy/errors.d.ts +109 -0
  31. package/dist/copy/index.d.ts +15 -0
  32. package/dist/copy/steps.d.ts +28 -0
  33. package/dist/copy/sweep.d.ts +24 -0
  34. package/dist/copy/types.d.ts +363 -0
  35. package/dist/embed/player.js +2 -0
  36. package/dist/host/adapters.d.ts +107 -0
  37. package/dist/host/detect.d.ts +68 -0
  38. package/dist/host/encoders.d.ts +34 -0
  39. package/dist/host/environment.d.ts +53 -0
  40. package/dist/host/index.d.ts +20 -0
  41. package/dist/host/linux.d.ts +94 -0
  42. package/dist/host/mac.d.ts +47 -0
  43. package/dist/host/network.d.ts +54 -0
  44. package/dist/host/node.d.ts +13 -0
  45. package/dist/host/policy.d.ts +101 -0
  46. package/dist/host/tuner.d.ts +48 -0
  47. package/dist/host/types.d.ts +118 -0
  48. package/dist/host-node.js +1 -0
  49. package/dist/host-node.mjs +1 -0
  50. package/dist/host.js +1 -0
  51. package/dist/host.mjs +1 -0
  52. package/dist/images/index.d.ts +11 -0
  53. package/dist/images/settings.d.ts +43 -0
  54. package/dist/images/types.d.ts +83 -0
  55. package/dist/images/url.d.ts +65 -0
  56. package/dist/index.d.ts +16 -0
  57. package/dist/index.js +1 -0
  58. package/dist/index.mjs +1 -0
  59. package/dist/player/adapters/hlsjs.d.ts +28 -0
  60. package/dist/player/bandwidthMemory.d.ts +28 -0
  61. package/dist/player/captions/index.d.ts +55 -0
  62. package/dist/player/embed/code.d.ts +195 -0
  63. package/dist/player/embed/constants.d.ts +4 -0
  64. package/dist/player/embed/controller.d.ts +62 -0
  65. package/dist/player/embed/element.d.ts +32 -0
  66. package/dist/player/embed/frame.d.ts +65 -0
  67. package/dist/player/embed/global.d.ts +14 -0
  68. package/dist/player/embed/index.d.ts +15 -0
  69. package/dist/player/embed/loader.d.ts +1 -0
  70. package/dist/player/embed/oembed.d.ts +74 -0
  71. package/dist/player/embed/protocol.d.ts +64 -0
  72. package/dist/player/engine.d.ts +215 -0
  73. package/dist/player/index.d.ts +18 -0
  74. package/dist/player/start.d.ts +62 -0
  75. package/dist/player/store.d.ts +10 -0
  76. package/dist/player/storyboard/index.d.ts +161 -0
  77. package/dist/player/stream.d.ts +206 -0
  78. package/dist/player/tracks.d.ts +41 -0
  79. package/dist/player.js +1 -0
  80. package/dist/player.mjs +1 -0
  81. package/dist/proxies/args.d.ts +19 -0
  82. package/dist/proxies/budget.d.ts +57 -0
  83. package/dist/proxies/camera.d.ts +104 -0
  84. package/dist/proxies/formats.d.ts +36 -0
  85. package/dist/proxies/index.d.ts +18 -0
  86. package/dist/proxies/jobs.d.ts +98 -0
  87. package/dist/proxies/node.d.ts +32 -0
  88. package/dist/proxies/plan.d.ts +89 -0
  89. package/dist/proxies/probe.d.ts +39 -0
  90. package/dist/proxies/render.d.ts +104 -0
  91. package/dist/proxies/safety.d.ts +45 -0
  92. package/dist/proxies/types.d.ts +83 -0
  93. package/dist/proxies/upload.d.ts +14 -0
  94. package/dist/react/BigPlay.d.ts +26 -0
  95. package/dist/react/Player.d.ts +58 -0
  96. package/dist/react/embed/index.d.ts +45 -0
  97. package/dist/react/examples/CustomControls.d.ts +8 -0
  98. package/dist/react/images/Image.d.ts +16 -0
  99. package/dist/react/images/index.d.ts +4 -0
  100. package/dist/react/images/useImage.d.ts +47 -0
  101. package/dist/react/index.d.ts +17 -0
  102. package/dist/react/storyboard/index.d.ts +58 -0
  103. package/dist/react/theme.d.ts +37 -0
  104. package/dist/react/useAdapterErrors.d.ts +8 -0
  105. package/dist/react/usePlaybackStart.d.ts +18 -0
  106. package/dist/react/usePlayer.d.ts +28 -0
  107. package/dist/react/useReducedMotion.d.ts +2 -0
  108. package/dist/react/useTimedTrack.d.ts +22 -0
  109. package/dist/react.js +1 -0
  110. package/dist/react.mjs +1 -0
  111. package/dist/server/auth/apiKeys.d.ts +30 -0
  112. package/dist/server/auth/cache.d.ts +21 -0
  113. package/dist/server/auth/deviceTokens.d.ts +38 -0
  114. package/dist/server/auth/envelope.d.ts +15 -0
  115. package/dist/server/auth/grants.d.ts +76 -0
  116. package/dist/server/auth/index.d.ts +19 -0
  117. package/dist/server/auth/jwt.d.ts +65 -0
  118. package/dist/server/auth/keyring.d.ts +31 -0
  119. package/dist/server/auth/kv.d.ts +12 -0
  120. package/dist/server/auth/repository.d.ts +45 -0
  121. package/dist/server/auth/revocations.d.ts +21 -0
  122. package/dist/server/auth/scope.d.ts +4 -0
  123. package/dist/server/auth/serviceAuth.d.ts +24 -0
  124. package/dist/server/auth/signedUrls.d.ts +28 -0
  125. package/dist/server/embed/index.d.ts +36 -0
  126. package/dist/server/embed/lifecycle.d.ts +53 -0
  127. package/dist/server/embed/playerScript.d.ts +4 -0
  128. package/dist/server/images/index.d.ts +15 -0
  129. package/dist/server/images/job.d.ts +80 -0
  130. package/dist/server/images/layout.d.ts +24 -0
  131. package/dist/server/images/params.d.ts +90 -0
  132. package/dist/server/images/route.d.ts +101 -0
  133. package/dist/server/images/sign.d.ts +55 -0
  134. package/dist/server/index.d.ts +42 -0
  135. package/dist/server/media/client.d.ts +99 -0
  136. package/dist/server/media/frameCheck.d.ts +62 -0
  137. package/dist/server/media/index.d.ts +10 -0
  138. package/dist/server/media/protocol.d.ts +556 -0
  139. package/dist/server/media/storyboard.d.ts +144 -0
  140. package/dist/server/media/transcript.d.ts +143 -0
  141. package/dist/server/pipeline/index.d.ts +12 -0
  142. package/dist/server/pipeline/match.d.ts +10 -0
  143. package/dist/server/pipeline/pipeline.d.ts +182 -0
  144. package/dist/server/pipeline/queues.d.ts +108 -0
  145. package/dist/server/pipeline/sources.d.ts +54 -0
  146. package/dist/server/r2/client.d.ts +164 -0
  147. package/dist/server/r2/crc32.d.ts +24 -0
  148. package/dist/server/r2/encoding.d.ts +35 -0
  149. package/dist/server/r2/errors.d.ts +9 -0
  150. package/dist/server/r2/integrity.d.ts +25 -0
  151. package/dist/server/r2/parts.d.ts +46 -0
  152. package/dist/server/r2/sign.d.ts +47 -0
  153. package/dist/server/redis/index.d.ts +39 -0
  154. package/dist/server/state/memory.d.ts +18 -0
  155. package/dist/server/state/r2.d.ts +73 -0
  156. package/dist/server/state/types.d.ts +57 -0
  157. package/dist/server/storage/chunked.d.ts +25 -0
  158. package/dist/server/storage/index.d.ts +12 -0
  159. package/dist/server/storage/r2.d.ts +96 -0
  160. package/dist/server/storage/s3.d.ts +144 -0
  161. package/dist/server/testing/fake-r2.d.ts +410 -0
  162. package/dist/server/testing/index.d.ts +10 -0
  163. package/dist/server/testing/kv-contract.d.ts +14 -0
  164. package/dist/server/transfer/handler.d.ts +217 -0
  165. package/dist/server/transfer/keys.d.ts +45 -0
  166. package/dist/server/transfer/protocol.d.ts +190 -0
  167. package/dist/server/zip/client.d.ts +32 -0
  168. package/dist/server/zip/generations.d.ts +83 -0
  169. package/dist/server/zip/index.d.ts +12 -0
  170. package/dist/server/zip/planner.d.ts +94 -0
  171. package/dist/server/zip/sign.d.ts +22 -0
  172. package/dist/server-media.js +1 -0
  173. package/dist/server-media.mjs +1 -0
  174. package/dist/server-redis.js +1 -0
  175. package/dist/server-redis.mjs +1 -0
  176. package/dist/server-testing.js +1 -0
  177. package/dist/server-testing.mjs +1 -0
  178. package/dist/server.js +1 -0
  179. package/dist/server.mjs +1 -0
  180. package/dist/storage/browserFile.d.ts +19 -0
  181. package/dist/storage/index.d.ts +12 -0
  182. package/dist/storage/local.d.ts +9 -0
  183. package/dist/storage/presigned.d.ts +22 -0
  184. package/dist/sync/ffmpeg.d.ts +44 -0
  185. package/dist/sync/index.d.ts +17 -0
  186. package/dist/sync/match.d.ts +28 -0
  187. package/dist/sync/probe.d.ts +30 -0
  188. package/dist/sync/timecode.d.ts +50 -0
  189. package/dist/sync/transcript.d.ts +35 -0
  190. package/dist/sync/types.d.ts +172 -0
  191. package/dist/sync/waveform.d.ts +89 -0
  192. package/dist/sync.js +1 -0
  193. package/dist/sync.mjs +1 -0
  194. package/dist/transfer/claims.d.ts +41 -0
  195. package/dist/transfer/client.d.ts +267 -0
  196. package/dist/transfer/download.d.ts +192 -0
  197. package/dist/transfer/engine.d.ts +402 -0
  198. package/dist/transfer/errors.d.ts +50 -0
  199. package/dist/transfer/growing/bytes.d.ts +17 -0
  200. package/dist/transfer/growing/index.d.ts +12 -0
  201. package/dist/transfer/growing/parts.d.ts +157 -0
  202. package/dist/transfer/growing/retry.d.ts +38 -0
  203. package/dist/transfer/growing/store.d.ts +66 -0
  204. package/dist/transfer/growing/upload.d.ts +126 -0
  205. package/dist/transfer/index.d.ts +40 -0
  206. package/dist/transfer/integrity.d.ts +93 -0
  207. package/dist/transfer/limits.d.ts +34 -0
  208. package/dist/transfer/node.d.ts +63 -0
  209. package/dist/transfer/pool.d.ts +83 -0
  210. package/dist/transfer/protocol.d.ts +172 -0
  211. package/dist/transfer/signer.d.ts +29 -0
  212. package/dist/transfer/storage.d.ts +135 -0
  213. package/dist/transfer/timing.d.ts +132 -0
  214. package/dist/transfer/transports/electronNet.d.ts +62 -0
  215. package/dist/transfer/transports/fetch.d.ts +15 -0
  216. package/dist/transfer/transports/retryAfter.d.ts +12 -0
  217. package/dist/transfer/transports/undici.d.ts +72 -0
  218. package/dist/transfer/tuner.d.ts +56 -0
  219. package/dist/workers/cli.mjs +115 -0
  220. package/dist/workers/media/config.mjs +53 -0
  221. package/dist/workers/media/container/Dockerfile +19 -0
  222. package/dist/workers/media/container/FFMPEG.md +129 -0
  223. package/dist/workers/media/container/runner.mjs +2690 -0
  224. package/dist/workers/media/index.mjs +1011 -0
  225. package/dist/workers/media/init/config.ts +52 -0
  226. package/dist/workers/media/init/worker.ts +8 -0
  227. package/dist/workers/media/init/wrangler.toml +44 -0
  228. package/dist/workers/media/runner.mjs +2656 -0
  229. package/dist/workers/media/types/build/entry/config.d.mts +6 -0
  230. package/dist/workers/media/types/build/entry/index.d.mts +43 -0
  231. package/dist/workers/media/types/build/entry/program.d.mts +13 -0
  232. package/dist/workers/media/types/build/entry/runner.d.mts +12 -0
  233. package/dist/workers/media/types/build/entry/settings.d.mts +40 -0
  234. package/dist/workers/media/types/src/config.d.mts +135 -0
  235. package/dist/workers/media/types/src/jobs.d.mts +73 -0
  236. package/dist/workers/media/types/src/runner/container.d.mts +32 -0
  237. package/dist/workers/media/types/src/runner/ffmpeg.d.mts +227 -0
  238. package/dist/workers/media/types/src/runner/job.d.mts +107 -0
  239. package/dist/workers/media/types/src/runner/node.d.mts +71 -0
  240. package/dist/workers/media/types/src/runner/plugins.d.mts +45 -0
  241. package/dist/workers/media/types/src/serve.d.mts +107 -0
  242. package/dist/workers/media/types/src/steps/audio.d.mts +33 -0
  243. package/dist/workers/media/types/src/steps/edit.d.mts +62 -0
  244. package/dist/workers/media/types/src/steps/frameCheck.d.mts +44 -0
  245. package/dist/workers/media/types/src/steps/gate.d.mts +18 -0
  246. package/dist/workers/media/types/src/steps/paths.d.mts +1 -0
  247. package/dist/workers/media/types/src/steps/prep.d.mts +60 -0
  248. package/dist/workers/media/types/src/steps/render.d.mts +40 -0
  249. package/dist/workers/media/types/src/steps/runner.d.mts +30 -0
  250. package/dist/workers/media/types/src/steps/transcribe.d.mts +89 -0
  251. package/dist/workers/media/types/src/storyboard/index.d.mts +61 -0
  252. package/dist/workers/media/types/src/transcoder.d.mts +30 -0
  253. package/dist/workers/media/types/src/worker.d.mts +30 -0
  254. package/dist/workers/zip/index.mjs +589 -0
  255. package/dist/workers/zip/init/config.ts +22 -0
  256. package/dist/workers/zip/init/worker.ts +5 -0
  257. package/dist/workers/zip/init/wrangler.toml +25 -0
  258. package/dist/workers/zip/types/build/entry/index.d.mts +5 -0
  259. package/dist/workers/zip/types/src/config.d.mts +35 -0
  260. package/dist/workers/zip/types/src/serve.d.mts +86 -0
  261. package/dist/workers/zip/types/src/worker.d.mts +12 -0
  262. package/dist/zip/index.d.ts +13 -0
  263. package/dist/zip/layout.d.ts +129 -0
  264. package/dist/zip/names.d.ts +34 -0
  265. package/dist/zip/plan.d.ts +115 -0
  266. package/dist/zip/sw.d.ts +7 -0
  267. package/package.json +313 -4
@@ -0,0 +1,107 @@
1
+ import { type LadderSettings, type RenderJob, type RunnerStatus, type Step, type StepSettings } from "@uploadfilm/sdk/server/media";
2
+ import { type DecoderPlugin } from "./plugins.mjs";
3
+ export interface RunSpec {
4
+ sourceBytes: number;
5
+ maxShort?: number;
6
+ steps: Step[];
7
+ ladder: LadderSettings;
8
+ plugins?: readonly DecoderPlugin[];
9
+ /** The optional steps' settings (audio, transcript, frame-check). Default DEFAULT_STEP_SETTINGS. */
10
+ stepSettings?: StepSettings;
11
+ /**
12
+ * Seconds the source is known to last (the job's expectDurationS): the done check measures the outputs against the
13
+ * longer of this and the header's duration, so a file cut short whose header has no duration (a MediaRecorder WebM)
14
+ * is refused too.
15
+ */
16
+ expectDurationS?: number;
17
+ /** A `render` job's sources and edit list (src/steps/render.ts). */
18
+ render?: RenderJob;
19
+ }
20
+ /** A process run; resolves with stdout (unless onStdout takes it), rejects with the tail of stderr. */
21
+ export type Exec = (cmd: string, args: string[], o?: {
22
+ onStdout?: (s: string) => void;
23
+ stdinFrom?: {
24
+ cmd: string;
25
+ args: string[];
26
+ };
27
+ /** ffmpeg may stop reading before the decoder is done (a poster alone needs one frame): not a failure then. */
28
+ earlyStopOk?: boolean;
29
+ /** Sees ffmpeg's stderr as it comes (the frame check's decoder errors). */
30
+ onStderr?: (s: string) => void;
31
+ /** Killed (and failed: "took longer than") past this many ms. Absent: no limit (every job but prep and render). */
32
+ timeoutMs?: number;
33
+ }) => Promise<string>;
34
+ export interface RunIO {
35
+ workDir: string;
36
+ /** Write the source to `dest`, calling onBytes as it arrives. */
37
+ download(dest: string, onBytes: (n: number) => void): Promise<void>;
38
+ /** A render's source `i` (its sources[i]) to `dest`. Only a render job calls it. */
39
+ downloadSource?(i: number, dest: string, onBytes: (n: number) => void): Promise<void>;
40
+ /** Store one output (rel: its name under the job's prefix). */
41
+ upload(rel: string, file: string): Promise<void>;
42
+ exec?: Exec;
43
+ ffmpeg?: string;
44
+ ffprobe?: string;
45
+ /** Parallel uploads (default 4). */
46
+ uploads?: number;
47
+ /** Free bytes on the work disk (default: statfs of workDir). Tests. */
48
+ freeBytes?: (dir: string) => number;
49
+ }
50
+ /** Free bytes for an unprivileged writer on the disk holding `dir`; Infinity when it can't be told. */
51
+ export declare function freeBytesOf(dir: string): number;
52
+ /** An error with the runner's reason code (protocol RunnerStatus.code). */
53
+ export declare class JobError extends Error {
54
+ code: RunnerStatus["code"];
55
+ constructor(message: string, code: RunnerStatus["code"]);
56
+ }
57
+ export declare const spawnExec: Exec;
58
+ /**
59
+ * A fragmented MP4/MOV: a movie fragment (moof) among the file's first top-level boxes. Only the box headers are read
60
+ * (8 or 16 bytes each, a few reads). Hand-rolled because ffprobe doesn't say whether a file is fragmented, and these
61
+ * files need the packet index to know where the picture ends (withPacketEnd: FFmpeg 7.1 reads their header a fragment
62
+ * short). An ordinary MP4 (ftyp, mdat, moov) and anything that isn't ISO-BMFF answer false; a file with more boxes
63
+ * than the budget answers true (only costs the scan).
64
+ */
65
+ export declare function isFragmentedMp4(path: string, maxBoxes?: number): boolean;
66
+ /**
67
+ * How much shorter than the source's own length an output may be: a stream ending a little before the container's
68
+ * duration (audio running past the last picture) is normal; a cut-off source is not. 1 % or 1.5 s, whichever is more.
69
+ */
70
+ export declare const shortfallAllowed: (duration: number) => number;
71
+ /** A VFR stream with a gap between two frames longer than this (seconds) has a still stretch: its rungs are filled. */
72
+ export declare const STILL_GAP = 0.25;
73
+ /**
74
+ * An ffmpeg failure whose cause is the source's format, not a fault: no decoder, no codec tag, no zimg for HDR…
75
+ * → "unsupported" with what it was. null: not one of those (left as it is).
76
+ */
77
+ export declare function unsupportedReason(stderr: string): string | null;
78
+ /**
79
+ * The general "done" invariant for a ladder: the master lists every rung, every rung's playlist has at least one
80
+ * segment (each one there, with its init segment), and covers the picture. FFmpeg exits 0 with a master that lists no
81
+ * variant (UPSTREAM.md U1) or a rung cut short (U2): never a "done" for that. Returns what's wrong, or null.
82
+ */
83
+ export declare function ladderProblem(out: string, rungs: number, pictureS: number): string | null;
84
+ /**
85
+ * The master playlist, written by the runner when FFmpeg's lists fewer variants than the ladder has (FFmpeg writes a
86
+ * master with NO variant when a variant is one segment: a clip under ~1 s, exit status 0; UPSTREAM.md U1). Written the
87
+ * way FFmpeg writes it: each rung's peak and average bandwidth (from its segments), size and codecs. No library writes
88
+ * an HLS master for us here (FFmpeg is that library, and this is its bug); the format is RFC 8216 §4.3.4.2.
89
+ * false: a rung's playlist or init segment isn't there (the done check refuses that ladder).
90
+ */
91
+ export declare function writeMaster(out: string, rungs: readonly {
92
+ width: number;
93
+ height: number;
94
+ }[], hasAudio: boolean): boolean;
95
+ /**
96
+ * Run the job. `onStatus` sees every change (the container serves it at GET /status). Resolves with the final "done"
97
+ * status; rejects (a JobError when the reason is known) on failure. The work directory is removed either way.
98
+ */
99
+ /**
100
+ * Does this process decode the source's frames? ffmpeg with a filter graph (scaled rungs, poster, storyboard), a decoder
101
+ * plugin, or ffprobe reading frames (-show_frames, -skip_frame: the old keyframe scan). Header probes, the packet index
102
+ * and stream copies don't.
103
+ */
104
+ export declare function decodesFrames(cmd: string, args: string[], o?: {
105
+ stdinFrom?: unknown;
106
+ }): boolean;
107
+ export declare function runJob(spec: RunSpec, io: RunIO, onStatus?: (st: RunnerStatus) => void): Promise<RunnerStatus>;
@@ -0,0 +1,71 @@
1
+ import { type LadderSettings, type RenderJob, type RunnerStatus, type Step, type StepSettings } from "@uploadfilm/sdk/server/media";
2
+ import { type Exec } from "./job.mjs";
3
+ import type { DecoderPlugin } from "./plugins.mjs";
4
+ import type { Transcriber } from "@uploadfilm/sdk/ai";
5
+ import type { RunnerSettings } from "@uploadfilm/sdk/host";
6
+ /** The part of the host's RunnerSettings the runner applies (encoder/api are the ladder's business, see above). */
7
+ export type RunnerHostSettings = Pick<RunnerSettings, "concurrency" | "threads" | "nice"> & Partial<RunnerSettings>;
8
+ export interface PulledJob {
9
+ id: string;
10
+ store: string;
11
+ sourceBytes: number;
12
+ maxShort?: number;
13
+ steps?: Step[];
14
+ /** Seconds the source is known to last (JobRequest.expectDurationS). */
15
+ expectDurationS?: number;
16
+ /** A render job's sources (GET <store>/source/<i>) and edit list (JobRequest.render). */
17
+ render?: RenderJob;
18
+ }
19
+ export interface PullOptions {
20
+ queue: string;
21
+ token?: string;
22
+ ladder: LadderSettings;
23
+ /** The optional steps' settings (audio, frame-check; a transcript is the queue host's, see src/steps/transcribe.ts). */
24
+ stepSettings?: StepSettings;
25
+ defaultSteps?: Step[];
26
+ plugins?: readonly DecoderPlugin[];
27
+ workDir?: string;
28
+ /** Stop after one job (or none waiting). */
29
+ once?: boolean;
30
+ /** Wait between polls when the queue is empty (default 5 s). */
31
+ idleMs?: number;
32
+ signal?: AbortSignal;
33
+ log?: (s: string) => void;
34
+ retryBaseMs?: number;
35
+ /** Makes the transcript of jobs with the `transcript` step (see above). */
36
+ transcriber?: Transcriber;
37
+ /** How hard to drive this machine (see above); a function is read before each job. Absent: as before. */
38
+ host?: RunnerHostSettings | (() => RunnerHostSettings);
39
+ /** The process runner the jobs use (default spawnExec); `host` wraps it. */
40
+ exec?: Exec;
41
+ }
42
+ /**
43
+ * ffmpeg arguments with every thread pool bounded to `n`: the filter graphs (global -filter_threads,
44
+ * -filter_complex_threads), the first input's decoder (-threads before its -i) and each encoded video stream
45
+ * (-threads:v:<i> after its -c:v:<i>; x264 otherwise sizes its own to every core). Arguments that already set threads
46
+ * are left as they are.
47
+ */
48
+ export declare function boundThreads(args: readonly string[], n: number): string[];
49
+ /**
50
+ * The jobs' process runner under host settings: ffmpeg with bounded threads, every process (and a decoder plugin's
51
+ * feeder) under `nice -n <nice>` on POSIX. An error names the program that failed, not `nice`.
52
+ */
53
+ export declare function hostExec(base: Exec, s: Pick<RunnerHostSettings, "threads" | "nice">, o?: {
54
+ ffmpeg?: string;
55
+ platform?: string;
56
+ }): Exec;
57
+ /** A finished job's result, with how its transcript went (jobs with the step, on a runner with a transcriber). */
58
+ export type PulledResult = RunnerStatus & {
59
+ transcript?: {
60
+ state: "done" | "error";
61
+ reason?: string;
62
+ };
63
+ };
64
+ /** Pull and run jobs until stopped. → how many jobs ran. */
65
+ export declare function pullLoop(o: PullOptions): Promise<number>;
66
+ /**
67
+ * The settings version the runner stamps when started without --version / MEDIA_VERSION: the template's default
68
+ * (template/config.ts VERSION), so a runner next to an unedited template makes outputs that Worker accepts. Change both
69
+ * together (test/templateVersion.test.ts). 2: the format lab's runner fixes (F1–F11).
70
+ */
71
+ export declare const RUNNER_DEFAULT_VERSION = "360-720-1080/2";
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Decoder plugins: how a format FFmpeg can't decode (a vendor's camera RAW: BRAW, R3D, ARRIRAW, Canon Cinema RAW
3
+ * Light …) gets a ladder anyway, without the vendor's SDK ever being in the core image.
4
+ *
5
+ * A plugin claims a source by its signature (its first bytes, and what ffprobe made of it), and decodes it ONCE into a
6
+ * stream FFmpeg reads on stdin (raw frames, or NUT/Y4M). That stream feeds the same single-pass FFmpeg run every other
7
+ * job uses, so a plugin job is still one decode (the plugin's) and one encode pass.
8
+ *
9
+ * Plugins live in their own optional packages and container layers (sdks/media-plugins/<vendor>): vendor licences
10
+ * decide what may be bundled. Without a plugin, a RAW source fails with code "unsupported" (stored, flagged "no
11
+ * preview"), never a half-made ladder.
12
+ */
13
+ import type { Probe } from "./ffmpeg.mjs";
14
+ /** What a plugin sees to decide whether a source is its own. */
15
+ export interface SourceSignature {
16
+ /** The source's first bytes (at least 64, fewer only for a shorter file). */
17
+ head: Uint8Array;
18
+ /** ffprobe's reading of it; null when FFmpeg couldn't read it at all. */
19
+ ffprobe: Probe | null;
20
+ sourceBytes: number;
21
+ }
22
+ /** The decoded stream a plugin produces. */
23
+ export interface DecodedSource {
24
+ /** The decoder process: it writes the stream to stdout. */
25
+ command: string;
26
+ args: string[];
27
+ /** FFmpeg's input options for that stream, e.g. ["-f", "rawvideo", "-pix_fmt", "yuv420p", "-s", "1920x1080", "-r", "24"]. */
28
+ inputArgs: string[];
29
+ /** The picture as it is shown (a plugin turns rotated footage itself), as read from the source's header. */
30
+ width: number;
31
+ height: number;
32
+ /** Seconds, 0 when unknown. */
33
+ duration: number;
34
+ }
35
+ export interface DecoderPlugin {
36
+ /** Shown in logs and timings. */
37
+ name: string;
38
+ claims(sig: SourceSignature): boolean;
39
+ /** Read the source's header and say how to decode it. Throws when the source is damaged. */
40
+ open(path: string, sig: SourceSignature): Promise<DecodedSource>;
41
+ }
42
+ /** The first plugin that claims the source (plugins are tried in order; a claim that throws is no claim). */
43
+ export declare function pickPlugin(plugins: readonly DecoderPlugin[] | undefined, sig: SourceSignature): DecoderPlugin | null;
44
+ /** A Probe for a plugin's decoded stream: raw frames, so the top rung is never a copy and keyframes don't matter. */
45
+ export declare function probeOfDecoded(d: DecodedSource): Probe;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * What viewers get from the media Worker, independent of the runtime (src/worker.ts runs it in workerd with the R2
3
+ * binding and the edge cache; tests run it in Node with fakes).
4
+ *
5
+ * GET|HEAD /h/<token>/<rel> an output file (master.m3u8, v<i>/index.m3u8, v<i>/init_<i>.mp4, v<i>/<seg>-N.m4s, …)
6
+ *
7
+ * The token is a sealed grant (the auth kit's grantSealer, the product's policy): encrypted, so its path never shows;
8
+ * it expires. Before any byte goes out (cached or not) the Worker checks the outputs are still there (their completion
9
+ * file), and for a grant naming a `copy` that the copy is still there: deleting either stops playback within
10
+ * liveTtlMs, even for tokens already handed out. Playlists use relative names, so one token in the path covers every
11
+ * file.
12
+ *
13
+ * The edge cache is keyed by the file and by the build it belongs to: the R2 version of the kind's completion file (a
14
+ * new one on every write; the encoder uploads it last). Outputs dropped and rebuilt at the same prefix (a file deleted
15
+ * then restored, a preview re-made) get new keys, so the old build's playlists, whose segments are gone, are never
16
+ * served for them. Purging instead wouldn't do: caches.default.delete clears one data centre. The build travels in the
17
+ * URLs: the playlists served name it on every URI (?b=), so the files a player asks for next are of the build its
18
+ * playlist was, whichever isolate (with whatever liveTtlMs view) answers them. (Ported from UploadFilm main e566a9b.)
19
+ * Left: a browser that still holds an old master in its HTTP cache under the same token URL plays the old build's
20
+ * names; the player's recovery asks the site for a fresh URL.
21
+ *
22
+ * Ranges (RFC 9110 §14): a GET with one `bytes=` range gets 206 + Content-Range (Safari plays a progressive MP4 only from
23
+ * a server that answers ranges, and every browser seeks past its buffer with them); If-Range with the file's strong
24
+ * ETag keeps the range, anything else (another ETag, a date: no Last-Modified here) gets the whole file; a range that
25
+ * starts past the end gets 416. Several ranges at once get the whole file (allowed, and nothing needs them). The
26
+ * grant and "still there" checks come first, exactly as for a whole file.
27
+ */
28
+ import { type OutputKind } from "@uploadfilm/sdk/server/media";
29
+ import { type MediaWorkerConfig } from "./config.mjs";
30
+ export interface ObjLike {
31
+ /** The whole object's size (also for a ranged read, as R2's binding reports it). */
32
+ size: number;
33
+ etag: string;
34
+ /** R2's id of this write (R2Object.version): a new one each time the object is written, even with the same bytes. */
35
+ version?: string;
36
+ body: ReadableStream<Uint8Array> | null;
37
+ /** The bytes `body` holds when the read was ranged (R2's binding sets it). Absent: the body is cut here. */
38
+ range?: {
39
+ offset?: number;
40
+ length?: number;
41
+ };
42
+ }
43
+ export interface BucketLike {
44
+ /**
45
+ * `range`: only these bytes (R2's binding takes the same option). A bucket that honours it must say so in the
46
+ * object's `range` (R2's does); one that ignores it (no `range` on the object) still works: the body is cut here.
47
+ */
48
+ get(key: string, options?: {
49
+ range: {
50
+ offset: number;
51
+ length: number;
52
+ };
53
+ }): Promise<ObjLike | null>;
54
+ head(key: string): Promise<{
55
+ size: number;
56
+ etag: string;
57
+ version?: string;
58
+ } | null>;
59
+ }
60
+ export interface CacheLike {
61
+ match(key: Request): Promise<Response | undefined>;
62
+ put(key: Request, res: Response): Promise<void>;
63
+ }
64
+ export interface ViewerEnv {
65
+ bucket: BucketLike;
66
+ secret: string;
67
+ /** Prepended to every key (a shared test bucket); "" in production. */
68
+ keyPrefix?: string;
69
+ }
70
+ export interface ServeOptions {
71
+ now?: () => number;
72
+ cache?: CacheLike | null;
73
+ /** Keep a cache write alive after the response (workerd: ctx.waitUntil). */
74
+ waitUntil?: (p: Promise<unknown>) => void;
75
+ }
76
+ /** A single byte range of a file `size` long: inclusive start and end. */
77
+ export interface ByteRange {
78
+ start: number;
79
+ end: number;
80
+ }
81
+ /**
82
+ * The Range header of a GET, against a file `size` bytes long (RFC 9110 §14.1.2):
83
+ * - null: no usable range, send the whole file (absent, not `bytes=`, malformed, or several ranges);
84
+ * - "unsatisfiable": a valid range that starts past the end (or a zero-length suffix): 416;
85
+ * - a range, clamped to the file.
86
+ */
87
+ export declare function parseRange(header: string | null, size: number): ByteRange | "unsatisfiable" | null;
88
+ /**
89
+ * Whether an If-Range lets the range through: only a strong ETag equal to the file's (RFC 9110 §13.1.5). A date never
90
+ * does (these answers carry no Last-Modified), nor a weak ETag.
91
+ */
92
+ export declare const ifRangeHolds: (header: string | null, etag: string) => boolean;
93
+ /** A playlist with `?b=<build>` on every URI it names (variant playlists, EXT-X-MAP, segments). */
94
+ export declare function withBuild(playlist: string, b: string): string;
95
+ export interface Viewer {
96
+ serve(req: Request, env: ViewerEnv, o?: ServeOptions): Promise<Response>;
97
+ /** Forget every "still there" answer (tests). */
98
+ resetLive(): void;
99
+ }
100
+ /**
101
+ * The transcript step writes the source's audio in chunks (audio/a-NNN.ogg) and their index (audio/audio.json) next to
102
+ * transcript.vtt and transcript.json. Before, serving the transcript served that audio too, to anyone with a grant for
103
+ * the captions (ClipMe adoption, gap 14). Now the audio files are served only when the product serves the "audio" step
104
+ * itself (lists it in serve.steps). transcript.json is the transcript's own data: served with "transcript".
105
+ */
106
+ export declare function servedKind(kind: OutputKind, steps: readonly string[]): boolean;
107
+ export declare function createViewer(cfg: Pick<MediaWorkerConfig, "grants" | "serve" | "ladder">): Viewer;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The `audio` step, container side: the filter branch and outputs that turn the source's first audio stream into Opus
3
+ * mono 16 kHz chunks (audio/a-NNN.ogg) on the job's one decode, with silence measured on the way (silencedetect →
4
+ * ametadata files), and the index (audio/audio.json) built from what FFmpeg wrote. Pure; src/runner runs it.
5
+ */
6
+ import { AUDIO_INDEX, type StepSettings } from "@uploadfilm/sdk/server/media";
7
+ import type { AudioChunk, AudioIndex, Silence } from "@uploadfilm/sdk/server/media";
8
+ export declare const AUDIO_RATE = 16000;
9
+ /** Work files the audio branch writes besides its chunks (never uploaded). */
10
+ export declare const audioWork: (work: string) => {
11
+ silenceStart: string;
12
+ silenceEnd: string;
13
+ list: string;
14
+ };
15
+ /**
16
+ * The filter chain (one entry of -filter_complex): the first audio stream, mono 16 kHz, silence measured, → [aud].
17
+ * Padded from the source's time 0 (first_pts=0, async: gaps filled too), so audio that starts late, or has holes, keeps
18
+ * the picture's timeline: chunk times, silences and captions all line up with the video.
19
+ */
20
+ export declare function audioFilter(work: string, s: StepSettings, input?: string): string;
21
+ /** The chunk outputs: Opus in Ogg, cut every chunkS seconds, each starting at 0, with a list of where each one starts. */
22
+ export declare function audioOutputArgs(out: string, work: string, s: StepSettings): string[];
23
+ /** ametadata's print files → silences. A silence still open at the end runs to `seconds`. */
24
+ export declare function parseSilences(startTxt: string, endTxt: string, seconds: number): Silence[];
25
+ /** The segment muxer's csv list (`a-000.ogg,0.000000,600.010000`) → chunks under audio/. */
26
+ export declare function parseChunkList(csv: string): AudioChunk[];
27
+ export declare function audioIndex(o: {
28
+ hasAudio: boolean;
29
+ chunks: AudioChunk[];
30
+ silences: Silence[];
31
+ seconds: number;
32
+ }, s: StepSettings): AudioIndex;
33
+ export { AUDIO_INDEX };
@@ -0,0 +1,62 @@
1
+ import type { RunnerStatus } from "@uploadfilm/sdk/server/media";
2
+ import { type Exec } from "../runner/job.mjs";
3
+ import { type Probe } from "../runner/ffmpeg.mjs";
4
+ /** What runJob hands an editor step: its counted exec and the tools' paths. */
5
+ export interface EditCtx {
6
+ exec: Exec;
7
+ ffmpeg: string;
8
+ ffprobe: string;
9
+ /** Processes run so far, and how many decoded frames (runJob counts them). */
10
+ counts(): {
11
+ decodes: number;
12
+ processes: number;
13
+ };
14
+ }
15
+ /** The demuxer a source is read with, from its first bytes; null: not a container either step reads. */
16
+ export type Demuxer = "mov" | "matroska";
17
+ /**
18
+ * The demuxer for these first bytes: ISO BMFF or QuickTime (MP4, MOV, M4V, 3GP: a known first box with a sane size)
19
+ * or EBML (Matroska, WebM). Anything else is refused before FFmpeg sees it: FFmpeg probes many formats (playlists,
20
+ * image sequences, concat lists…) that a source must never be read as.
21
+ */
22
+ export declare function demuxerOf(head: Uint8Array): Demuxer | null;
23
+ export declare function readHead(path: string, n?: number): Uint8Array;
24
+ /** Input options for a source: its demuxer forced, local files only (no URL or data reference followed). */
25
+ export declare const sourceInput: (path: string, d: Demuxer) => string[];
26
+ /** The source's header, read with its demuxer forced. Not a video: "unsupported" with why. */
27
+ export declare function probeSource(ctx: EditCtx, path: string, what?: string): Promise<{
28
+ probe: Probe;
29
+ demuxer: Demuxer;
30
+ fps: number;
31
+ }>;
32
+ /** The picture's nominal rate (frames a second): its average rate, else its base rate, else 30. */
33
+ export declare function nominalFps(json: string, video: number): number;
34
+ /** One stream's packets, from the container's index (nothing decoded): how many, and where the last one ends (s). */
35
+ export declare function packetSpan(ctx: EditCtx, path: string, d: Demuxer, stream: string): Promise<{
36
+ count: number;
37
+ start: number;
38
+ end: number;
39
+ durations: number;
40
+ }>;
41
+ /** Free bytes check, before anything is downloaded. */
42
+ export declare function needDisk(need: number, free: number): void;
43
+ /** Every file under `dir`, relative. */
44
+ export declare function listFiles(dir: string, base?: string): string[];
45
+ export declare const sizeOf: (f: string) => number;
46
+ /** A status updater with timings by phase (seconds), like runJob's. */
47
+ export declare function phases(onStatus: (st: RunnerStatus) => void): {
48
+ st: RunnerStatus;
49
+ emit: () => void;
50
+ /** Close the current phase (its seconds into the timings) and start the next. */
51
+ next(name: string, phase?: string): void;
52
+ };
53
+ /** Append `from` to `to` in 1 MiB chunks (never the whole file in memory). */
54
+ export declare function appendFile(to: string, from: string): void;
55
+ /** A failure because the work disk is full (FFmpeg's message, or Node's ENOSPC). */
56
+ export declare const isDiskFull: (e: unknown) => boolean;
57
+ /**
58
+ * Is there a movie fragment (moof) among the file's top-level boxes? Only the box headers are read. Unlike the
59
+ * runner's isFragmentedMp4, a scan that runs out of budget answers false: "edit-ready" needs proof, not a maybe.
60
+ * (Hand-rolled for the same reason as that one: ffprobe doesn't say whether a file is fragmented.)
61
+ */
62
+ export declare function hasMoof(path: string, maxBoxes?: number): boolean;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The `frame-check` step, container side: one more branch of the job's one decode, scaled to a 16×16 grey thumbnail,
3
+ * whose every frame's timestamp is printed by the `metadata` filter (in the filter graph: before any muxer could
4
+ * normalise a repeated or backward timestamp), the branch itself going to the null muxer; and the report built from
5
+ * those timestamps plus the decoder's error lines (the report's shape: sdks/sdk/src/server/media/frameCheck.ts).
6
+ * Pure. Loaded by the runner only for a job that asks for the step (src/steps/runner.ts).
7
+ */
8
+ import type { FrameCheckReport, FrameCheckSettings } from "@uploadfilm/sdk/server/media";
9
+ export declare const frameCheckWork: (work: string) => string;
10
+ /**
11
+ * The filter branch after the shared split: [in] → [fc]. signalstats gives every frame a metadata key, so the metadata
12
+ * filter prints a line for every frame (it prints only frames carrying the key).
13
+ */
14
+ export declare const frameCheckBranch: (input: string, work: string) => string;
15
+ /**
16
+ * The printed timestamps' time base: microseconds (settb), so it is known exactly whatever the source's (1001/30000
17
+ * would not survive being read back from pts / pts_time). Distinct frames never round to the same microsecond.
18
+ */
19
+ export declare const FRAME_TB = 1000000;
20
+ /** The branch's frames are dropped (null muxer), each one passed as it is (no frame invented or dropped on the way). */
21
+ export declare const frameCheckOutputArgs: () => string[];
22
+ /**
23
+ * The metadata filter's print file → every frame's pts (microseconds: FRAME_TB), in decoder output order. null when it
24
+ * isn't one.
25
+ */
26
+ export declare function parseFramePrint(text: string): {
27
+ tb: [number, number];
28
+ pts: number[];
29
+ } | null;
30
+ /** Lines of FFmpeg's stderr (at -loglevel error) that are decoding problems, not our own messages. */
31
+ export declare function decoderErrorLines(stderr: string): string[];
32
+ /**
33
+ * The report for frames with these timestamps (time-base ticks, in the order the decoder output them) and these
34
+ * decoder error lines.
35
+ *
36
+ * A gap is a step at least gapFactor × the LOCAL cadence (the median of the steps around it): one frame missing in a
37
+ * steady stream. A stream that changes its cadence (60 → 30 fps, a phone in low light) has long steps whose neighbours
38
+ * are long too: that is a variable frame rate, reported as such, not as missing frames.
39
+ */
40
+ export declare function analyzeFrames(input: {
41
+ tb: [number, number];
42
+ pts: number[];
43
+ errors?: string[];
44
+ }, s: FrameCheckSettings): FrameCheckReport;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The gatekeeper's part for the editor's steps (prep, render): what a container may store, beyond the version stamp
3
+ * src/jobs.ts gatekeep() has already checked.
4
+ *
5
+ * edit/media.mp4, render/video.mp4 streamed (≤ 5 GiB, one R2 PUT), must start with an ISO BMFF `ftyp` box
6
+ * edit/sb-NNN.jpg, render/poster.jpg ≤ maxPutBytes, must start like a JPEG (FF D8 FF)
7
+ * edit/peaks.bin ≤ the longest source's peaks (two bytes a bucket), an even length
8
+ * edit/prep.json, render/result.json ≤ 64 KiB, must parse and match the job (prepResultProblem,
9
+ * renderResultProblem), and every file they name must already be stored: the
10
+ * completion file can't be written before the files it completes
11
+ */
12
+ import { type OutputKind } from "@uploadfilm/sdk/server/media";
13
+ import { type MediaWorkerConfig } from "../config.mjs";
14
+ import type { Gate, GateBucket } from "../jobs.mjs";
15
+ export declare const MAX_RESULT_BYTES: number;
16
+ type Cfg = Pick<MediaWorkerConfig, "maxPutBytes" | "stepSettings">;
17
+ export declare function editOutput(req: Request, bucket: GateBucket, g: Gate, cfg: Cfg, rel: string, kind: OutputKind, len: number): Promise<Response>;
18
+ export {};
@@ -0,0 +1 @@
1
+ export declare function filterPath(p: string): string;
@@ -0,0 +1,60 @@
1
+ import { type PrepSettings, type RunnerStatus } from "@uploadfilm/sdk/server/media";
2
+ import { type Probe } from "../runner/ffmpeg.mjs";
3
+ import { type RunIO, type RunSpec } from "../runner/job.mjs";
4
+ import { type Demuxer, type EditCtx } from "./edit.mjs";
5
+ /**
6
+ * The sound's rate for the peaks: about 8 kHz mono (plenty for a waveform), made an exact multiple of the bucket rate so
7
+ * every bucket is the same whole number of samples (no drift: 300 buckets a second is 27 samples at 8100 Hz).
8
+ */
9
+ export declare const peaksSampleRate: (rate: number) => number;
10
+ /** The edit-ready picture's size: shown in square pixels, the short side at most `cap`. */
11
+ export declare function editFrame(p: Pick<Probe, "width" | "height" | "rotation" | "sar">, cap: number): {
12
+ width: number;
13
+ height: number;
14
+ };
15
+ /** A filmstrip tile's size: `long` px on the picture's long side. */
16
+ export declare function tileSize(p: {
17
+ width: number;
18
+ height: number;
19
+ }, long: number): {
20
+ width: number;
21
+ height: number;
22
+ };
23
+ /**
24
+ * Is the source already edit-ready, used as it is? Fragmented MP4 (not QuickTime), H.264 8-bit 4:2:0, AAC or no
25
+ * sound, upright, square pixels, progressive SDR, even sides, short side within the cap. (A full-range Chrome
26
+ * recording passes: the render's scaler reads its range.)
27
+ */
28
+ export declare function isEditReady(path: string, d: Demuxer, p: Probe, cap: number, audioCodec: string | null): boolean;
29
+ export interface PrepPlan {
30
+ convert: boolean;
31
+ frame: {
32
+ width: number;
33
+ height: number;
34
+ };
35
+ tile: {
36
+ width: number;
37
+ height: number;
38
+ };
39
+ interval: number;
40
+ /** Thumbnails at 0, interval, 2·interval… within the picture (at most maxFrames). */
41
+ thumbnails: number;
42
+ /** Where the picture starts on FFmpeg's clock (s): the peaks' bucket 0. */
43
+ videoStart: number;
44
+ fps: number;
45
+ }
46
+ /** The one FFmpeg run: the conversion (when needed), the thumbnails, the peaks' sound. */
47
+ export declare function prepArgs(src: string, d: Demuxer, p: Probe, plan: PrepPlan, s: PrepSettings, out: {
48
+ media: string;
49
+ thumbs: string;
50
+ pcm: string;
51
+ }): string[];
52
+ /** Tile the thumbnails into sheets (small JPEGs in, no source involved). */
53
+ export declare const sheetArgs: (thumbs: string, outDir: string, s: Pick<PrepSettings, "columns" | "rows" | "jpegQ">) => string[];
54
+ /**
55
+ * Peaks from 16-bit mono PCM: one [min, max] pair (signed 8-bit: the high byte) per `per` samples, read in chunks
56
+ * (never the whole sound in memory).
57
+ */
58
+ export declare function peaksOf(pcm: string, per: number): Int8Array;
59
+ /** Run a prep job (runJob's dispatch: steps ["prep"]). Resolves with the done status; the work directory is removed. */
60
+ export declare function runPrep(spec: RunSpec, io: RunIO, ctx: EditCtx, onStatus: (st: RunnerStatus) => void): Promise<RunnerStatus>;
@@ -0,0 +1,40 @@
1
+ import { type EditList, type EditPart, type RenderSettings, type RunnerStatus } from "@uploadfilm/sdk/server/media";
2
+ import { type Probe } from "../runner/ffmpeg.mjs";
3
+ import { type RunIO, type RunSpec } from "../runner/job.mjs";
4
+ import { type Demuxer, type EditCtx } from "./edit.mjs";
5
+ /** The picture chain of one part (see the file comment for the order), ending at the output's rate in yuv420p. */
6
+ export declare function partFilter(part: EditPart, p: Probe, e: EditList, s: Pick<RenderSettings, "maxShort">): string;
7
+ /**
8
+ * Where each part's picture starts on the output clock (its first frame, a frame boundary) and how far that is past
9
+ * where its sound starts (the edit list's exact time): the picture is read from that much later in the source, so
10
+ * frame k of the output shows what the edit list puts at k / fps (never up to a frame behind its sound).
11
+ */
12
+ export declare function pictureLead(e: EditList): number[];
13
+ /**
14
+ * One part's run: exactly `frames` pictures (H.264 in Matroska: its EBML header is always recognised, where a tiny
15
+ * MPEG-TS part of a few dark frames isn't, and the join then stops early) and exactly `samples` 48 kHz stereo s16
16
+ * samples.
17
+ */
18
+ export declare function partArgs(part: EditPart, src: {
19
+ path: string;
20
+ demuxer: Demuxer;
21
+ probe: Probe;
22
+ }, e: EditList, s: RenderSettings, frames: number, samples: number, out: {
23
+ ts: string;
24
+ pcm: string;
25
+ },
26
+ /** pictureLead(e)[k]: seconds the picture is read past the part's in-point. */
27
+ lead?: number): string[];
28
+ /** The AAC encoder's priming: 1024 samples of its own before the first real one, hidden by the moov's edit list. */
29
+ export declare const AAC_PRIMING = 1024;
30
+ /**
31
+ * Fragmented MP4 with the moov first. `delay_moov`: the (still empty) moov is written once the first packets are
32
+ * known, so it carries the edit lists that hide the AAC priming and the B-frames' reorder delay. Without it FFmpeg
33
+ * writes none in a fragmented file: the sound plays its priming (21 ms late) and the picture starts two frames late.
34
+ */
35
+ export declare const RENDER_MOVFLAGS = "+frag_keyframe+empty_moov+default_base_moof+delay_moov";
36
+ /** The pictures joined without re-encoding, the sound encoded once. */
37
+ export declare function joinArgs(list: string, pcm: string, out: string, s: Pick<RenderSettings, "audioKbps">): string[];
38
+ export declare const posterArgs: (video: string, out: string, s: Pick<RenderSettings, "posterWidth">) => string[];
39
+ /** Run a render job (runJob's dispatch: steps ["render"]). Resolves with the done status; the work directory is removed. */
40
+ export declare function runRender(spec: RunSpec, io: RunIO, ctx: EditCtx, onStatus: (st: RunnerStatus) => void): Promise<RunnerStatus>;
@@ -0,0 +1,30 @@
1
+ import { type Step, type StepSettings } from "@uploadfilm/sdk/server/media";
2
+ export interface StepJob {
3
+ /** The decodable audio stream (default 0:a:0). */
4
+ audioInput?: string;
5
+ steps: readonly Step[];
6
+ /** Does the source have an audio stream? */
7
+ hasAudio: boolean;
8
+ settings: StepSettings;
9
+ /** The job's work directory (silence lists, frame timestamps: never uploaded) and its output directory. */
10
+ work: string;
11
+ out: string;
12
+ }
13
+ /** What jobArgs adds for the optional steps (src/runner/ffmpeg.ts JobArgsOptions.stepArgs). */
14
+ export interface StepArgs {
15
+ /** Branches of the shared video split, numbered from `first` ([s<first>], …). */
16
+ videoBranches(first: number): string[];
17
+ /** More -filter_complex chains of their own (the audio's). */
18
+ chains: string[];
19
+ /** Output arguments, after every other output's. */
20
+ outputs: string[];
21
+ }
22
+ /** A failure of a step's own output: the source didn't give what the step needs. */
23
+ export declare class StepError extends Error {
24
+ code: "source";
25
+ }
26
+ export declare function stepArgs(j: StepJob): StepArgs;
27
+ /** After the ffmpeg run: write the audio index and the frame report into `out` (uploaded with everything else). */
28
+ export declare function finishSteps(j: StepJob & {
29
+ stderr: string;
30
+ }): void;