@adonis-agora/media 0.25.0 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +9 -8
  3. package/dist/src/define_config.d.ts +3 -3
  4. package/dist/src/errors.d.ts +2 -2
  5. package/dist/src/errors.d.ts.map +1 -1
  6. package/dist/src/errors.js +3 -3
  7. package/dist/src/errors.js.map +1 -1
  8. package/dist/src/hls/delivery.d.ts +1 -1
  9. package/dist/src/hls/delivery.d.ts.map +1 -1
  10. package/dist/src/hls/delivery.js +1 -1
  11. package/dist/src/hls/delivery.js.map +1 -1
  12. package/dist/src/hls/to_dash.d.ts +51 -0
  13. package/dist/src/hls/to_dash.d.ts.map +1 -0
  14. package/dist/src/hls/to_dash.js +130 -0
  15. package/dist/src/hls/to_dash.js.map +1 -0
  16. package/dist/src/index.d.ts +5 -6
  17. package/dist/src/index.d.ts.map +1 -1
  18. package/dist/src/index.js +3 -3
  19. package/dist/src/index.js.map +1 -1
  20. package/dist/src/media_access.d.ts +2 -3
  21. package/dist/src/media_access.d.ts.map +1 -1
  22. package/dist/src/media_access.js +2 -3
  23. package/dist/src/media_access.js.map +1 -1
  24. package/dist/src/media_collection.d.ts +1 -1
  25. package/dist/src/media_library.d.ts +2 -2
  26. package/dist/src/media_library.js +2 -2
  27. package/dist/src/streaming.d.ts +3 -3
  28. package/dist/src/streaming.d.ts.map +1 -1
  29. package/dist/src/streaming.js +10 -9
  30. package/dist/src/streaming.js.map +1 -1
  31. package/dist/src/transformer.d.ts +1 -1
  32. package/dist/src/transformers/factory.d.ts +11 -15
  33. package/dist/src/transformers/factory.d.ts.map +1 -1
  34. package/dist/src/transformers/factory.js +12 -18
  35. package/dist/src/transformers/factory.js.map +1 -1
  36. package/dist/src/transformers/ffmpeg.d.ts +23 -35
  37. package/dist/src/transformers/ffmpeg.d.ts.map +1 -1
  38. package/dist/src/transformers/ffmpeg.js +51 -54
  39. package/dist/src/transformers/ffmpeg.js.map +1 -1
  40. package/dist/src/transformers/mediabunny.d.ts +2 -2
  41. package/dist/src/transformers/mediabunny.d.ts.map +1 -1
  42. package/dist/src/transformers/mediabunny.js +148 -32
  43. package/dist/src/transformers/mediabunny.js.map +1 -1
  44. package/dist/src/transformers/mediabunny_loader.d.ts +2 -2
  45. package/dist/src/transformers/mediabunny_loader.d.ts.map +1 -1
  46. package/dist/src/transformers/probe.js +1 -1
  47. package/dist/src/transformers/probe.js.map +1 -1
  48. package/dist/src/transformers/video.d.ts +124 -0
  49. package/dist/src/transformers/video.d.ts.map +1 -0
  50. package/dist/src/transformers/video.js +133 -0
  51. package/dist/src/transformers/video.js.map +1 -0
  52. package/package.json +1 -1
  53. package/skills/media-library-collections/SKILL.md +4 -4
  54. package/dist/src/transformers/dash.d.ts +0 -70
  55. package/dist/src/transformers/dash.d.ts.map +0 -1
  56. package/dist/src/transformers/dash.js +0 -80
  57. package/dist/src/transformers/dash.js.map +0 -1
  58. package/dist/src/transformers/hls.d.ts +0 -113
  59. package/dist/src/transformers/hls.d.ts.map +0 -1
  60. package/dist/src/transformers/hls.js +0 -110
  61. package/dist/src/transformers/hls.js.map +0 -1
