gpac / mp4box.js

JavaScript version of GPAC's MP4Box tool
https://gpac.github.io/mp4box.js/
BSD 3-Clause "New" or "Revised" License
1.95k stars 330 forks source link

Too much memory for large files #393

Open tiuvi opened 6 months ago

tiuvi commented 6 months ago

Library uses too much memory for large files

image

In this case the file weighs 500 MB and uses 700 MB, I think the memory could be lowered to 0 using this api.

https://developer.mozilla.org/en-US/docs/Web/API/File_System_API

This api lets you create a virtual file where you can save the data and then obtain it through the demux by reading the file.

I have already made progress in demux webm, ffmpeg and webCodecs by reducing memory. I would only be missing the mp4 demuxer.

I don't know exactly where the memory expenditure is, it could be when reading the file that everything is stored in memory and then reading it to process it or it could be when creating the chunks that it stores them in memory and that is why it uses so much memory.

In either case you could use this api to read directly from the file.

image

If you use it, I recommend using this one, which is compatible with webview https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle

image

You only need to save the file's offsets and then read them.

Someone who knows the library well could implement it quickly, greetings.

rbouqueau commented 6 months ago

Hi there, I think you'll have more chance if you write in English. Thanks