How to save a webRTC stream into a file on server with nodejs?

Viewed 38

I get my stream from my client like this :

  webrtc_connection.ontrack = async (e) => {
    
 //TODO : RECORD

  }

How can I record / save it into a file on server? Apparently nodejs does not have MediaRecorder, so I am at loss for going further.

1 Answers

There are two options. The first is to use MediaRecorder+Socket.io+FFmpeg. Here is an example of how to stream from the browser to RTMP via node.js, but instead of streaming, you can just save it to the file.

  1. draw your video on canvas, use canvas.captureStream() to get MediaStream from the canvas;
  2. append your audio to MediaStream that you got in the previous step using MediaStream.addTrack();
  3. use MediaRecorder to get raw data from the MediaStream;
  4. send this raw data via WebSockets to node.js;
  5. use FFmpeg to decode and save your video data to a file.

The Second is to use node-webrtc. You can join your WebRTC room from the server as another participant using WebRTC and record media tracks using FFmpeg. Here is an example.

Related