0
我使用html5創建視頻來循環並將視頻畫到畫布上,我創建了多個畫布並在每個畫布上繪製了視頻的每個部分,但是一段時間後我發現,它會導致谷歌瀏覽器內存不足。防止視頻循環導致瀏覽器內存不足
這裏是在畫布上繪製視頻的代碼。
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);
}
這裏是PRINTSCREEN:Google Chrome ran out of memory
反正是有防止循環視頻引起 「內存不足」 的錯誤?