yusitnikov / fix-webm-duration

navigator.mediaDevices.getUserMedia + MediaRecorder create WEBM files without duration metadata. This library appends missing metadata section right to the file blob.
MIT License
259 stars 50 forks source link

Allow pre-allocating bytes for eventual Duration section? #17

Open somebee opened 1 year ago

somebee commented 1 year ago

Great library! It would be very nice if it was possible to run the first chunk received from MediaRecorder through this library to get a blob that has pre-allocated place for duration (and possibly cues?). This way, the final file would be the exact same length++ as the raw blob from MediaRecorder, but with a certain byte-range at the start replaced (where we inject the cues).

Then, after receiving the last chunk it should be possible to run the whole blob through library and essentially just replace a chunk of the start of the file?

See functionality from webm-muxer.js:

The constructor takes an optional options object with a single property, metadata_reserve_size. This is the number of extra bytes to leave at the start of the file for the header so it can be fixed up after writing stops. The default is 1024, which is enough to rewrite the header. WebMWriter will try to put the cues into this space too if they’re small enough, otherwise they’re appended to the end of the file, after the track data. You can increase metadata_reserve_size to leave more space for the cues at the start of the file, but remember the longer the recording, the larger the cues section will be.