@@ -0,0 +1,124 @@
1
+ import type { Transformer, TransformerContext, TransformResult } from '../transformer.js';
2
+ /** A streaming format a {@link VideoTransformer} can write manifests for. */
3
+ export type VideoFormat = 'hls' | 'dash';
4
+ /**
5
+ * The container of the segments.
6
+ *
7
+ * - `'cmaf'` — fragmented MP4 (`.m4s`), the format HLS and DASH share: one set of segments, a
8
+ * manifest per format. The default.
9
+ * - `'ts'` — MPEG-TS (`.ts`), the original HLS segment format. HLS only (dash.js cannot play it);
10
+ * for players that predate fMP4 HLS (iOS 9 and older, some set-top boxes and smart TVs).
11
+ */
12
+ export type VideoSegmentFormat = 'cmaf' | 'ts';
13
+ /**
14
+ * Lazily supplies a WebCodecs implementation (`{ VideoEncoder, VideoDecoder, AudioEncoder, … }`).
15
+ * Node has no built-in WebCodecs, which is why the mediabunny engine is remux-only by default —
16
+ * but NAPI-based implementations exist (e.g. `@napi-rs/webcodecs`), and injecting one unlocks the
17
+ * re-encode fallback for sources whose codecs cannot be stream-copied:
18
+ *
19
+ * ```ts
20
+ * transformers.video({ webcodecs: () => import('@napi-rs/webcodecs') })
21
+ * ```
22
+ *
23
+ * The engine installs the provided classes onto `globalThis` (only the ones missing — a native
24
+ * implementation is never overwritten), because that is where the media engine looks them up.
25
+ */
26
+ export type WebCodecsProvider = () => Promise<Record<string, unknown>>;
27
+ /** How a runtime can satisfy the WebCodecs requirement. See {@link resolveWebCodecsSupport}. */
28
+ export type WebCodecsSupport = 'native' | 'injected' | 'absent';
29
+ /**
30
+ * Detect how (whether) WebCodecs is available: `'native'` when the runtime already exposes
31
+ * `VideoEncoder`, `'injected'` when a {@link WebCodecsProvider} supplies one, `'absent'` otherwise.
32
+ */
33
+ export declare function resolveWebCodecsSupport(provider?: WebCodecsProvider): Promise<WebCodecsSupport>;
34
+ /** What {@link VideoPackagingEngine.package} receives. */
35
+ export interface VideoPackageRequest {
36
+ /** Local path of the source file. */
37
+ sourcePath: string;
38
+ /** Local directory the engine writes the whole package into. */
39
+ outputDir: string;
40
+ /** Segment container. `'ts'` only ever comes with HLS alone. */
41
+ segments: VideoSegmentFormat;
42
+ /** File name of the HLS master playlist to write, or `undefined` when HLS is not wanted. */
43
+ hlsEntry?: string | undefined;
44
+ /** File name of the DASH manifest to write, or `undefined` when DASH is not wanted. */
45
+ dashManifest?: string | undefined;
46
+ /** Target (max) segment duration in seconds. */
47
+ targetDuration: number;
48
+ /** Optional WebCodecs implementation enabling the mediabunny re-encode fallback. */
49
+ webcodecs?: WebCodecsProvider | undefined;
50
+ }
51
+ /** What the engine learned about the source — persisted into the conversion `meta`. */
52
+ export interface VideoPackageSummary {
53
+ durationSeconds?: number;
54
+ width?: number;
55
+ height?: number;
56
+ videoCodec?: string | null;
57
+ audioCodec?: string | null;
58
+ }
59
+ /**
60
+ * The engine seam of {@link VideoTransformer}: a local file in, a streaming package in a local
61
+ * directory out — segments plus every manifest the request names, at the root of `outputDir`.
62
+ * The default is mediabunny (pure JS, remux); `engines.ffmpeg()` transcodes with the system
63
+ * ffmpeg. Tests inject a fake that writes files.
64
+ */
65
+ export interface VideoPackagingEngine {
66
+ package(request: VideoPackageRequest): Promise<VideoPackageSummary>;
67
+ }
68
+ export interface VideoTransformerOptions<Name extends string = 'video'> {
69
+ /** Conversion name on the record. Default `'video'`. */
70
+ name?: Name;
71
+ /**
72
+ * Which manifests to write. Default `['hls', 'dash']`: with CMAF segments both describe the
73
+ * same files, so the second format costs a manifest, not a second copy of the video.
74
+ */
75
+ formats?: readonly VideoFormat[];
76
+ /** Segment container. Default `'cmaf'`; `'ts'` requires `formats: ['hls']`. */
77
+ segments?: VideoSegmentFormat;
78
+ /** Target (max) segment duration in seconds. Default 4. */
79
+ targetDuration?: number;
80
+ /**
81
+ * Run inside attach. Default `false`, and think twice: packaging takes real time, and an eager
82
+ * failure rolls the attach back. Run `media.library.transform(id, 'video')` from a job.
83
+ */
84
+ eager?: boolean;
85
+ /**
86
+ * The engine. Default: mediabunny (pure JS — no ffmpeg on the host — remux only). Use
87
+ * `engines.ffmpeg({ ladder })` to transcode an adaptive-bitrate ladder.
88
+ */
89
+ engine?: VideoPackagingEngine;
90
+ /** WebCodecs for the mediabunny engine's re-encode fallback (see {@link WebCodecsProvider}). */
91
+ webcodecs?: WebCodecsProvider;
92
+ }
93
+ /** File name of the HLS master playlist a {@link VideoTransformer} writes. */
94
+ export declare const VIDEO_HLS_ENTRY = "index.m3u8";
95
+ /** File name of the DASH manifest a {@link VideoTransformer} writes. */
96
+ export declare const VIDEO_DASH_MANIFEST = "manifest.mpd";
97
+ /**
98
+ * The built-in video {@link Transformer}: packages a stored video for adaptive streaming —
99
+ * segments plus an HLS master playlist and/or a DASH manifest — persisted as
100
+ * `record.conversions['video']`.
101
+ *
102
+ * - **CMAF by default.** Fragmented-MP4 segments are the one format both HLS and DASH play, so
103
+ * `formats: ['hls', 'dash']` (the default) writes the video once and describes it twice.
104
+ * - **TS when you need it.** `segments: 'ts'` writes MPEG-TS segments, HLS only, for players
105
+ * that predate fMP4 HLS.
106
+ * - **No ffmpeg needed.** The default engine (mediabunny) remuxes in pure JS; `engines.ffmpeg()`
107
+ * transcodes, ladder included, where the host has ffmpeg.
108
+ *
109
+ * Serve it with `media.access.streamRoute()` and play it with `useMediaStream`.
110
+ */
111
+ export declare class VideoTransformer<Name extends string = 'video'> implements Transformer {
112
+ readonly name: Name;
113
+ readonly eager: boolean;
114
+ readonly formats: readonly VideoFormat[];
115
+ readonly segments: VideoSegmentFormat;
116
+ private readonly targetDuration;
117
+ private readonly engine;
118
+ private readonly webcodecs;
119
+ constructor(options?: VideoTransformerOptions<Name>);
120
+ transform(context: TransformerContext): Promise<TransformResult>;
121
+ }
122
+ /** Drop `undefined` values so the persisted meta round-trips identically through JSON stores. */
123
+ export declare function compactMeta(meta: Record<string, unknown>): Record<string, unknown>;
124
+ //# sourceMappingURL=video.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../src/transformers/video.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAI1F,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,MAAM,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEvE,gGAAgG;AAChG,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEhE;;;GAGG;AACH,wBAAsB,uBAAu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M,CAAC,EAAE,oBAAoB,CAAC;IAC9B,gGAAgG;IAChG,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAED,8EAA8E;AAC9E,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,wEAAwE;AACxE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAElD;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAgB,CAAC,IAAI,SAAS,MAAM,GAAG,OAAO,CAAE,YAAW,WAAW;IACjF,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAC1D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgC;IAE1D,YAAY,OAAO,GAAE,uBAAuB,CAAC,IAAI,CAAM,EA+BtD;IAEK,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CA+DrE;CACF;AAED,iGAAiG;AACjG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAElF"}
@@ -0,0 +1,133 @@
1
+ import { createReadStream } from 'node:fs';
2
+ import { mkdir, readdir, stat } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { streamArtifactContentType } from '../streaming.js';
5
+ import { loadMediabunny } from './mediabunny_loader.js';
6
+ import { withSourceFile } from './source_file.js';
7
+ /**
8
+ * Detect how (whether) WebCodecs is available: `'native'` when the runtime already exposes
9
+ * `VideoEncoder`, `'injected'` when a {@link WebCodecsProvider} supplies one, `'absent'` otherwise.
10
+ */
11
+ export async function resolveWebCodecsSupport(provider) {
12
+ if (globalThis.VideoEncoder !== undefined)
13
+ return 'native';
14
+ if (provider && (await provider()).VideoEncoder !== undefined)
15
+ return 'injected';
16
+ return 'absent';
17
+ }
18
+ /** File name of the HLS master playlist a {@link VideoTransformer} writes. */
19
+ export const VIDEO_HLS_ENTRY = 'index.m3u8';
20
+ /** File name of the DASH manifest a {@link VideoTransformer} writes. */
21
+ export const VIDEO_DASH_MANIFEST = 'manifest.mpd';
22
+ /**
23
+ * The built-in video {@link Transformer}: packages a stored video for adaptive streaming —
24
+ * segments plus an HLS master playlist and/or a DASH manifest — persisted as
25
+ * `record.conversions['video']`.
26
+ *
27
+ * - **CMAF by default.** Fragmented-MP4 segments are the one format both HLS and DASH play, so
28
+ * `formats: ['hls', 'dash']` (the default) writes the video once and describes it twice.
29
+ * - **TS when you need it.** `segments: 'ts'` writes MPEG-TS segments, HLS only, for players
30
+ * that predate fMP4 HLS.
31
+ * - **No ffmpeg needed.** The default engine (mediabunny) remuxes in pure JS; `engines.ffmpeg()`
32
+ * transcodes, ladder included, where the host has ffmpeg.
33
+ *
34
+ * Serve it with `media.access.streamRoute()` and play it with `useMediaStream`.
35
+ */
36
+ export class VideoTransformer {
37
+ name;
38
+ eager;
39
+ formats;
40
+ segments;
41
+ targetDuration;
42
+ engine;
43
+ webcodecs;
44
+ constructor(options = {}) {
45
+ this.name = options.name ?? 'video';
46
+ this.eager = options.eager ?? false;
47
+ this.formats = [...new Set(options.formats ?? ['hls', 'dash'])];
48
+ this.segments = options.segments ?? 'cmaf';
49
+ this.targetDuration = options.targetDuration ?? 4;
50
+ this.engine = options.engine;
51
+ this.webcodecs = options.webcodecs;
52
+ // Fail at config time, not on the first upload hours later.
53
+ if (this.formats.length === 0) {
54
+ throw new Error(`transformers.video({ name: '${this.name}' }): \`formats\` is empty.`);
55
+ }
56
+ for (const format of this.formats) {
57
+ if (format !== 'hls' && format !== 'dash') {
58
+ throw new Error(`transformers.video({ name: '${this.name}' }): unknown format '${format}' — use 'hls' and/or 'dash'.`);
59
+ }
60
+ }
61
+ if (this.segments !== 'cmaf' && this.segments !== 'ts') {
62
+ throw new Error(`transformers.video({ name: '${this.name}' }): unknown segments '${this.segments}' — use 'cmaf' or 'ts'.`);
63
+ }
64
+ if (this.segments === 'ts' && this.formats.includes('dash')) {
65
+ throw new Error(`transformers.video({ name: '${this.name}' }): DASH cannot use TS segments — players ` +
66
+ "only play DASH over fragmented MP4. Use `formats: ['hls']` with `segments: 'ts'`, or " +
67
+ "keep the default `segments: 'cmaf'` (which serves both formats).");
68
+ }
69
+ }
70
+ async transform(context) {
71
+ const engine = this.engine ?? (await loadMediabunny(this.name)).createVideoEngine();
72
+ const hls = this.formats.includes('hls');
73
+ const dash = this.formats.includes('dash');
74
+ return withSourceFile(context, async ({ sourcePath, tempDir }) => {
75
+ const outputDir = join(tempDir, 'video');
76
+ await mkdir(outputDir, { recursive: true });
77
+ const summary = await engine.package({
78
+ sourcePath,
79
+ outputDir,
80
+ segments: this.segments,
81
+ hlsEntry: hls ? VIDEO_HLS_ENTRY : undefined,
82
+ dashManifest: dash ? VIDEO_DASH_MANIFEST : undefined,
83
+ targetDuration: this.targetDuration,
84
+ webcodecs: this.webcodecs,
85
+ });
86
+ // Upload the whole package — manifests and segments — streaming each file (a segment never
87
+ // has to fit in memory). Sorted for a deterministic `conversions[name].files`.
88
+ const files = (await readdir(outputDir, { recursive: true })).sort();
89
+ const written = [];
90
+ let segmentCount = 0;
91
+ for (const file of files) {
92
+ const relative = file.split('\\').join('/');
93
+ const local = join(outputDir, file);
94
+ const info = await stat(local);
95
+ if (!info.isFile())
96
+ continue;
97
+ written.push(relative);
98
+ if (/\.(m4s|ts)$/i.test(relative) && !/(^|\/)init[^/]*$/i.test(relative)) {
99
+ segmentCount += 1;
100
+ }
101
+ const contentType = streamArtifactContentType(relative);
102
+ await context.write(relative, createReadStream(local), {
103
+ contentLength: info.size,
104
+ ...(contentType !== undefined ? { contentType } : {}),
105
+ });
106
+ }
107
+ for (const [format, manifest] of [
108
+ ['hls', hls ? VIDEO_HLS_ENTRY : undefined],
109
+ ['dash', dash ? VIDEO_DASH_MANIFEST : undefined],
110
+ ]) {
111
+ if (manifest && !written.includes(manifest)) {
112
+ throw new Error(`The video engine did not write the ${format.toUpperCase()} manifest "${manifest}".`);
113
+ }
114
+ }
115
+ return {
116
+ entry: hls ? VIDEO_HLS_ENTRY : VIDEO_DASH_MANIFEST,
117
+ meta: compactMeta({
118
+ ...summary,
119
+ segments: this.segments,
120
+ segmentCount,
121
+ targetDuration: this.targetDuration,
122
+ hlsEntry: hls ? VIDEO_HLS_ENTRY : undefined,
123
+ dashManifest: dash ? VIDEO_DASH_MANIFEST : undefined,
124
+ }),
125
+ };
126
+ });
127
+ }
128
+ }
129
+ /** Drop `undefined` values so the persisted meta round-trips identically through JSON stores. */
130
+ export function compactMeta(meta) {
131
+ return Object.fromEntries(Object.entries(meta).filter(([, value]) => value !== undefined));
132
+ }
133
+ //# sourceMappingURL=video.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video.js","sourceRoot":"","sources":["../../../src/transformers/video.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAiClD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,QAA4B;IAE5B,IAAK,UAAsC,CAAC,YAAY,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACxF,IAAI,QAAQ,IAAI,CAAC,MAAM,QAAQ,EAAE,CAAC,CAAC,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C7F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/media",
3
- "version": "0.25.0",
3
+ "version": "0.26.1",
4
4
  "description": "Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, all on top of @adonisjs/drive. Pluggable MediaStore (in-memory + Lucid) and ImageProcessor (sharp). Part of the Agora ecosystem.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -246,17 +246,17 @@ Source: `docs/configuration.mdx` (`imageProcessor`), `docs/errors.mdx`.
