recording a remote webrtc stream with RecordRTC
Asked Answered
S

3

7

I am using Opentok JavaScript WebRTC library to host a 1-to-1 video chat (peer-to-peer). I can see my peer's video and hear the audio flawlessly.

My wish is to record audio / video of other chat party (remote). For this purpose, I'm using RecordRTC. I was able to record the video of other chat participant (video is outputted to HTML video element), but, so far, I have not succeeded in recording audio (a dead-silence .wav file is as far as I could get). Using Chrome Canary (30.0.1554.0). This is my method:

var clientVideo = $('#peerdiv video')[0];//peer's video (html element)
var serverVideo = $('#myselfdiv video')[0];//my video (html element)

var context = new webkitAudioContext();
var clientStream = context.createMediaStreamSource(clientVideo.webRTCStream);
var serverStream = context.createMediaStreamSource(serverVideo.webRTCStream);

webRTCStream is a custom property i assigned to HTMLVideoElement object by modifying source of opentok js library. It contains MediaStream object linked to respective < video > element.

var recorder = RecordRTC({
                    video: clientVideo,
                    stream: clientStream
                });
recorder.recordAudio();
recorder.recordVideo();

Video is recorded. Audio file is also created, it has a length that is close to video's length, however, it's completely silent (and yes, there was a lot of noise making on the other side during recording)

I've tested this with video element which displays my webcam's video stream (and audio), and it worked: both audio and video were recorded:

...
var recorder = RecordRTC({
                    video: serverVideo,
                    stream: serverStream
                });
...

Is there something special about streams originating from a remote location? Any guidance on this issue would be very helpful.

Schneider answered 4/7, 2013 at 16:40 Comment(1)
See my answer, this now works in Firefox. It was a limitation of the AudioAPI.Brooch
K
7

This is the same issue occurs in following situations...

  1. If not a stereo audio (dual channel audio)...i.e. it is mono audio
  2. If audio input channels are not equal to audio output channels
  3. If audio input device is not the default device selected on chrome

I'm still trying to find the actual issue.

I added this experiment for testing purpose... see console...

https://webrtc-experiment.appspot.com/demos/remote-stream-recording.html

Updated at: Saturday, 1 February 2014, 09:22:04 PKT

Remote audio recording is not supported; and this issue is considered as low-priority wontfix:

  1. Support feeding remote WebRTC MediaStreamTrack output to WebAudio
  2. Connect WebRTC MediaStreamTrack output to Web Audio API

Updated at March 28, 2016

Remote audio+video recording is now supported in RecordRTC, since Chrome version 49+.

Firefox, on the other hand, can merely record remote-audio.

Karleenkarlen answered 4/7, 2013 at 17:11 Comment(4)
Is there any possibility for recording remote peer's video ?Tollgate
You can record both audio+video in Firefox for remote peer, however you can record "only-video" for remote peer in Chrome (NOT-remote-audio).Karleenkarlen
Please share any link (if you have) for audio+video remote recording.Tollgate
Try any demo from this page: webrtc-experiment.com/RTCMultiConnection After getting remote stream, type connection.streams.selectFirst({ remote: true}).startRecording(); in the console. Then you can type: connection.streams.selectFirst({ remote: true}).stopRecording(function(blob) { alert( blob.audio.type + ':' + blob.audio.size });Karleenkarlen
S
2

If Chrome/WebRTC/Opus outputs mono audio by default and if that is the problem here, I see two options in that case:

  1. By making opus output stereo - not sure how.
  2. By making the RecordRTC/Recorderjs code work with mono

Or does anyone know any other recording library that works?

Stratocracy answered 4/7, 2013 at 21:33 Comment(0)
B
0

This actually now works fine in Firefox. I am using FireFox 29.0.1 and the AudioAPI can now work with audio streams sources grabbed from remote parties from a peer connection.

To test go to Muaz Khan's experiment page. I am not sure with what version of Firefox this rolled out but I would like to thank the team for cranking it out!

The chrome bug was moved to the AudioAPI team cr bug to track progress

Brooch answered 20/6, 2014 at 13:25 Comment(1)
RecordRTC is using MediaRecorder API for Firefox 28+ which is supporting remote audio recording as well. The referenced experiment is using RecordRTC.Karleenkarlen

© 2022 - 2024 — McMap. All rights reserved.