@editframe/assets 0.7.0-beta.8 → 0.8.0-beta.10

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 (51) hide show
  1. package/dist/EncodedAsset.d.ts +101 -0
  2. package/dist/EncodedAsset.js +564 -0
  3. package/dist/MP4File.d.ts +31 -0
  4. package/dist/{packages/assets/src/Probe.d.ts → Probe.d.ts} +45 -41
  5. package/dist/{packages/assets/src/Probe.js → Probe.js} +54 -5
  6. package/dist/{packages/assets/src/VideoRenderOptions.d.ts → VideoRenderOptions.d.ts} +0 -1
  7. package/dist/{packages/assets/src/idempotentTask.d.ts → idempotentTask.d.ts} +0 -1
  8. package/dist/index.d.ts +9 -0
  9. package/dist/index.js +24 -0
  10. package/dist/{packages/assets/src/md5.d.ts → md5.d.ts} +1 -1
  11. package/dist/{packages/assets/src/md5.js → md5.js} +6 -0
  12. package/dist/memoize.d.ts +2 -0
  13. package/dist/memoize.js +14 -0
  14. package/dist/{packages/assets/src/mp4FileWritable.d.ts → mp4FileWritable.d.ts} +1 -2
  15. package/dist/tasks/cacheImage.d.ts +1 -0
  16. package/dist/tasks/findOrCreateCaptions.d.ts +2 -0
  17. package/dist/tasks/findOrCreateCaptions.js +30 -0
  18. package/dist/tasks/generateTrack.d.ts +4 -0
  19. package/dist/{packages/assets/src/tasks → tasks}/generateTrack.js +26 -23
  20. package/dist/tasks/generateTrackFragmentIndex.d.ts +3 -0
  21. package/dist/{packages/assets/src/tasks → tasks}/generateTrackFragmentIndex.js +12 -6
  22. package/package.json +16 -12
  23. package/src/tasks/cacheImage.ts +1 -1
  24. package/src/tasks/findOrCreateCaptions.ts +18 -11
  25. package/src/tasks/generateTrack.ts +36 -31
  26. package/src/tasks/generateTrackFragmentIndex.ts +16 -9
  27. package/dist/lib/av/MP4File.cjs +0 -187
  28. package/dist/lib/util/execPromise.cjs +0 -6
  29. package/dist/lib/util/execPromise.js +0 -6
  30. package/dist/packages/assets/src/Probe.cjs +0 -224
  31. package/dist/packages/assets/src/VideoRenderOptions.cjs +0 -36
  32. package/dist/packages/assets/src/idempotentTask.cjs +0 -57
  33. package/dist/packages/assets/src/index.cjs +0 -20
  34. package/dist/packages/assets/src/index.d.ts +0 -9
  35. package/dist/packages/assets/src/index.js +0 -20
  36. package/dist/packages/assets/src/md5.cjs +0 -60
  37. package/dist/packages/assets/src/mp4FileWritable.cjs +0 -21
  38. package/dist/packages/assets/src/tasks/cacheImage.cjs +0 -22
  39. package/dist/packages/assets/src/tasks/cacheImage.d.ts +0 -1
  40. package/dist/packages/assets/src/tasks/findOrCreateCaptions.cjs +0 -26
  41. package/dist/packages/assets/src/tasks/findOrCreateCaptions.d.ts +0 -1
  42. package/dist/packages/assets/src/tasks/findOrCreateCaptions.js +0 -26
  43. package/dist/packages/assets/src/tasks/generateTrack.cjs +0 -52
  44. package/dist/packages/assets/src/tasks/generateTrack.d.ts +0 -1
  45. package/dist/packages/assets/src/tasks/generateTrackFragmentIndex.cjs +0 -105
  46. package/dist/packages/assets/src/tasks/generateTrackFragmentIndex.d.ts +0 -1
  47. /package/dist/{lib/av/MP4File.js → MP4File.js} +0 -0
  48. /package/dist/{packages/assets/src/VideoRenderOptions.js → VideoRenderOptions.js} +0 -0
  49. /package/dist/{packages/assets/src/idempotentTask.js → idempotentTask.js} +0 -0
  50. /package/dist/{packages/assets/src/mp4FileWritable.js → mp4FileWritable.js} +0 -0
  51. /package/dist/{packages/assets/src/tasks → tasks}/cacheImage.js +0 -0
