@editframe/assets 0.12.0-beta.1 → 0.12.0-beta.2
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/MP4File.js +5 -3
- package/dist/tasks/generateTrack.js +17 -1
- package/package.json +1 -1
- package/src/tasks/generateTrack.ts +21 -1
package/dist/MP4File.js
CHANGED
|
@@ -123,14 +123,16 @@ class MP4File extends MP4Box.ISOFile {
|
|
|
123
123
|
if (trak.nextSample >= trak.samples.length) {
|
|
124
124
|
trackInfoForFrag.complete = true;
|
|
125
125
|
}
|
|
126
|
-
log(
|
|
127
|
-
`Yielding fragment #${trackInfoForFrag.index} for track=${fragTrak.id}`
|
|
128
|
-
);
|
|
129
126
|
const startSample = fragmentStartSamples[fragTrak.id];
|
|
130
127
|
const endSample = trak.samples[trak.nextSample - 1];
|
|
131
128
|
if (!startSample || !endSample) {
|
|
132
129
|
throw new Error("startSample or endSample is undefined");
|
|
133
130
|
}
|
|
131
|
+
log(
|
|
132
|
+
`Yielding fragment #${trackInfoForFrag.index} for track=${fragTrak.id}`,
|
|
133
|
+
`startTime=${startSample.cts}`,
|
|
134
|
+
`endTime=${endSample.cts + endSample.duration}`
|
|
135
|
+
);
|
|
134
136
|
yield {
|
|
135
137
|
track: fragTrak.id,
|
|
136
138
|
segment: trackInfoForFrag.index,
|
|
@@ -15,9 +15,25 @@ const generateTrackFromPath = async (absolutePath, trackId) => {
|
|
|
15
15
|
readStream.pipe(mp4FileWritable(mp4File));
|
|
16
16
|
(async () => {
|
|
17
17
|
try {
|
|
18
|
+
let bytesWritten = 0;
|
|
18
19
|
for await (const fragment of mp4File.fragmentIterator()) {
|
|
20
|
+
log("Writing fragment", fragment);
|
|
19
21
|
if (fragment.track === trackId) {
|
|
20
|
-
trackStream.write(
|
|
22
|
+
const written = trackStream.write(
|
|
23
|
+
Buffer.from(fragment.data),
|
|
24
|
+
"binary"
|
|
25
|
+
);
|
|
26
|
+
if (!written) {
|
|
27
|
+
log(`Waiting for drain for track ${trackId}`);
|
|
28
|
+
await new Promise((resolve) => trackStream.once("drain", resolve));
|
|
29
|
+
}
|
|
30
|
+
bytesWritten += fragment.data.byteLength;
|
|
31
|
+
}
|
|
32
|
+
if (!readStream.readableEnded) {
|
|
33
|
+
await Promise.race([
|
|
34
|
+
new Promise((resolve) => readStream.once("end", resolve)),
|
|
35
|
+
new Promise((resolve) => readStream.once("data", resolve))
|
|
36
|
+
]);
|
|
21
37
|
}
|
|
22
38
|
}
|
|
23
39
|
trackStream.end();
|
package/package.json
CHANGED
|
@@ -24,11 +24,31 @@ export const generateTrackFromPath = async (
|
|
|
24
24
|
// Process fragments as they become available
|
|
25
25
|
(async () => {
|
|
26
26
|
try {
|
|
27
|
+
let bytesWritten = 0;
|
|
27
28
|
for await (const fragment of mp4File.fragmentIterator()) {
|
|
29
|
+
log("Writing fragment", fragment);
|
|
28
30
|
if (fragment.track === trackId) {
|
|
29
|
-
trackStream.write(
|
|
31
|
+
const written = trackStream.write(
|
|
32
|
+
Buffer.from(fragment.data),
|
|
33
|
+
"binary",
|
|
34
|
+
);
|
|
35
|
+
if (!written) {
|
|
36
|
+
log(`Waiting for drain for track ${trackId}`);
|
|
37
|
+
await new Promise((resolve) => trackStream.once("drain", resolve));
|
|
38
|
+
}
|
|
39
|
+
bytesWritten += fragment.data.byteLength;
|
|
40
|
+
}
|
|
41
|
+
// There is a race condition where the mp4file writable doesn't correctly wait for the whole readSTream
|
|
42
|
+
// Waiting for data/end events seems to fix it
|
|
43
|
+
// FIXME: This is a hack, we should fix the root issue in MP4File
|
|
44
|
+
if (!readStream.readableEnded) {
|
|
45
|
+
await Promise.race([
|
|
46
|
+
new Promise((resolve) => readStream.once("end", resolve)),
|
|
47
|
+
new Promise((resolve) => readStream.once("data", resolve)),
|
|
48
|
+
]);
|
|
30
49
|
}
|
|
31
50
|
}
|
|
51
|
+
|
|
32
52
|
trackStream.end();
|
|
33
53
|
} catch (error) {
|
|
34
54
|
trackStream.destroy(error as Error);
|