javascript - HTML5 video screenshot -
i'm trying take screenshot of video predefined time in movie. tried canvas element. thing video must playing when draw image of video, need image still paused. tried this:
video.play(); context.drawimage(video,0,0,canvas.width,canvas.height); video.pause();
but can imagine, video pauses before canvas done drawing, resulting in no screenshot. there callback function drawimage? in case, drawing process takes 50ms, doesn't feel safe do:
settimeout(function() { video.pause(); }, 50);
rather pausing try setting video's playbackrate low (or 0 if works?):
video.playbackrate = 0.0001; // or 0
this pause video you.
you set canvas black, tranparency 0.99 , scan resulting image in timeout non-black pixel:
settimeout(function() { pixel = context.getimagedata(image.width/2, image.height/2, 1, 1); // pixel, kick off timeout if still has transparency }, 50);
when using last method video must same domain script, , not work on local files because of security constraints.
Comments
Post a Comment