javascript - trying to use the getUserMedia framerate constraint -
i trying adjust framerate display of getusermedia webcam stream. method trying use is
var constraints = { video: { framerate: { ideal: 10, max: 15 } } };
as referenced in moz developer network.
i create several functions can called change framerate different settings, in trying implement constraint not seem have effect. i've tried using alone
function setfps1() { var constraints ... }
and within functions (re)declare stream
function usevideo(){ // query user device permission navigator.mediadevices.getusermedia({video: true}) // if granted .then(function(stream) { // stream & play video webcam var video = document.getelementbyid('uservideo'); var constraints = { video: { framerate: { ideal: 10, max: 15 } } }; video.src = window.url.createobjecturl(stream); video.play(); }) // if not .catch(function(error) { alert(error.message); }); }
and tried
function usevideo(){ // query user device permission navigator.mediadevices.getusermedia({video: true}) // if granted .then(function(stream) { // stream & play video webcam var video = document.getelementbyid('uservideo'); video.src = window.url.createobjecturl(stream); video.play(); var constraints = { video: { framerate: { ideal: 10, max: 15 } } }; }) // if not .catch(function(error) { alert(error.message); }); }
for measure, thinking maybe video had first playing before framerate set.
how framerate constraint meant used, or preventing me using it?
the line:
var constraints = { video: { framerate: { ideal: 10, max: 15 } } };
just initializates local variable constraints
object specified. no effect on else.
you set constraints on camera functions getusermedia
or applyconstraints
, e.g.:
navigator.mediadevices.getusermedia(constraints) .then(function(stream) { var video = document.getelementbyid('uservideo'); video.srcobject = stream; video.play(); }) .catch(error => console.log(error));
or
var track = video.srcobject.getvideotracks()[0]; track.applyconstraints(constraints).catch(e => console.log(e));
once working, note browsers implement constraints a bit differently.
Comments
Post a Comment