chrisguttandin / extendable-media-recorder

An extendable drop-in replacement for the native MediaRecorder.
MIT License
272 stars 13 forks source link

Manually specify channelCount #644

Closed Red-mar closed 3 years ago

Red-mar commented 3 years ago

Hey,

I've been using the recorder on Chrome and it works very well! However when running on Firefox it seems the channel count for the recording is always set to 2. I tried to add the channelCount constraint to the stream and I can see that I can set it to 1 there. But when I check the recording it is still in stereo. This happens with both the 'audio/wav' and 'audio/webm' mimetype. Do you know why this might happen?

Thank you for your time

chrisguttandin commented 3 years ago

Hi @Red-mar, thanks for raising this issue.

The problem is that Firefox (and Safari) don't expose a channelCount property as part of the settings of an MediaStreamTrack. Therefore I just not implemented any channelCount handling so far. :-( However I changed that now. The implementation now checks if the property is there and if not it will fallback to 2.

That way you can overwrite the channelCount in your code to make the MediaRecorder pick the right number.

If you have a MediaStream with one audio track you can augment the settings like this:

const [firstAudioTrack] = mediaStream.getAudioTracks();
const channelCount = 1;

if (firstAudioTrack.getSettings().channelCount === undefined) {
    firstAudioTrack.getSettings = ((getSettings) => () => ({
        channelCount,
        ...getSettings.call(firstAudioTrack)
    }))(firstAudioTrack.getSettings);
}