246
246
  Wrong:
247
247
 
248
248
  ```ts
249
- // 'videos' collection declares transformers.hls()
250
- const url = await media.library.url(videoId, 'hls') // throws before any transform ran
249
+ // 'videos' collection declares transformers.video()
250
+ const url = await media.library.url(videoId, 'video') // throws before any transform ran
251
251
  ```
252
252
 
253
253
  Correct:
254
254
 
255
255
  ```ts
256
256
  // run the transform explicitly (usually from a job), then read
257
- await media.library.transform(videoId, 'hls') // idempotent — retries skip through
257
+ await media.library.transform(videoId, 'video') // idempotent — retries skip through
258
258
  const record = await media.library.find(videoId)
259
- record!.conversions.hls // { path, prefix, files, meta }
259
+ record!.conversions.video // { path, prefix, files, meta }
260
260
  ```
261
261
 
262
262
  Mechanism: image presets generate lazily on first read, but reads NEVER generate transforms —
@@ -1,70 +0,0 @@
1
- import type { Transformer, TransformerContext, TransformResult } from '../transformer.js';
2
- import type { HlsRemuxSummary } from './hls.js';
3
- /** What {@link DashPackageEngine.package} receives. */
4
- export interface DashPackageRequest {
5
- /** Local path of the source file. */
6
- sourcePath: string;
7
- /** Local directory the engine writes the whole package into. */
8
- outputDir: string;
9
- /** File name of the DASH manifest, e.g. `manifest.mpd`. */
10
- manifestName: string;
11
- /**
12
- * File name of an HLS master playlist to write over the **same** segments, or `undefined` for a
13
- * DASH-only package.
14
- */
15
- hlsEntryName?: string | undefined;
16
- /** Target segment duration in seconds. */
17
- targetDuration: number;
18
- }
19
- /**
20
- * The engine seam of {@link DashTransformer}: local file in, a CMAF package (fragmented-MP4
21
- * segments, an MPD, optionally an HLS master over the same segments) in a local directory out.
22
- * The default is {@link ffmpegDashEngine}; tests inject a fake that writes files.
23
- */
24
- export interface DashPackageEngine {
25
- package(request: DashPackageRequest): Promise<HlsRemuxSummary>;
26
- }
27
- export interface DashTransformerOptions<Name extends string = 'dash'> {
28
- /** Conversion name on the record. Default `'dash'`. */
29
- name?: Name;
30
- /** Run inside attach. Default `false`: packaging a video takes real time — run it from a job. */
31
- eager?: boolean;
32
- /** Target segment duration in seconds. Default 4. */
33
- targetDuration?: number;
34
- /**
35
- * Also write an HLS master playlist over the same segments. Default `true`: the segments are
36
- * CMAF (fragmented MP4), which both formats play, so HLS costs a few playlists and no extra
37
- * storage — and Safari/iOS, which play HLS natively but not DASH, are covered by one package.
38
- */
39
- hls?: boolean;
40
- /** Replace the engine. Default `engines.ffmpegDash()` (remux; pass a `ladder` to transcode). */
41
- engine?: DashPackageEngine;
42
- }
43
- /** File name of the manifest a {@link DashTransformer} produces. */
44
- export declare const DASH_MANIFEST = "manifest.mpd";
45
- /** File name of the HLS master playlist a {@link DashTransformer} writes alongside (`hls: true`). */
46
- export declare const DASH_HLS_ENTRY = "index.m3u8";
47
- /**
48
- * Video → a **CMAF** package: fragmented-MP4 segments described by a DASH manifest
49
- * (`manifest.mpd`, the conversion entry) and, by default, by an HLS master playlist too
50
- * (`index.m3u8`, recorded as `meta.hlsEntry`) — one encode, one copy of the segments, both
51
- * formats. Persisted as `record.conversions['dash']`.
52
- *
53
- * The default engine is the system ffmpeg (`engines.ffmpegDash()`), remuxing the source as is;
54
- * `engines.ffmpegDash({ ladder: engines.ladders.standard })` transcodes an adaptive-bitrate ladder.
55
- * mediabunny has no DASH muxer, so unlike {@link HlsTransformer} there is no pure-JS default.
56
- *
57
- * Serve it with `media.access.streamRoute()`, and play it with `useMediaStream` from
58
- * `@adonis-agora/media-react` — which picks HLS where it plays natively and dash.js/hls.js
59
- * elsewhere.
60
- */
61
- export declare class DashTransformer<Name extends string = 'dash'> implements Transformer {
62
- readonly name: Name;
63
- readonly eager: boolean;
64
- private readonly targetDuration;
65
- private readonly hls;
66
- private readonly engine;
67
- constructor(options?: DashTransformerOptions<Name>);
68
- transform(context: TransformerContext): Promise<TransformResult>;
69
- }
70
- //# sourceMappingURL=dash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dash.d.ts","sourceRoot":"","sources":["../../../src/transformers/dash.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhD,uDAAuD;AACvD,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,0CAA0C;IAC1C,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,sBAAsB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IAClE,uDAAuD;IACvD,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,iGAAiG;IACjG,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qDAAqD;IACrD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,gGAAgG;IAChG,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAED,oEAAoE;AACpE,eAAO,MAAM,aAAa,iBAAiB,CAAC;AAE5C,qGAAqG;AACrG,eAAO,MAAM,cAAc,eAAe,CAAC;AAE3C;;;;;;;;;;;;;GAaG;AACH,qBAAa,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,CAAE,YAAW,WAAW;IAC/E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IAEvD,YAAY,OAAO,GAAE,sBAAsB,CAAC,IAAI,CAAM,EAMrD;IAEK,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAyCrE;CACF"}
@@ -1,80 +0,0 @@
1
- import { createReadStream } from 'node:fs';
2
- import { mkdir, readdir, stat } from 'node:fs/promises';
3
- import { join } from 'node:path';
4
- import { streamArtifactContentType } from '../streaming.js';
5
- import { ffmpegDashEngine } from './ffmpeg.js';
6
- import { compactMeta } from './hls.js';
7
- import { withSourceFile } from './source_file.js';
8
- /** File name of the manifest a {@link DashTransformer} produces. */
9
- export const DASH_MANIFEST = 'manifest.mpd';
10
- /** File name of the HLS master playlist a {@link DashTransformer} writes alongside (`hls: true`). */
11
- export const DASH_HLS_ENTRY = 'index.m3u8';
12
- /**
13
- * Video → a **CMAF** package: fragmented-MP4 segments described by a DASH manifest
14
- * (`manifest.mpd`, the conversion entry) and, by default, by an HLS master playlist too
15
- * (`index.m3u8`, recorded as `meta.hlsEntry`) — one encode, one copy of the segments, both
16
- * formats. Persisted as `record.conversions['dash']`.
17
- *
18
- * The default engine is the system ffmpeg (`engines.ffmpegDash()`), remuxing the source as is;
19
- * `engines.ffmpegDash({ ladder: engines.ladders.standard })` transcodes an adaptive-bitrate ladder.
20
- * mediabunny has no DASH muxer, so unlike {@link HlsTransformer} there is no pure-JS default.
21
- *
22
- * Serve it with `media.access.streamRoute()`, and play it with `useMediaStream` from
23
- * `@adonis-agora/media-react` — which picks HLS where it plays natively and dash.js/hls.js
24
- * elsewhere.
25
- */
26
- export class DashTransformer {
27
- name;
28
- eager;
29
- targetDuration;
30
- hls;
31
- engine;
32
- constructor(options = {}) {
33
- this.name = options.name ?? 'dash';
34
- this.eager = options.eager ?? false;
35
- this.targetDuration = options.targetDuration ?? 4;
36
- this.hls = options.hls ?? true;
37
- this.engine = options.engine;
38
- }
39
- async transform(context) {
40
- const engine = this.engine ?? ffmpegDashEngine();
41
- return withSourceFile(context, async ({ sourcePath, tempDir }) => {
42
- const outputDir = join(tempDir, 'dash');
43
- await mkdir(outputDir, { recursive: true });
44
- const summary = await engine.package({
45
- sourcePath,
46
- outputDir,
47
- manifestName: DASH_MANIFEST,
48
- hlsEntryName: this.hls ? DASH_HLS_ENTRY : undefined,
49
- targetDuration: this.targetDuration,
50
- });
51
- const files = (await readdir(outputDir, { recursive: true })).sort();
52
- let segmentCount = 0;
53
- for (const file of files) {
54
- const relative = file.split('\\').join('/');
55
- const local = join(outputDir, file);
56
- const info = await stat(local);
57
- if (!info.isFile())
58
- continue;
59
- if (!/\.(mpd|m3u8)$/i.test(relative))
60
- segmentCount += 1;
61
- const contentType = streamArtifactContentType(relative);
62
- await context.write(relative, createReadStream(local), {
63
- contentLength: info.size,
64
- ...(contentType !== undefined ? { contentType } : {}),
65
- });
66
- }
67
- const relativeFiles = files.map((f) => f.split('\\').join('/'));
68
- return {
69
- entry: DASH_MANIFEST,
70
- meta: compactMeta({
71
- ...summary,
72
- segmentCount,
73
- targetDuration: this.targetDuration,
74
- hlsEntry: this.hls && relativeFiles.includes(DASH_HLS_ENTRY) ? DASH_HLS_ENTRY : undefined,
75
- }),
76
- };
77
- });
78
- }
79
- }
80
- //# sourceMappingURL=dash.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dash.js","sourceR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AC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACtD,CAAC,CAAC;YACL,CAAC;YAED,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAChE,OAAO;gBACL,KAAK,EAAE,aAAa;gBACpB,IAAI,EAAE,WAAW,CAAC;oBAChB,GAAG,OAAO;oBACV,YAAY;oBACZ,cAAc,EAAE,IAAI,CAAC,cAAc;oBACnC,QAAQ,EAAE,IAAI,CAAC,GAAG,IAAI,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;iBAC1F,CAAC;aACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,113 +0,0 @@
1
- import type { Transformer, TransformerContext, TransformResult } from '../transformer.js';
2
- /**
3
- * Lazily supplies a WebCodecs implementation (`{ VideoEncoder, VideoDecoder, AudioEncoder, … }`).
4
- * Node has no built-in WebCodecs, which is exactly why the HLS transformer is remux-only by
5
- * default — but NAPI-based implementations exist (e.g. `@napi-rs/webcodecs`), and injecting one
6
- * unlocks the re-encode fallback for sources whose codecs cannot be stream-copied:
7
- *
8
- * ```ts
9
- * transformers.hls({ webcodecs: () => import('@napi-rs/webcodecs') })
10
- * ```
11
- *
12
- * The engine installs the provided classes onto `globalThis` (only the ones missing — a native
13
- * implementation is never overwritten), because that is where the underlying media engine looks
14
- * the API up.
15
- */
16
- export type WebCodecsProvider = () => Promise<Record<string, unknown>>;
17
- /** How a runtime can satisfy the WebCodecs requirement. See {@link resolveWebCodecsSupport}. */
18
- export type WebCodecsSupport = 'native' | 'injected' | 'absent';
19
- /**
20
- * Detect how (whether) WebCodecs is available: `'native'` when the runtime already exposes
21
- * `VideoEncoder`, `'injected'` when a {@link WebCodecsProvider} supplies one, `'absent'` otherwise.
22
- * `'absent'` means encoding is impossible — transforms stay stream-copy only, and a transformer
23
- * that cannot proceed without an encoder should throw `TransformerRuntimeMissingError`.
24
- */
25
- export declare function resolveWebCodecsSupport(provider?: WebCodecsProvider): Promise<WebCodecsSupport>;
26
- /** What {@link HlsRemuxEngine.remux} receives. */
27
- export interface HlsRemuxRequest {
28
- /** Local path of the source file. */
29
- sourcePath: string;
30
- /** Local directory the engine writes the whole package into (entry playlist at its root). */
31
- outputDir: string;
32
- /** File name of the entry (master) playlist, e.g. `index.m3u8`. */
33
- entryName: string;
34
- /** Target (max) segment duration in seconds. */
35
- targetDuration: number;
36
- /** Optional WebCodecs implementation enabling the re-encode fallback. */
37
- webcodecs?: WebCodecsProvider | undefined;
38
- }
39
- /** What the engine learned about the source while remuxing — persisted into the conversion `meta`. */
40
- export interface HlsRemuxSummary {
41
- durationSeconds?: number;
42
- width?: number;
43
- height?: number;
44
- videoCodec?: string | null;
45
- audioCodec?: string | null;
46
- }
47
- /**
48
- * The engine seam of {@link HlsTransformer}: local file in, HLS package (playlists + segments) in
49
- * a local directory out. The default engine is mediabunny, loaded lazily on first transform; tests
50
- * inject a fake that writes files, so every bit of orchestration around the engine is testable
51
- * without the optional peer.
52
- */
53
- export interface HlsRemuxEngine {
54
- remux(request: HlsRemuxRequest): Promise<HlsRemuxSummary>;
55
- }
56
- export interface HlsTransformerOptions<Name extends string = 'hls'> {
57
- /** Conversion name on the record. Default `'hls'`. */
58
- name?: Name;
59
- /**
60
- * Run inside attach. Default `false`, and think twice: a remux takes real time, and an eager
61
- * failure rolls the attach back. The intended flow is deferred —
62
- * `media.library.transform(id, 'hls')` from a job.
63
- */
64
- eager?: boolean;
65
- /** Target (max) segment duration in seconds. Default 4. */
66
- targetDuration?: number;
67
- /** WebCodecs implementation for the re-encode fallback (see {@link WebCodecsProvider}). */
68
- webcodecs?: WebCodecsProvider;
69
- /**
70
- * Replace the mediabunny engine — e.g. `engines.ffmpegHls({ ladder })` to transcode an
71
- * adaptive-bitrate ladder with the system ffmpeg, or your own {@link HlsRemuxEngine}.
72
- */
73
- engine?: HlsRemuxEngine;
74
- }
75
- /** File name of the entry (master) playlist an {@link HlsTransformer} produces. */
76
- export declare const HLS_ENTRY_PLAYLIST = "index.m3u8";
77
- /**
78
- * The built-in video {@link Transformer}: converts a stored video into an HLS package — MPEG-TS
79
- * segments plus media playlists behind one master playlist — written under the conversion prefix
80
- * and persisted as `record.conversions['hls']` with duration/resolution/codec metadata.
81
- *
82
- * **Remux-only by default.** The engine (mediabunny, pure JS — no ffmpeg binary) stream-copies
83
- * the source's h264/aac tracks into segments without re-encoding, because encoding needs
84
- * WebCodecs, which Node does not provide. Two consequences, both deliberate:
85
- *
86
- * - a source whose codecs MPEG-TS cannot carry (vp9, av1…) fails with a clear, definitive
87
- * `HlsSourceUnsupportedError` — unless a {@link WebCodecsProvider} is configured, which enables
88
- * the engine's re-encode fallback;
89
- * - the package has a single variant at the original resolution. Multi-quality renditions are the
90
- * documented evolution once an encoder is present (mediabunny supports fan-out video options),
91
- * not something this transformer fakes today.
92
- *
93
- * The engine also carries the subtle bit the naive implementation gets wrong: AAC audio with
94
- * priming (an mp4 edit list) starts at a **negative** timestamp, and a conversion trimmed at t=0
95
- * would kick that track off the stream-copy fast path — impossible without an encoder. The
96
- * conversion is therefore trimmed at the source's real first timestamp, shifting all tracks
97
- * equally (sync is unchanged) and keeping every track copyable.
98
- *
99
- * Serving the result is the other half: playlists are stored with storage-relative references and
100
- * must be rewritten per request — see {@link HlsDeliveryHandler}.
101
- */
102
- export declare class HlsTransformer<Name extends string = 'hls'> implements Transformer {
103
- readonly name: Name;
104
- readonly eager: boolean;
105
- private readonly targetDuration;
106
- private readonly webcodecs;
107
- private readonly engine;
108
- constructor(options?: HlsTransformerOptions<Name>);
109
- transform(context: TransformerContext): Promise<TransformResult>;
110
- }
111
- /** Drop `undefined` values so the persisted meta round-trips identically through JSON stores. */
112
- export declare function compactMeta(meta: Record<string, unknown>): Record<string, unknown>;
113
- //# sourceMappingURL=hls.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hls.d.ts","sourceRoot":"","sources":["../../../src/transformers/hls.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAI1F;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEvE,gGAAgG;AAChG,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAI3B;AAED,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,6FAA6F;IAC7F,SAAS,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,cAAc,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,SAAS,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC3C;AAED,sGAAsG;AACtG,MAAM,WAAW,eAAe;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,qBAAqB,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