0

Problem

I am recording the webm chunks by MediaRecorder at Chrome 83 in Windows 10 and sending these to other computer. These chunks are playing on another Chrome by using Media Source Extension(MSE).

sourceBuffer.appendBuffer(webmChunkData);

Everything works fine between 1 to 1.20 seconds. But after that, the audio/video syncing problem starts. The gap between audio and video is minimal at the moment, but as time increases, the gap also rises.

The weird thing is that we can see the different behaviour on different browsers, let me show this by

enter image description here

Chrome's version is 83+ in almost all operating systems.

Camera can be the problem ?

I think Camera is not the problem as I have dual operating systems Fedora and Windows in the same machine. And webm chunks play fine with the Fedora.

Sample rate can be the problem ?

I doubt this. But when I compare the sample rate used by browsers while playing. chrome://media-internals shows 48000 for both with and without a syncing problem.

enter image description here

Warning message from Chrome

Chrome which has sync problem also shows the below message on chrome://media-internals

enter image description here

Question:

Why there is an audio/video syncing problem when both recording and playing are performed on Chrome browser in Windows 10?

How can I eliminate this syncing problem?

mpx
  • 3,081
  • 2
  • 26
  • 56
Suman Bogati
  • 6,289
  • 1
  • 23
  • 34
  • 1
    Could you try to generate a standalon file from these chunks and check if the drift is already there? Maybe at both ends (emitter and receiver). – Kaiido Jul 07 '20 at 13:34
  • @Kaiido, could you please look at https://bugs.chromium.org/p/chromium/issues/detail?id=1102830#c7 – Suman Bogati Jul 15 '20 at 04:52

1 Answers1

0

I believe I have a workaround for you. The problem seems specific to Chrome + MediaRecorder + VP8, and has nothing to do with MSE or the platform. I have the same issues on Chrome 98 on Mac 12.2.1. Additionally, if you decrease the .start(timeslice) argument, the issue will appear more rapidly and more severely.

However... when I use VP9 the problem does not manifest!

I'm using code like this:

function supportedMimeTypes(): string[] {
  // From least desirable to most desirable
  return [
    // most compatible, but chrome creates bad chunks
    'video/webm;codecs=vp8,opus',
    // works in chrome, firefox falls back to vp8
    'video/webm;codecs=vp9,opus'
  ].filter(
    (m) => MediaRecorder.isTypeSupported(m)
  );
}

const mimeType = supportedMimeTypes().pop();

if (!mimeType) throw new Error("Could not find a supported mime-type");

const recorder = new MediaRecorder(stream, {
  // be sure to use a mimeType with a specific `codecs=` as otherwise
  // chrome completely ignores it and uses video/x-matroska!
  // https://stackoverflow.com/questions/64233494/mediarecorder-does-not-produce-a-valid-webm-file
  mimeType,
});

recorder.start(1000)

The resulting VP9 appears to play in Firefox, and a VP8 recorded in Firefox plays well in Chrome too.

Andrew
  • 3,332
  • 4
  • 31
  • 37