Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser web cam stream has extremely low performance/frame rate

I am trying to test WebRTC and want to display my own stream as well as the peer's stream. I currently have a simple shim to obtain the camera's stream and pipe that into a video element, however the frame rate is extremely low. The rare thing about this is that I can try examples from the WebRTC site and they work flawlessly.. The video is smooth and there are no problems. I go to the console and my code resembles theirs.. What could be happening? I tried to create both a fiddle and run that code within brackets but it still performs horribly.

video = document.getElementById('usr-cam');

  navigator.mediaDevices.getUserMedia({video : {
      width : {exact : 320},
      height : {exact: 240}
  }})
  .then(function(stream){


      if(navigator.mozGetUserMedia)
      {
        video.mozSrcObject = stream;
      }
      else
      { 
         video.srcObject = stream;
      }



  })
  .catch(function(e){
      alert(e);
  });

Pretty much everything I do. Take into account that I am using the new navigator.mediaDevices() API instead of navigator.getUserMedia() but I don't see how that would matter since 1.I am using a shim provided by the WebRTC group named adapter.js which they themselves use. 2. I don't think how you obtain hold of the video stream would affect performance.

like image 412
naughty boy Avatar asked Apr 17 '16 01:04

naughty boy


People also ask

Why is my FPS so low when streaming?

Streaming affects your FPS for one simple reason, and that is the amount of resources required for streaming. Not only is it resource intensive on your GPU, but it can be quite a struggle for your CPU, ram and even your harddrive.

What is a good FPS for Webcam?

30fps. Many modern cameras offer the option to film video content in 30 frames per second. Traditionally, this is the best frame rate for live streaming (fps live) that was used for TV video content in the USA.


1 Answers

Alright, I feel very stupid for this one... I was kind of deceived by the fact that the video element will update the displayed image without you having to do anything but pipe the output stream, which means the image will update but just at really long intervals, making it seem as if the video is lagging. What I forgot to do was actually play() the video or add autoplay as its property... it works well now.

like image 171
naughty boy Avatar answered Sep 21 '22 19:09

naughty boy