pion / example-webrtc-applications

Examples of WebRTC applications that are large, or use 3rd party libraries
https://pion.ly/
MIT License
1.06k stars 248 forks source link

Garbled/Corrupted audio when using a modified version of play-from-disk #127

Open e3ndr opened 2 years ago

e3ndr commented 2 years ago

Your environment.

What did you do? / What did you expect? / What happened?

I'm working on a screen sharing/voice chatting service and I've come across an issue when using a modified example of play-drom-disk. I'm trying to pipe in an OGG file and stream that to a receiver (here's the code) but the audio is garbled/corrupted.

https://user-images.githubusercontent.com/33337309/190562898-1da823a1-986e-4c7a-8b99-fd5f9bff7a5e.mp4

For context, here's how the video is getting to the server:

  1. MediaRecorder records audio into a webm file (Opus, 510kbps, 48khz, 2 channel, 16bit).
  2. I grab a chunk every ~250ms and send that to my api via websocket (it's running on my local machine though).
  3. I then remux the data into a NUT container (for ease of data handling).

And here's how the media is getting to pion:

  1. I wait for the SDP to given to pion, since I need stdin for the OGG stream.
  2. I attach the output of the NUT feed to a OGG remuxer (here's the ffmpeg command I'm running).
  3. I dump the output of the OGG remuxer to a file.
  4. I pipe that output into the pion code via stdin.

Now the raw OGG does not exhibit the playback issues shown in the screen recording, leading me to believe that it's either a pion bug or, more likely, a bug in my code.

Thanks!