i use html5 to create a video to loop and draw the video to canvas, i create multiple canvas and draw every part of video on each canvas, but i found out after some time, it will cause google chrome ran out of memory.
here is the code to draw video on canvas.
v.addEventListener('play', function(){
cw = v.clientWidth * convas_rate_width;
ch = v.clientHeight * convas_rate_height;
canvas.width = (videoWidth/matrix_x) * canvas_location_x;
canvas.height = (videoHeight/matrix_y) * canvas_location_y;
back.width = cw;
back.height = ch;
draw(v,context,context,cw,ch,x,y,matrix_x, matrix_y);
},false);
function draw(v,c,bc,w,h,x,y,matrix_x,matrix_y) {
if(v.paused || v.ended) return false;
// First, draw it into the backing canvas
var x_coord = -((w/matrix_x) * x);
var y_coord = -((h/matrix_y) * y);
bc.drawImage(v,x_coord,y_coord,w,h);
// Grab the pixel data from the backing canvas
var idata = bc.getImageData(0,0,(w),(h));
var data = idata.data;
// Loop through the pixels, turning them grayscale
idata.data = data;
// Draw the pixels onto the visible canvas
c.putImageData(idata,0,0);
// Start over!
setTimeout(draw,10,v,c,bc,w,h,x,y,matrix_x, matrix_y);
}
Here is the printscreen : Google Chrome ran out of memory
Is there anyway to prevent looped video causing the "out of memory" error?