Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JoshuaeKaiser opened this issue Feb 24, 2021 · 5 comments

Comments

@JoshuaeKaiser
Copy link

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.

@chrisguttandin
Copy link
Owner

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

@guest271314
Copy link

@mysteriousHerb
Copy link

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?

@guest271314
Copy link

@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.

@mysteriousHerb
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants