Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting specific sample range without reading whole mp4 file #410

Open
hcglitte opened this issue Oct 21, 2024 · 1 comment
Open

Extracting specific sample range without reading whole mp4 file #410

hcglitte opened this issue Oct 21, 2024 · 1 comment
Labels

Comments

@hcglitte
Copy link

Hi,

I am using FileReader() to read an mp4 file in chunks.
Initially I read enough of the start of the file to load the metadata in order for onReady(info) to be called.

After this I would like to only read a specific byte range of this mp4 source file which corresponds to a given set of samples.
I know the offsets and sizes for the samples, so I can read at the correct location with FileReader().

The problem seems to be that appendBuffer(arrayBuffer) needs to process the whole mp4 file from the start of the file to the end of the file. I am not sure if this assumption is correct?

Preferably I would like to read appendBuffer(arrayBuffer) with arrayBuffer.fileStart = offset at the starting point corresponding to my set of sampels. Then I would imagine that onSamples is called with the samples I have "requested".

Is there any way to achieve this? In this case, how can I do it?

@DenizUgur
Copy link
Member

Hi @hcglitte, I'm trying to understand your issue, so if I miss something, please let me know. For starters, there's no guarantee that onReady will be called at the beginning of the file. The metadata (i.e., moov) doesn't have to be at the beginning of the file. So, it's expected that arrayBuffer wants the entire file.

Therefore, there is no official way to get around that (see the relevant code below). However, you could append zeros before and after your samples to trick MP4Box.js into extracting your samples. But then, why not just use the offset and size information you already have?

mp4box.js/src/isofile.js

Lines 132 to 138 in 57463b4

if (this.hasIncompleteMdat && this.hasIncompleteMdat()) {
if (this.processIncompleteMdat()) {
continue;
} else {
return;
}
} else {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants