gpac / mp4box.js

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

Question / Feature Request: Write un-fragmented MP4 #259

Open rlamarche opened 2 years ago

rlamarche commented 2 years ago

Hi, thank you for this awesome tool. I wonder if it is possible to write an unfragmented MP4 file ? With the whole moov atom at start, followed by the mdat data. I'm already able to read many unfragmented mp4 files, and merge them to a single one, then save it. The file is playable on my computer, in chrome (android), in VLC on android, but not on the android's native media player.

So I'm looking to make the exact same thing as ffmpeg does with the "concat filter" from ffmpeg. I'm almost ok (I had to made a small patch to be able to get the avcC atom), but I want the output file to be the most "compatible" as possible. At the moment I'm able to create a merged mp4 file as blob with the size of 1.2 GB in an android hybrid application (based on capacitorjs). The input mp4 segments are unfragmented mp4 files of 1 min each saved in an indexed DB as blob. It works perfectly well.

Thank you.

Note :

My current algorithm is to parse the moov atom of the whole files, then emit all fragmented segments, but discarding the data (to prevent memory usage). At the end I have the correct moov atoms, then I re-read / send all the files and write a whole file starting with the moov atoms, then the ordered pair moof (pre-generated in memory) and mdat. It works on Android, in chrome and electron.

cconcolato commented 2 years ago

Thank you for the details. I was not aware that Android's native media player did not support fragmented mp4. It is not possible at the moment to write unfragmented mp4. It's not technically impossible but not coded yet.