Jason (jcreed) wrote,
Jason
jcreed

I'd heard the term "WebRTC" before, but I didn't realize that among the things it entails was "hey there are javascript apis to video capture now".

So on my laptop I ran

var sizex = 32;
var sizey = 16;
w = 32;
h = 24;
counter = 0;
video = document.createElement("video");
video.setAttribute('width', w);
video.setAttribute('height', h);
c = document.getElementById("c");
d = c.getContext('2d');

navigator.webkitGetUserMedia({
  video: true
}, function(stream) {
  gstream = stream;
  video.src = URL.createObjectURL(gstream);
  c.width = w * sizex;
  c.height = h * sizey;
  video.play();

  renderTimer = setInterval(function() {
    var t = counter % (sizex * sizey);
//    d.globalAlpha = 0.5;
    d.drawImage(video, w * (t % sizex), h * Math.floor(t / sizex), video.width, video.height);
    counter++;
  }, 15);
});

document.onkeydown = function() {
  clearInterval(renderTimer);
}



and on my phone I ran a full-screened jsfiddle with
counter = 0;
setInterval(function() {
    $('body').css({'background-color': counter == 0 ? 'black' : 'white'});
  counter = (counter + 1) % 9;
}, 30);


and out came this thing when I waved my phone around in front of the camera:
strobe
Tags: javascript, video
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 2 comments