node-webrtc / node-webrtc-examples

MediaStream and RTCDataChannel examples using node-webrtc
508 stars 161 forks source link

Getting bad quality sound in video-compositing example. #14

Closed Glunky closed 4 years ago

Glunky commented 4 years ago

Hi! So i opened video-compositing example and it works great. But then i wanted to add sound functionality like in documentation. So i just puted those pieces of code like bellow:

  const videoSource = new RTCVideoSource();
  const audioSource = new RTCAudioSource();
  const videoTrack = videoSource.createTrack();
  const audioTrack = audioSource.createTrack();
  const videoTransceiver = peerConnection.addTransceiver(videoTrack);
  const audioTransceiver = peerConnection.addTransceiver(audioTrack);
  const videoSink = new RTCVideoSink(videoTransceiver.receiver.track);
  const audioSink = new RTCAudioSink(audioTransceiver.receiver.track);

  let lastFrame = null;
  let lastSample = null;

  function onFrame({ frame }) {
    lastFrame = frame;
  }

  videoSink.addEventListener('frame', onFrame);

  audioSink.ondata = data => {
    lastSample = data;
  };
...
if (lastFrame) {
  ...
}

if (lastSample) {
      audioSource.onData(lastSample);
}

But i get bad quality audio. How can i change samples to get good audio?? Please, help)) thx.

markandrus commented 4 years ago

Since you don’t appear to be transforming the audio, why not skip the RTCAudioSource and RTCAudioSink stuff and just transmit the remote MediaStreamTrack unmodified? But, you can still expect synchronization issues between audio and video here… these are really just toy examples

On Thu, Dec 26, 2019 at 5:00 AM Glunky notifications@github.com wrote:

Hi! So i opened video-compositing example and it works great. But then i wanted to add sound functionality like in documentation. So i just puted those pieces of code like bellow:

const videoSource = new RTCVideoSource(); const audioSource = new RTCAudioSource(); const videoTrack = videoSource.createTrack(); const audioTrack = audioSource.createTrack(); const videoTransceiver = peerConnection.addTransceiver(videoTrack); const audioTransceiver = peerConnection.addTransceiver(audioTrack); const videoSink = new RTCVideoSink(videoTransceiver.receiver.track); const audioSink = new RTCAudioSink(audioTransceiver.receiver.track);

let lastFrame = null; let lastSample = null;

function onFrame({ frame }) { lastFrame = frame; }

videoSink.addEventListener('frame', onFrame);

audioSink.ondata = data => { lastSample = data; }; ... if (lastFrame) { ... }

if (lastSample) { audioSource.onData(lastSample); }

But i get bad quality audio. How can i change samples to get good audio?? Please, help)) thx.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/node-webrtc/node-webrtc-examples/issues/14?email_source=notifications&email_token=AACXV4WUHTA5FCODVKFPENTQ2SFDDA5CNFSM4J7KQNZKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICWHG6A, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACXV4XJZ6EAJ5IQBZRO4GTQ2SFDDANCNFSM4J7KQNZA .

Glunky commented 4 years ago

Since you don’t appear to be transforming the audio, why not skip the RTCAudioSource and RTCAudioSink stuff and just transmit the remote MediaStreamTrack unmodified? But, you can still expect synchronization issues between audio and video here… these are really just toy examples On Thu, Dec 26, 2019 at 5:00 AM Glunky @.***> wrote: Hi! So i opened video-compositing example and it works great. But then i wanted to add sound functionality like in documentation. So i just puted those pieces of code like bellow: const videoSource = new RTCVideoSource(); const audioSource = new RTCAudioSource(); const videoTrack = videoSource.createTrack(); const audioTrack = audioSource.createTrack(); const videoTransceiver = peerConnection.addTransceiver(videoTrack); const audioTransceiver = peerConnection.addTransceiver(audioTrack); const videoSink = new RTCVideoSink(videoTransceiver.receiver.track); const audioSink = new RTCAudioSink(audioTransceiver.receiver.track); let lastFrame = null; let lastSample = null; function onFrame({ frame }) { lastFrame = frame; } videoSink.addEventListener('frame', onFrame); audioSink.ondata = data => { lastSample = data; }; ... if (lastFrame) { ... } if (lastSample) { audioSource.onData(lastSample); } But i get bad quality audio. How can i change samples to get good audio?? Please, help)) thx. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#14?email_source=notifications&email_token=AACXV4WUHTA5FCODVKFPENTQ2SFDDA5CNFSM4J7KQNZKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICWHG6A>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACXV4XJZ6EAJ5IQBZRO4GTQ2SFDDANCNFSM4J7KQNZA .

Oh, yeah, you right, thx)