You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are trying to build an app with support for streaming fragmented mp4's directly from the server. In order to do so we are looking to segment an mp4 during the upload. The goal is to get a segmented byteArray from a readable stream. We currently have the following, but the moov box is incorrect and we can't get the audio track included.
Any clues, where to look? The documentation only got us so far, and the library has many more features, so we are confident is has to be possible in some way.
let segmentedBytes: Uint8Array;
mp4File.onError = function (e: unknown) {
reject(e);
};
mp4File.onReady = function (info: { tracks: { id: number; nb_samples: number }[] }) {
// TODO: Fix audio track.. it's not working
// for (var i = 0; i < info.tracks.length; i++) {
for (var i = 0; i < 1; i++) {
var track = info.tracks[i];
mp4File.setSegmentOptions(track.id, null, {
nb_samples: info.tracks[i].nb_samples,
});
}
const initSegment: { id: number; buffer: ArrayBuffer }[] =
mp4File.initializeSegmentation();
segmentedBytes = mergeByteArrays(initSegment.map((s) => new Uint8Array(s.buffer)));
mp4File.start();
};
mp4File.onSegment = function (
id: number,
user: unknown,
buffer: ArrayBuffer,
sampleNum: number,
is_last: boolean
) {
console.debug(
`Recieved ${
is_last ? ' last' : ''
} segment on track ${id} with sample up to ${sampleNum}`
);
segmentedBytes = mergeByteArrays([
...(segmentedBytes ? [segmentedBytes] : []),
new Uint8Array(buffer),
]);
if (is_last) {
console.log({ mp4File });
resolve(segmentedBytes);
}
};
var offset = 0;
var reader = file.stream().getReader();
const getNextChunk = ({ done, value }: ReadableStreamReadResult<Uint8Array>): any => {
if (done) {
mp4File.stop();
mp4File.flush();
return;
}
const block: any = value.buffer;
block.fileStart = offset;
offset += value.length;
mp4File.appendBuffer(block);
return reader.read().then(getNextChunk);
};
reader.read().then(getNextChunk);```
The text was updated successfully, but these errors were encountered:
stef-coenen
changed the title
Segmenting from a buffer, and saving it back into a buffer
Segmenting from a buffer back into a buffer for upload
Apr 6, 2023
We are trying to build an app with support for streaming fragmented mp4's directly from the server. In order to do so we are looking to segment an mp4 during the upload. The goal is to get a segmented byteArray from a readable stream. We currently have the following, but the moov box is incorrect and we can't get the audio track included.
Any clues, where to look? The documentation only got us so far, and the library has many more features, so we are confident is has to be possible in some way.
The text was updated successfully, but these errors were encountered: