SRS server, DVR doesn’t work correctly with WebRTC

230 views Asked by At

I'm testing SRS on my server. I have a problem when using DVR to save WebRTC to an mp4 file. The mp4 file only has some seconds, not full time (sometimes it only has 1 second). Do you have any suggestions for my case?

1

There are 1 answers

0
Winlin On

For the feature WebRTC DVR, SRS converts WebRTC to RTMP, then DVR RTMP to FLV or MP4 file.

WebRTC video stream changes the SPS/PPS now and then, which means there would be more than one SPS/PPS frame, actually there is one before each keyframe.

It works well for DVR WebRTC to FLV file, because FLV supports SPS/PPS change. But for MP4, it fails because it doesn't support SPS/PPS change.

There is a solution:

  1. DVR WebRTC to FLV file by SRS.
  2. Setup the on_dvr http callback, so that your server can handle the FLV file.
  3. Your server starts a FFmpeg process to transcode the FLV file to MP4.

Note: Here your server is not SRS, but your backend server. You can write one by Go, and there is an example.

Please note that you should use FFmpeg to transcode the FLV file, not only transmux the format, here is an example:

ffmpeg -i dvr.flv -vcodec libx264 -profile:v high -preset:v slow \
  -acodec copy -y dvr.mp4

Here we transcode the video stream and copy the audio stream, which has already been transcoded from opus by SRS.