@@ -1,224 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_child_process = require("node:child_process");
4
- const node_fs = require("node:fs");
5
- const z = require("zod");
6
- const debug = require("debug");
7
- const execPromise = require("../../../lib/util/execPromise.cjs");
8
- function _interopNamespaceDefault(e) {
9
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
- if (e) {
11
- for (const k in e) {
12
- if (k !== "default") {
13
- const d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: () => e[k]
17
- });
18
- }
19
- }
20
- }
21
- n.default = e;
22
- return Object.freeze(n);
23
- }
24
- const z__namespace = /* @__PURE__ */ _interopNamespaceDefault(z);
25
- const log = debug("ef:assets:probe");
26
- const AudioStreamSchema = z__namespace.object({
27
- index: z__namespace.number(),
28
- codec_name: z__namespace.string(),
29
- codec_long_name: z__namespace.string(),
30
- codec_type: z__namespace.literal("audio"),
31
- codec_tag_string: z__namespace.string(),
32
- codec_tag: z__namespace.string(),
33
- sample_fmt: z__namespace.string(),
34
- sample_rate: z__namespace.string(),
35
- channels: z__namespace.number(),
36
- channel_layout: z__namespace.string(),
37
- bits_per_sample: z__namespace.number(),
38
- initial_padding: z__namespace.number().optional(),
39
- r_frame_rate: z__namespace.string(),
40
- avg_frame_rate: z__namespace.string(),
41
- time_base: z__namespace.string(),
42
- start_pts: z__namespace.number(),
43
- start_time: z__namespace.coerce.number(),
44
- duration_ts: z__namespace.number(),
45
- duration: z__namespace.coerce.number(),
46
- bit_rate: z__namespace.string(),
47
- disposition: z__namespace.record(z__namespace.unknown())
48
- });
49
- const VideoStreamSchema = z__namespace.object({
50
- index: z__namespace.number(),
51
- codec_name: z__namespace.string(),
52
- codec_long_name: z__namespace.string(),
53
- codec_type: z__namespace.literal("video"),
54
- codec_tag_string: z__namespace.string(),
55
- codec_tag: z__namespace.string(),
56
- width: z__namespace.number(),
57
- height: z__namespace.number(),
58
- coded_width: z__namespace.number(),
59
- coded_height: z__namespace.number(),
60
- r_frame_rate: z__namespace.string(),
61
- avg_frame_rate: z__namespace.string(),
62
- time_base: z__namespace.string(),
63
- start_pts: z__namespace.number().optional(),
64
- start_time: z__namespace.coerce.number().optional(),
65
- duration_ts: z__namespace.number().optional(),
66
- duration: z__namespace.coerce.number().optional(),
67
- bit_rate: z__namespace.string().optional(),
68
- disposition: z__namespace.record(z__namespace.unknown())
69
- });
70
- const ProbeFormatSchema = z__namespace.object({
71
- filename: z__namespace.string(),
72
- nb_streams: z__namespace.number(),
73
- nb_programs: z__namespace.number(),
74
- format_name: z__namespace.string(),
75
- format_long_name: z__namespace.string(),
76
- start_time: z__namespace.string().optional(),
77
- duration: z__namespace.string().optional(),
78
- size: z__namespace.string(),
79
- bit_rate: z__namespace.string().optional(),
80
- probe_score: z__namespace.number()
81
- });
82
- const StreamSchema = z__namespace.discriminatedUnion("codec_type", [
83
- AudioStreamSchema,
84
- VideoStreamSchema
85
- ]);
86
- const ProbeSchema = z__namespace.object({
87
- streams: z__namespace.array(StreamSchema),
88
- format: ProbeFormatSchema
89
- });
90
- class Probe {
91
- constructor(absolutePath, rawData) {
92
- this.absolutePath = absolutePath;
93
- this.data = ProbeSchema.parse(rawData);
94
- }
95
- static async probePath(absolutePath) {
96
- const probeCommand = `ffprobe -v error -show_format -show_streams -of json ${absolutePath}`;
97
- log("Probing", probeCommand);
98
- const probeResult = await execPromise.execPromise(probeCommand);
99
- log("Probe result", probeResult.stdout);
100
- log("Probe stderr", probeResult.stderr);
101
- const json = JSON.parse(probeResult.stdout);
102
- return new Probe(absolutePath, json);
103
- }
104
- get audioStreams() {
105
- return this.data.streams.filter(
106
- (stream) => stream.codec_type === "audio"
107
- );
108
- }
109
- get videoStreams() {
110
- return this.data.streams.filter(
111
- (stream) => stream.codec_type === "video"
112
- );
113
- }
114
- get streams() {
115
- return this.data.streams;
116
- }
117
- get format() {
118
- return this.data.format;
119
- }
120
- get mustReencodeAudio() {
121
- return this.audioStreams.some((stream) => stream.codec_name !== "aac");
122
- }
123
- get mustReencodeVideo() {
124
- return false;
125
- }
126
- get mustRemux() {
127
- return this.format.format_name !== "mp4";
128
- }
129
- get hasAudio() {
130
- return this.audioStreams.length > 0;
131
- }
132
- get hasVideo() {
133
- return this.videoStreams.length > 0;
134
- }
135
- get isAudioOnly() {
136
- return this.audioStreams.length > 0 && this.videoStreams.length === 0;
137
- }
138
- get isVideoOnly() {
139
- return this.audioStreams.length === 0 && this.videoStreams.length > 0;
140
- }
141
- get mustProcess() {
142
- return this.mustReencodeAudio || this.mustReencodeVideo || this.mustRemux;
143
- }
144
- get ffmpegAudioOptions() {
145
- if (!this.hasAudio) {
146
- return [];
147
- }
148
- if (this.mustReencodeAudio) {
149
- return [
150
- "-c:a",
151
- "aac",
152
- "-b:a",
153
- "192k"
154
- ];
155
- }
156
- return ["-c:a", "copy"];
157
- }
158
- get ffmpegVideoOptions() {
159
- if (!this.hasVideo) {
160
- return [];
161
- }
162
- if (this.mustReencodeVideo) {
163
- return [
164
- "-c:v",
165
- "h264",
166
- // Filter out SEI NAL units that aren't supported by the webcodecs decoder
167
- "-bsf:v",
168
- "filter_units=remove_types=6",
169
- "-pix_fmt",
170
- "yuv420p"
171
- ];
172
- }
173
- return [
174
- "-c:v",
175
- "copy",
176
- // Filter out SEI NAL units that aren't supported by the webcodecs decoder
177
- "-bsf:v",
178
- "filter_units=remove_types=6"
179
- ];
180
- }
181
- createConformingReadstream() {
182
- if (!this.mustProcess) {
183
- return node_fs.createReadStream(this.absolutePath);
184
- }
185
- const ffmpegConformanceArgs = [
186
- "-i",
187
- this.absolutePath,
188
- ...this.ffmpegAudioOptions,
189
- ...this.ffmpegVideoOptions,
190
- "-f",
191
- "mp4",
192
- "-movflags",
193
- "cmaf+frag_keyframe+empty_moov",
194
- "pipe:1"
195
- ];
196
- log("Running ffmpeg", ffmpegConformanceArgs);
197
- const ffmpegConformer = node_child_process.spawn("ffmpeg", ffmpegConformanceArgs, {
198
- stdio: ["ignore", "pipe", "pipe"]
199
- });
200
- ffmpegConformer.stderr.on("data", (data) => {
201
- log(data.toString());
202
- });
203
- const ffmpegFragmentArgs = [
204
- "-i",
205
- "-",
206
- "-c",
207
- "copy",
208
- "-f",
209
- "mp4",
210
- "-movflags",
211
- "frag_keyframe+empty_moov",
212
- "pipe:1"
213
- ];
214
- log("Running ffmpeg", ffmpegFragmentArgs);
215
- const ffmpegFragmenter = node_child_process.spawn("ffmpeg", ffmpegFragmentArgs, {
216
- stdio: ["pipe", "pipe", "pipe"]
217
- });
218
- ffmpegConformer.stdout.pipe(ffmpegFragmenter.stdin);
219
- return ffmpegFragmenter.stdout;
220
- }
221
- }
222
- exports.AudioStreamSchema = AudioStreamSchema;
223
- exports.Probe = Probe;
224
- exports.VideoStreamSchema = VideoStreamSchema;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const z = require("zod");
4
- const VideoRenderOptions = z.z.object({
5
- mode: z.z.enum(["canvas", "screenshot"]),
6
- strategy: z.z.enum(["v1", "v2"]),
7
- showFrameBox: z.z.boolean().optional(),
8
- encoderOptions: z.z.object({
9
- sequenceNumber: z.z.number(),
10
- keyframeIntervalMs: z.z.number(),
11
- toMs: z.z.number(),
12
- fromMs: z.z.number(),
13
- shouldPadStart: z.z.boolean(),
14
- shouldPadEnd: z.z.boolean(),
15
- alignedFromUs: z.z.number(),
16
- alignedToUs: z.z.number(),
17
- isInitSegment: z.z.boolean(),
18
- noVideo: z.z.boolean().optional(),
19
- noAudio: z.z.boolean().optional(),
20
- video: z.z.object({
21
- width: z.z.number(),
22
- height: z.z.number(),
23
- framerate: z.z.number(),
24
- codec: z.z.string(),
25
- bitrate: z.z.number()
26
- }),
27
- audio: z.z.object({
28
- sampleRate: z.z.number(),
29
- codec: z.z.string(),
30
- numberOfChannels: z.z.number(),
31
- bitrate: z.z.number()
32
- })
33
- }),
34
- fetchHost: z.z.string()
35
- });
36
- exports.VideoRenderOptions = VideoRenderOptions;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_fs = require("node:fs");
4
- const path = require("node:path");
5
- const md5 = require("./md5.cjs");
6
- const debug = require("debug");
7
- const promises = require("node:fs/promises");
8
- const node_stream = require("node:stream");
9
- const idempotentTask = ({
10
- label,
11
- filename,
12
- runner
13
- }) => {
14
- const tasks = {};
15
- return async (rootDir, absolutePath, ...args) => {
16
- const log = debug(`ef:${label}`);
17
- const md5$1 = await md5.md5FilePath(absolutePath);
18
- const cacheDir = path.join(rootDir, ".cache", md5$1);
19
- log(`Cache dir: ${cacheDir}`);
20
- await promises.mkdir(cacheDir, { recursive: true });
21
- const cachePath = path.join(cacheDir, filename(absolutePath, ...args));
22
- const key = cachePath;
23
- if (node_fs.existsSync(cachePath)) {
24
- log(`Returning cached ef:${label} task for ${key}`);
25
- return { cachePath, md5Sum: md5$1 };
26
- }
27
- const maybeTask = tasks[key];
28
- if (maybeTask) {
29
- log(`Returning existing ef:${label} task for ${key}`);
30
- await maybeTask;
31
- return { cachePath, md5Sum: md5$1 };
32
- }
33
- log(`Creating new ef:${label} task for ${key}`);
34
- const task = runner(absolutePath, ...args);
35
- tasks[key] = task;
36
- log(`Awaiting task for ${key}`);
37
- const result = await task;
38
- if (result instanceof node_stream.Readable) {
39
- log(`Piping task for ${key} to cache`);
40
- const writeStream = node_fs.createWriteStream(cachePath);
41
- result.pipe(writeStream);
42
- await new Promise((resolve, reject) => {
43
- result.on("error", reject);
44
- writeStream.on("error", reject);
45
- writeStream.on("finish", resolve);
46
- });
47
- return { cachePath, md5Sum: md5$1 };
48
- }
49
- log(`Writing to ${cachePath}`);
50
- await promises.writeFile(cachePath, result);
51
- return {
52
- md5Sum: md5$1,
53
- cachePath
54
- };
55
- };
56
- };
57
- exports.idempotentTask = idempotentTask;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const Probe = require("./Probe.cjs");
4
- const md5 = require("./md5.cjs");
5
- const generateTrackFragmentIndex = require("./tasks/generateTrackFragmentIndex.cjs");
6
- const generateTrack = require("./tasks/generateTrack.cjs");
7
- const findOrCreateCaptions = require("./tasks/findOrCreateCaptions.cjs");
8
- const cacheImage = require("./tasks/cacheImage.cjs");
9
- const VideoRenderOptions = require("./VideoRenderOptions.cjs");
10
- exports.AudioStreamSchema = Probe.AudioStreamSchema;
11
- exports.Probe = Probe.Probe;
12
- exports.VideoStreamSchema = Probe.VideoStreamSchema;
13
- exports.md5Directory = md5.md5Directory;
14
- exports.md5FilePath = md5.md5FilePath;
15
- exports.md5ReadStream = md5.md5ReadStream;
16
- exports.generateTrackFragmentIndex = generateTrackFragmentIndex.generateTrackFragmentIndex;
17
- exports.generateTrack = generateTrack.generateTrack;
18
- exports.findOrCreateCaptions = findOrCreateCaptions.findOrCreateCaptions;
19
- exports.cacheImage = cacheImage.cacheImage;
20
- exports.VideoRenderOptions = VideoRenderOptions.VideoRenderOptions;
@@ -1,9 +0,0 @@
1
- export { AudioStreamSchema, VideoStreamSchema, Probe } from './Probe';
2
- export type { StreamSchema, TrackSegment, TrackFragmentIndex } from './Probe';
3
- export { md5FilePath, md5Directory, md5ReadStream } from './md5';
4
- export { generateTrackFragmentIndex } from './tasks/generateTrackFragmentIndex';
5
- export { generateTrack } from './tasks/generateTrack';
6
- export { findOrCreateCaptions } from './tasks/findOrCreateCaptions';
7
- export { cacheImage } from './tasks/cacheImage';
8
- export type { TaskResult } from './idempotentTask';
9
- export { VideoRenderOptions } from './VideoRenderOptions';
@@ -1,20 +0,0 @@
1
- import { AudioStreamSchema, Probe, VideoStreamSchema } from "./Probe.js";
2
- import { md5Directory, md5FilePath, md5ReadStream } from "./md5.js";
3
- import { generateTrackFragmentIndex } from "./tasks/generateTrackFragmentIndex.js";
4
- import { generateTrack } from "./tasks/generateTrack.js";
5
- import { findOrCreateCaptions } from "./tasks/findOrCreateCaptions.js";
6
- import { cacheImage } from "./tasks/cacheImage.js";
7
- import { VideoRenderOptions } from "./VideoRenderOptions.js";
8
- export {
9
- AudioStreamSchema,
10
- Probe,
11
- VideoRenderOptions,
12
- VideoStreamSchema,
13
- cacheImage,
14
- findOrCreateCaptions,
15
- generateTrack,
16
- generateTrackFragmentIndex,
17
- md5Directory,
18
- md5FilePath,
19
- md5ReadStream
20
- };
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_fs = require("node:fs");
4
- const promises = require("node:fs/promises");
5
- const path = require("node:path");
6
- const crypto = require("node:crypto");
7
- const ora = require("ora");
8
- async function md5Directory(directory, spinner) {
9
- const shouldEndSpinner = !spinner;
10
- spinner ||= ora("⚡️ Calculating MD5").start();
11
- spinner.suffixText = directory;
12
- const files = await promises.readdir(directory, { withFileTypes: true });
13
- const hashes = await Promise.all(
14
- files.map(async (file) => {
15
- const filePath = path.join(directory, file.name);
16
- if (file.isDirectory()) {
17
- return md5Directory(filePath, spinner);
18
- }
19
- spinner.suffixText = filePath;
20
- return md5FilePath(filePath);
21
- })
22
- );
23
- const hash = crypto.createHash("md5");
24
- for (const fileHash of hashes) {
25
- hash.update(fileHash);
26
- }
27
- if (shouldEndSpinner) {
28
- spinner.succeed("MD5 calculated");
29
- spinner.suffixText = directory;
30
- }
31
- return addDashesToUUID(hash.digest("hex"));
32
- }
33
- async function md5FilePath(filePath) {
34
- const readStream = node_fs.createReadStream(filePath);
35
- return md5ReadStream(readStream);
36
- }
37
- function md5ReadStream(readStream) {
38
- return new Promise((resolve, reject) => {
39
- const hash = crypto.createHash("md5");
40
- readStream.on("data", (data) => {
41
- hash.update(data);
42
- });
43
- readStream.on("error", reject);
44
- readStream.on("end", () => {
45
- resolve(addDashesToUUID(hash.digest("hex")));
46
- });
47
- });
48
- }
49
- function addDashesToUUID(uuidWithoutDashes) {
50
- if (uuidWithoutDashes.length !== 32) {
51
- throw new Error("Invalid UUID without dashes. Expected 32 characters.");
52
- }
53
- return (
54
- // biome-ignore lint/style/useTemplate: using a template makes a long line
55
- uuidWithoutDashes.slice(0, 8) + "-" + uuidWithoutDashes.slice(8, 12) + "-" + uuidWithoutDashes.slice(12, 16) + "-" + uuidWithoutDashes.slice(16, 20) + "-" + uuidWithoutDashes.slice(20, 32)
56
- );
57
- }
58
- exports.md5Directory = md5Directory;
59
- exports.md5FilePath = md5FilePath;
60
- exports.md5ReadStream = md5ReadStream;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_stream = require("node:stream");
4
- const mp4FileWritable = (mp4File) => {
5
- let arrayBufferStart = 0;
6
- return new node_stream.Writable({
7
- write: (chunk, _encoding, callback) => {
8
- const mp4BoxBuffer = chunk.buffer;
9
- mp4BoxBuffer.fileStart = arrayBufferStart;
10
- arrayBufferStart += chunk.length;
11
- mp4File.appendBuffer(mp4BoxBuffer, false);
12
- callback();
13
- },
14
- final: (callback) => {
15
- mp4File.flush();
16
- mp4File.processSamples(true);
17
- callback();
18
- }
19
- });
20
- };
21
- exports.mp4FileWritable = mp4FileWritable;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const idempotentTask = require("../idempotentTask.cjs");
4
- const node_fs = require("node:fs");
5
- const path = require("node:path");
6
- const cacheImageTask = idempotentTask.idempotentTask({
7
- label: "image",
8
- filename: (absolutePath) => path.basename(absolutePath),
9
- runner: async (absolutePath) => {
10
- return node_fs.createReadStream(absolutePath);
11
- }
12
- });
13
- const cacheImage = async (cacheRoot, absolutePath) => {
14
- try {
15
- return await cacheImageTask(cacheRoot, absolutePath);
16
- } catch (error) {
17
- console.error(error);
18
- console.trace("Error generating track fragment index", error);
19
- throw error;
20
- }
21
- };
22
- exports.cacheImage = cacheImage;
@@ -1 +0,0 @@
1
- export declare const cacheImage: (cacheRoot: string, absolutePath: string) => Promise<import('../idempotentTask').TaskResult>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const execPromise = require("../../../../lib/util/execPromise.cjs");
4
- const idempotentTask = require("../idempotentTask.cjs");
5
- const debug = require("debug");
6
- const path = require("node:path");
7
- const log = debug("ef:generateCaptions");
8
- const generateCaptionData = idempotentTask.idempotentTask({
9
- label: "captions",
10
- filename: (absolutePath) => `${path.basename(absolutePath)}.captions.json`,
11
- runner: async (absolutePath) => {
12
- const command = `whisper_timestamped --language en --efficient --output_format vtt ${absolutePath}`;
13
- log(`Running command: ${command}`);
14
- const { stdout } = await execPromise.execPromise(command);
15
- return stdout;
16
- }
17
- });
18
- const findOrCreateCaptions = async (cacheRoot, absolutePath) => {
19
- try {
20
- return await generateCaptionData(cacheRoot, absolutePath);
21
- } catch (error) {
22
- console.trace("Error finding or creating captions", error);
23
- throw error;
24
- }
25
- };
26
- exports.findOrCreateCaptions = findOrCreateCaptions;
@@ -1 +0,0 @@
1
- export declare const findOrCreateCaptions: (cacheRoot: string, absolutePath: string) => Promise<import('../idempotentTask').TaskResult>;
@@ -1,26 +0,0 @@
1
- import { execPromise } from "../../../../lib/util/execPromise.js";
2
- import { idempotentTask } from "../idempotentTask.js";
3
- import debug from "debug";
4
- import { basename } from "node:path";
5
- const log = debug("ef:generateCaptions");
6
- const generateCaptionData = idempotentTask({
7
- label: "captions",
8
- filename: (absolutePath) => `${basename(absolutePath)}.captions.json`,
9
- runner: async (absolutePath) => {
10
- const command = `whisper_timestamped --language en --efficient --output_format vtt ${absolutePath}`;
11
- log(`Running command: ${command}`);
12
- const { stdout } = await execPromise(command);
13
- return stdout;
14
- }
15
- });
16
- const findOrCreateCaptions = async (cacheRoot, absolutePath) => {
17
- try {
18
- return await generateCaptionData(cacheRoot, absolutePath);
19
- } catch (error) {
20
- console.trace("Error finding or creating captions", error);
21
- throw error;
22
- }
23
- };
24
- export {
25
- findOrCreateCaptions
26
- };
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const idempotentTask = require("../idempotentTask.cjs");
4
- const MP4File = require("../../../../lib/av/MP4File.cjs");
5
- const debug = require("debug");
6
- const mp4FileWritable = require("../mp4FileWritable.cjs");
7
- const node_stream = require("node:stream");
8
- const path = require("node:path");
9
- const Probe = require("../Probe.cjs");
10
- const generateTrackTask = idempotentTask.idempotentTask({
11
- label: "track",
12
- filename: (absolutePath, trackId) => `${path.basename(absolutePath)}.track-${trackId}.mp4`,
13
- runner: async (absolutePath, trackId) => {
14
- const log = debug("ef:generateTrackFragment");
15
- const probe = await Probe.Probe.probePath(absolutePath);
16
- const readStream = probe.createConformingReadstream();
17
- const mp4File = new MP4File.MP4File();
18
- log(`Generating track fragment index for ${absolutePath}`);
19
- readStream.pipe(mp4FileWritable.mp4FileWritable(mp4File));
20
- await new Promise((resolve, reject) => {
21
- readStream.on("end", resolve);
22
- readStream.on("error", reject);
23
- });
24
- const trackStream = new node_stream.PassThrough();
25
- for await (const fragment of mp4File.fragmentIterator()) {
26
- if (fragment.track !== trackId) {
27
- continue;
28
- }
29
- trackStream.write(Buffer.from(fragment.data), "binary");
30
- }
31
- trackStream.end();
32
- return trackStream;
33
- }
34
- });
35
- const generateTrack = async (cacheRoot, absolutePath, url) => {
36
- try {
37
- const trackId = new URL(
38
- `http://localhost${url}` ?? "bad-url"
39
- ).searchParams.get("trackId");
40
- if (trackId === null) {
41
- throw new Error(
42
- "No trackId provided. IT must be specified in the query string: ?trackId=0"
43
- );
44
- }
45
- return await generateTrackTask(cacheRoot, absolutePath, Number(trackId));
46
- } catch (error) {
47
- console.error(error);
48
- console.trace("Error generating track fragment index", error);
49
- throw error;
50
- }
51
- };
52
- exports.generateTrack = generateTrack;
@@ -1 +0,0 @@
1
- export declare const generateTrack: (cacheRoot: string, absolutePath: string, url: string) => Promise<import('../idempotentTask').TaskResult>;