Instantly share code, notes, and snippets.

Embed
What would you like to do?
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