@editframe/assets 0.7.0-beta.11 → 0.7.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EncodedAsset.d.ts +102 -0
- package/dist/EncodedAsset.js +564 -0
- package/dist/MP4File.d.ts +31 -0
- package/dist/{packages/assets/src/Probe.d.ts → Probe.d.ts} +45 -41
- package/dist/{packages/assets/src/Probe.js → Probe.js} +54 -5
- package/dist/index.d.ts +9 -0
- package/dist/{packages/assets/src/index.js → index.js} +6 -3
- package/dist/memoize.d.ts +2 -0
- package/dist/memoize.js +14 -0
- package/dist/{packages/assets/src/mp4FileWritable.d.ts → mp4FileWritable.d.ts} +1 -1
- package/dist/tasks/cacheImage.d.ts +1 -0
- package/dist/tasks/findOrCreateCaptions.d.ts +2 -0
- package/dist/tasks/findOrCreateCaptions.js +30 -0
- package/dist/tasks/generateTrack.d.ts +5 -0
- package/dist/{packages/assets/src/tasks → tasks}/generateTrack.js +26 -23
- package/dist/tasks/generateTrackFragmentIndex.d.ts +4 -0
- package/dist/{packages/assets/src/tasks → tasks}/generateTrackFragmentIndex.js +12 -6
- package/package.json +13 -10
- package/src/tasks/cacheImage.ts +1 -1
- package/src/tasks/findOrCreateCaptions.ts +18 -11
- package/src/tasks/generateTrack.ts +36 -31
- package/src/tasks/generateTrackFragmentIndex.ts +16 -9
- package/dist/lib/av/MP4File.cjs +0 -187
- package/dist/lib/util/execPromise.cjs +0 -6
- package/dist/lib/util/execPromise.js +0 -6
- package/dist/packages/assets/src/Probe.cjs +0 -224
- package/dist/packages/assets/src/VideoRenderOptions.cjs +0 -36
- package/dist/packages/assets/src/idempotentTask.cjs +0 -57
- package/dist/packages/assets/src/index.cjs +0 -20
- package/dist/packages/assets/src/index.d.ts +0 -9
- package/dist/packages/assets/src/md5.cjs +0 -60
- package/dist/packages/assets/src/mp4FileWritable.cjs +0 -21
- package/dist/packages/assets/src/tasks/cacheImage.cjs +0 -22
- package/dist/packages/assets/src/tasks/cacheImage.d.ts +0 -1
- package/dist/packages/assets/src/tasks/findOrCreateCaptions.cjs +0 -26
- package/dist/packages/assets/src/tasks/findOrCreateCaptions.d.ts +0 -1
- package/dist/packages/assets/src/tasks/findOrCreateCaptions.js +0 -26
- package/dist/packages/assets/src/tasks/generateTrack.cjs +0 -52
- package/dist/packages/assets/src/tasks/generateTrack.d.ts +0 -1
- package/dist/packages/assets/src/tasks/generateTrackFragmentIndex.cjs +0 -105
- package/dist/packages/assets/src/tasks/generateTrackFragmentIndex.d.ts +0 -1
- /package/dist/{lib/av/MP4File.js → MP4File.js} +0 -0
- /package/dist/{packages/assets/src/VideoRenderOptions.d.ts → VideoRenderOptions.d.ts} +0 -0
- /package/dist/{packages/assets/src/VideoRenderOptions.js → VideoRenderOptions.js} +0 -0
- /package/dist/{packages/assets/src/idempotentTask.d.ts → idempotentTask.d.ts} +0 -0
- /package/dist/{packages/assets/src/idempotentTask.js → idempotentTask.js} +0 -0
- /package/dist/{packages/assets/src/md5.d.ts → md5.d.ts} +0 -0
- /package/dist/{packages/assets/src/md5.js → md5.js} +0 -0
- /package/dist/{packages/assets/src/mp4FileWritable.js → mp4FileWritable.js} +0 -0
- /package/dist/{packages/assets/src/tasks → tasks}/cacheImage.js +0 -0
|
@@ -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,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>;
|
|
@@ -1,105 +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 path = require("node:path");
|
|
8
|
-
const Probe = require("../Probe.cjs");
|
|
9
|
-
const generateTrackFragmentIndexFromPath = async (absolutePath) => {
|
|
10
|
-
const log = debug("ef:generateTrackFragment");
|
|
11
|
-
const probe = await Probe.Probe.probePath(absolutePath);
|
|
12
|
-
const readStream = probe.createConformingReadstream();
|
|
13
|
-
const mp4File = new MP4File.MP4File();
|
|
14
|
-
log(`Generating track fragment index for ${absolutePath}`);
|
|
15
|
-
readStream.pipe(mp4FileWritable.mp4FileWritable(mp4File));
|
|
16
|
-
await new Promise((resolve, reject) => {
|
|
17
|
-
readStream.on("end", resolve);
|
|
18
|
-
readStream.on("error", reject);
|
|
19
|
-
});
|
|
20
|
-
const trackFragmentIndexes = {};
|
|
21
|
-
const trackByteOffsets = {};
|
|
22
|
-
for await (const fragment of mp4File.fragmentIterator()) {
|
|
23
|
-
const track = mp4File.getInfo().tracks.find((track2) => track2.id === fragment.track);
|
|
24
|
-
if (!track) {
|
|
25
|
-
throw new Error("Track not found");
|
|
26
|
-
}
|
|
27
|
-
if (fragment.segment === "init") {
|
|
28
|
-
trackByteOffsets[fragment.track] = fragment.data.byteLength;
|
|
29
|
-
if (track?.type === "video") {
|
|
30
|
-
const videoTrack = mp4File.getInfo().videoTracks.find((track2) => track2.id === fragment.track);
|
|
31
|
-
if (!videoTrack) {
|
|
32
|
-
throw new Error("Video track not found");
|
|
33
|
-
}
|
|
34
|
-
trackFragmentIndexes[fragment.track] = {
|
|
35
|
-
track: fragment.track,
|
|
36
|
-
type: "video",
|
|
37
|
-
width: videoTrack.video.width,
|
|
38
|
-
height: videoTrack.video.height,
|
|
39
|
-
timescale: track.timescale,
|
|
40
|
-
sample_count: videoTrack.nb_samples,
|
|
41
|
-
duration: 0,
|
|
42
|
-
initSegment: {
|
|
43
|
-
offset: 0,
|
|
44
|
-
size: fragment.data.byteLength
|
|
45
|
-
},
|
|
46
|
-
segments: []
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (track?.type === "audio") {
|
|
50
|
-
const audioTrack = mp4File.getInfo().audioTracks.find((track2) => track2.id === fragment.track);
|
|
51
|
-
if (!audioTrack) {
|
|
52
|
-
throw new Error("Audio track not found");
|
|
53
|
-
}
|
|
54
|
-
trackFragmentIndexes[fragment.track] = {
|
|
55
|
-
track: fragment.track,
|
|
56
|
-
type: "audio",
|
|
57
|
-
channel_count: audioTrack.audio.channel_count,
|
|
58
|
-
sample_rate: audioTrack.audio.sample_rate,
|
|
59
|
-
sample_size: audioTrack.audio.sample_size,
|
|
60
|
-
sample_count: audioTrack.nb_samples,
|
|
61
|
-
timescale: track.timescale,
|
|
62
|
-
duration: 0,
|
|
63
|
-
initSegment: {
|
|
64
|
-
offset: 0,
|
|
65
|
-
size: fragment.data.byteLength
|
|
66
|
-
},
|
|
67
|
-
segments: []
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
const fragmentIndex = trackFragmentIndexes[fragment.track];
|
|
72
|
-
if (trackByteOffsets[fragment.track] === void 0) {
|
|
73
|
-
throw new Error("Fragment index not found");
|
|
74
|
-
}
|
|
75
|
-
if (!fragmentIndex) {
|
|
76
|
-
throw new Error("Fragment index not found");
|
|
77
|
-
}
|
|
78
|
-
fragmentIndex.duration += fragment.duration;
|
|
79
|
-
fragmentIndex.segments.push({
|
|
80
|
-
cts: fragment.cts,
|
|
81
|
-
dts: fragment.dts,
|
|
82
|
-
duration: fragment.duration,
|
|
83
|
-
// biome-ignore lint/style/noNonNullAssertion: This was checked above
|
|
84
|
-
offset: trackByteOffsets[fragment.track],
|
|
85
|
-
size: fragment.data.byteLength
|
|
86
|
-
});
|
|
87
|
-
trackByteOffsets[fragment.track] += fragment.data.byteLength;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return JSON.stringify(trackFragmentIndexes, null, 2);
|
|
91
|
-
};
|
|
92
|
-
const generateTrackFragmentIndexTask = idempotentTask.idempotentTask({
|
|
93
|
-
label: "trackFragmentIndex",
|
|
94
|
-
filename: (absolutePath) => `${path.basename(absolutePath)}.tracks.json`,
|
|
95
|
-
runner: generateTrackFragmentIndexFromPath
|
|
96
|
-
});
|
|
97
|
-
const generateTrackFragmentIndex = async (cacheRoot, absolutePath) => {
|
|
98
|
-
try {
|
|
99
|
-
return await generateTrackFragmentIndexTask(cacheRoot, absolutePath);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.trace("Error generating track fragment index", error);
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
exports.generateTrackFragmentIndex = generateTrackFragmentIndex;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const generateTrackFragmentIndex: (cacheRoot: string, absolutePath: string) => Promise<import('../idempotentTask').TaskResult>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|