23 / resumable.js

A JavaScript library for providing multiple simultaneous, stable, fault-tolerant and resumable/restartable uploads via the HTML5 File API.
MIT License
4.65k stars 611 forks source link

re-combine the mp4 chunks results in a not-playable file #607

Closed qiaohaojie closed 2 years ago

qiaohaojie commented 2 years ago

Hi,

I am stuck on a problem and hope can find some insights here.

I plan to use ResumableJS to upload a large mp4 (1GB). Firstly, split the video/mp4 file into smaller chunks and upload to a server. Then, on the server side, I re-combine those chunks back to a single mp4 file with binary contention.

I would expect it should work as I merely split and re-combine a single large mp4 file. However, in my current project, for small size (<=250 MB) it seems working fine. But for large mp4 (>=800 MB), the re-combined video is not able to play in VLC. And I am pretty sure the original file is fine. Even the file size is the same. But the re-combined video cannot play.

Just wondering do you have any idea what might go wrong?

Regards, George

qiaohaojie commented 2 years ago

Finally, I solved my problem. If anyone hits a similar problem, you may try the same way I used.

In ResumableJS.js (version 1.0), line 57, the code says method:'multipart'. In most cases, it is fine, especially for text based data. However, for mp4, it is not the best option for the server side to parse the form/multipart binary properly. At least in my case, the server-side multipart parser I used has some issues to extract the binary properly. For small mp4, the parser seems working fine. However, for large mp4 file (1GB+), it often ended up with a un-playable mp4 file after merging. This is also related to the underlying form/multipart encoding, which is utf-8 by default.

In my case, I changed method:'multipart' to method:'octet'. This is to post chunks as octet-stream instead of multipart form data. This also simplifies the serverside logic. Now, I just need to binary concat the chunks and not to worry about parsing multipart form data anymore. Tested with 1GB+ mp4 files and pdf files. All working fine.

764653880 commented 2 weeks ago

1.