Skip to content

Instantly share code, notes, and snippets.

@stevygee
Last active March 25, 2018 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevygee/e62d2e42bb86a33571223ff3698caa6a to your computer and use it in GitHub Desktop.
Save stevygee/e62d2e42bb86a33571223ff3698caa6a to your computer and use it in GitHub Desktop.
Two approaches to draw the current frame from video element on a canvas in regular intervals
function draw() { // Global function for displaying the game, this is called in a game loop
drawVideo(currentVideo);
// ... display other elements ...
}
var video1 = $("#video1");
var canvas = $("#myCanvas");
var ctx = canvas[0].getContext("2d");
var timerID;
function drawImage(video) {
ctx.drawImage(video, 0, 0, 640, 360);
}
video1.on("play", function () {
timerID = window.setInterval(function () { drawImage(video1[0]); }, 30);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment