@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.
- package/CHANGELOG.md +28 -0
- package/README.md +9 -8
- package/dist/src/define_config.d.ts +3 -3
- package/dist/src/errors.d.ts +2 -2
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +3 -3
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hls/delivery.d.ts +1 -1
- package/dist/src/hls/delivery.d.ts.map +1 -1
- package/dist/src/hls/delivery.js +1 -1
- package/dist/src/hls/delivery.js.map +1 -1
- package/dist/src/hls/to_dash.d.ts +51 -0
- package/dist/src/hls/to_dash.d.ts.map +1 -0
- package/dist/src/hls/to_dash.js +130 -0
- package/dist/src/hls/to_dash.js.map +1 -0
- package/dist/src/index.d.ts +5 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/media_access.d.ts +2 -3
- package/dist/src/media_access.d.ts.map +1 -1
- package/dist/src/media_access.js +2 -3
- package/dist/src/media_access.js.map +1 -1
- package/dist/src/media_collection.d.ts +1 -1
- package/dist/src/media_library.d.ts +2 -2
- package/dist/src/media_library.js +2 -2
- package/dist/src/streaming.d.ts +3 -3
- package/dist/src/streaming.d.ts.map +1 -1
- package/dist/src/streaming.js +10 -9
- package/dist/src/streaming.js.map +1 -1
- package/dist/src/transformer.d.ts +1 -1
- package/dist/src/transformers/factory.d.ts +11 -15
- package/dist/src/transformers/factory.d.ts.map +1 -1
- package/dist/src/transformers/factory.js +12 -18
- package/dist/src/transformers/factory.js.map +1 -1
- package/dist/src/transformers/ffmpeg.d.ts +23 -35
- package/dist/src/transformers/ffmpeg.d.ts.map +1 -1
- package/dist/src/transformers/ffmpeg.js +51 -54
- package/dist/src/transformers/ffmpeg.js.map +1 -1
- package/dist/src/transformers/mediabunny.d.ts +2 -2
- package/dist/src/transformers/mediabunny.d.ts.map +1 -1
- package/dist/src/transformers/mediabunny.js +148 -32
- package/dist/src/transformers/mediabunny.js.map +1 -1
- package/dist/src/transformers/mediabunny_loader.d.ts +2 -2
- package/dist/src/transformers/mediabunny_loader.d.ts.map +1 -1
- package/dist/src/transformers/probe.js +1 -1
- package/dist/src/transformers/probe.js.map +1 -1
- package/dist/src/transformers/video.d.ts +124 -0
- package/dist/src/transformers/video.d.ts.map +1 -0
- package/dist/src/transformers/video.js +133 -0
- package/dist/src/transformers/video.js.map +1 -0
- package/package.json +1 -1
- package/skills/media-library-collections/SKILL.md +4 -4
- package/dist/src/transformers/dash.d.ts +0 -70
- package/dist/src/transformers/dash.d.ts.map +0 -1
- package/dist/src/transformers/dash.js +0 -80
- package/dist/src/transformers/dash.js.map +0 -1
- package/dist/src/transformers/hls.d.ts +0 -113
- package/dist/src/transformers/hls.d.ts.map +0 -1
- package/dist/src/transformers/hls.js +0 -110
- package/dist/src/transformers/hls.js.map +0 -1
|
@@ -1,110 +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 { hlsArtifactContentType } from '../hls/playlist.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
|
-
* `'absent'` means encoding is impossible — transforms stay stream-copy only, and a transformer
|
|
11
|
-
* that cannot proceed without an encoder should throw `TransformerRuntimeMissingError`.
|
|
12
|
-
*/
|
|
13
|
-
export async function resolveWebCodecsSupport(provider) {
|
|
14
|
-
if (globalThis.VideoEncoder !== undefined)
|
|
15
|
-
return 'native';
|
|
16
|
-
if (provider && (await provider()).VideoEncoder !== undefined)
|
|
17
|
-
return 'injected';
|
|
18
|
-
return 'absent';
|
|
19
|
-
}
|
|
20
|
-
/** File name of the entry (master) playlist an {@link HlsTransformer} produces. */
|
|
21
|
-
export const HLS_ENTRY_PLAYLIST = 'index.m3u8';
|
|
22
|
-
/**
|
|
23
|
-
* The built-in video {@link Transformer}: converts a stored video into an HLS package — MPEG-TS
|
|
24
|
-
* segments plus media playlists behind one master playlist — written under the conversion prefix
|
|
25
|
-
* and persisted as `record.conversions['hls']` with duration/resolution/codec metadata.
|
|
26
|
-
*
|
|
27
|
-
* **Remux-only by default.** The engine (mediabunny, pure JS — no ffmpeg binary) stream-copies
|
|
28
|
-
* the source's h264/aac tracks into segments without re-encoding, because encoding needs
|
|
29
|
-
* WebCodecs, which Node does not provide. Two consequences, both deliberate:
|
|
30
|
-
*
|
|
31
|
-
* - a source whose codecs MPEG-TS cannot carry (vp9, av1…) fails with a clear, definitive
|
|
32
|
-
* `HlsSourceUnsupportedError` — unless a {@link WebCodecsProvider} is configured, which enables
|
|
33
|
-
* the engine's re-encode fallback;
|
|
34
|
-
* - the package has a single variant at the original resolution. Multi-quality renditions are the
|
|
35
|
-
* documented evolution once an encoder is present (mediabunny supports fan-out video options),
|
|
36
|
-
* not something this transformer fakes today.
|
|
37
|
-
*
|
|
38
|
-
* The engine also carries the subtle bit the naive implementation gets wrong: AAC audio with
|
|
39
|
-
* priming (an mp4 edit list) starts at a **negative** timestamp, and a conversion trimmed at t=0
|
|
40
|
-
* would kick that track off the stream-copy fast path — impossible without an encoder. The
|
|
41
|
-
* conversion is therefore trimmed at the source's real first timestamp, shifting all tracks
|
|
42
|
-
* equally (sync is unchanged) and keeping every track copyable.
|
|
43
|
-
*
|
|
44
|
-
* Serving the result is the other half: playlists are stored with storage-relative references and
|
|
45
|
-
* must be rewritten per request — see {@link HlsDeliveryHandler}.
|
|
46
|
-
*/
|
|
47
|
-
export class HlsTransformer {
|
|
48
|
-
name;
|
|
49
|
-
eager;
|
|
50
|
-
targetDuration;
|
|
51
|
-
webcodecs;
|
|
52
|
-
engine;
|
|
53
|
-
constructor(options = {}) {
|
|
54
|
-
this.name = options.name ?? 'hls';
|
|
55
|
-
this.eager = options.eager ?? false;
|
|
56
|
-
this.targetDuration = options.targetDuration ?? 4;
|
|
57
|
-
this.webcodecs = options.webcodecs;
|
|
58
|
-
this.engine = options.engine;
|
|
59
|
-
}
|
|
60
|
-
async transform(context) {
|
|
61
|
-
const engine = this.engine ?? (await loadMediabunny(this.name)).createHlsEngine();
|
|
62
|
-
return withSourceFile(context, async ({ sourcePath, tempDir }) => {
|
|
63
|
-
const outputDir = join(tempDir, 'hls');
|
|
64
|
-
await mkdir(outputDir, { recursive: true });
|
|
65
|
-
const summary = await engine.remux({
|
|
66
|
-
sourcePath,
|
|
67
|
-
outputDir,
|
|
68
|
-
entryName: HLS_ENTRY_PLAYLIST,
|
|
69
|
-
targetDuration: this.targetDuration,
|
|
70
|
-
webcodecs: this.webcodecs,
|
|
71
|
-
});
|
|
72
|
-
// Upload the whole package the engine wrote — playlists and segments alike — streaming each
|
|
73
|
-
// file (a segment never has to fit in memory). Sorted for deterministic order in
|
|
74
|
-
// `conversions[name].files`.
|
|
75
|
-
const files = (await readdir(outputDir, { recursive: true })).sort();
|
|
76
|
-
let segmentCount = 0;
|
|
77
|
-
let playlistCount = 0;
|
|
78
|
-
for (const file of files) {
|
|
79
|
-
const relative = file.split('\\').join('/');
|
|
80
|
-
const local = join(outputDir, file);
|
|
81
|
-
const info = await stat(local);
|
|
82
|
-
if (!info.isFile())
|
|
83
|
-
continue;
|
|
84
|
-
if (relative.toLowerCase().endsWith('.m3u8'))
|
|
85
|
-
playlistCount += 1;
|
|
86
|
-
else
|
|
87
|
-
segmentCount += 1;
|
|
88
|
-
const contentType = hlsArtifactContentType(relative);
|
|
89
|
-
await context.write(relative, createReadStream(local), {
|
|
90
|
-
contentLength: info.size,
|
|
91
|
-
...(contentType !== undefined ? { contentType } : {}),
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
entry: HLS_ENTRY_PLAYLIST,
|
|
96
|
-
meta: compactMeta({
|
|
97
|
-
...summary,
|
|
98
|
-
segmentCount,
|
|
99
|
-
playlistCount,
|
|
100
|
-
targetDuration: this.targetDuration,
|
|
101
|
-
}),
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/** Drop `undefined` values so the persisted meta round-trips identically through JSON stores. */
|
|
107
|
-
export function compactMeta(meta) {
|
|
108
|
-
return Object.fromEntries(Object.entries(meta).filter(([, value]) => value !== undefined));
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=hls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hls.js","sourceRoot":"","sources":["../../../src/transformers/hls.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,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAqBlD;;;;;GAKG;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,YAAY,KAAK,SAAS;QAAE,OAAO,UAAU,CAAC;IACjF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAuDD,mFAAmF;AACnF,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAE/C;;;;;;;;;;;;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