chrisguttandin/extendable-media-recorder

Timescliced chunks dont contain wav headers, only the first chunk does (ondataavailable)

Opened this issue ยท 5 comments

Hi There,

Sorry to be a pain. Quick question. I am looking to basically process each timesliced chunk as its own audio file and not join all the chunks toguether at the end of the recording.

I have noticed the first chunk saves perfectly (As i asume it has the correct WAV headers), but any chunk after that is corrupted.

Is there a way I can specify that each timesliced chunk contain headers, or a way I can retrospectively add the headers to the 2nd, 3rd, .... etc chunks ?

Appreicate any help on this.

Hi @JoshuaeKaiser,

that's actually a feature and not a bug. :-) The native MediaRecorder also produces chunks that can only be used when stitched together.

https://w3c.github.io/mediacapture-record/#dom-mediarecorder-start

When multiple Blobs are returned (because of timeslice or requestData()), the individual Blobs need not be playable, but the combination of all the Blobs from a completed recording MUST be playable.

But it should be fairly easy to add the appropriate header to each chunk for wav files. When provided a timeslice value the wav header generated by this library sets the file length to the largest possible value. If that works for you, you can just copy that header and prepend it to each consecutive chunk. The first 44 bytes of the first chunk contain that header.

https://github.com/chrisguttandin/extendable-media-recorder-wav-encoder-worker/blob/master/src/functions/encode-header.ts#L9

Hi @JoshuaeKaiser,

that's actually a feature and not a bug. :-) The native MediaRecorder also produces chunks that can only be used when stitched together.

https://w3c.github.io/mediacapture-record/#dom-mediarecorder-start

When multiple Blobs are returned (because of timeslice or requestData()), the individual Blobs need not be playable, but the combination of all the Blobs from a completed recording MUST be playable.

But it should be fairly easy to add the appropriate header to each chunk for wav files. When provided a timeslice value the wav header generated by this library sets the file length to the largest possible value. If that works for you, you can just copy that header and prepend it to each consecutive chunk. The first 44 bytes of the first chunk contain that header.

https://github.com/chrisguttandin/extendable-media-recorder-wav-encoder-worker/blob/master/src/functions/encode-header.ts#L9

Hi, on a similar vein, is it possible to know whats the length of header for webm audio file so I can also make every chunks playable?

@herbzhao You can encode each chunk with WebCodecs AudioEncoder and playback each chunk with Media Source Extensions appendEncodedChunks(), or deserialize to WAV and playback each chunk, see https://github.com/guest271314/WebCodecsOpusRecorder.

@herbzhao You can encode each chunk with WebCodecs AudioEncoder and playback each chunk with Media Source Extensions appendEncodedChunks(), or deserialize to WAV and playback each chunk, see https://github.com/guest271314/WebCodecsOpusRecorder.

Thanks. I took the lazy approach evetually by prepending all the previous chunks and then slice them in my backend, since i will have all the chunks available anyway.