简体   繁体   English

HTML5视频-画布上的图像

[英]HTML5 video - image on canvas

I'm trying to capture video frame as image like here: 我正在尝试将视频帧捕获为图像,如下所示:

http://appcropolis.com/using-html5-canvas-to-capture-frames-from-a-video/ http://appcropolis.com/using-html5-canvas-to-capture-frames-from-a-video/

My simple code: 我的简单代码:

var video = document.getElementById("video");
var bottom = document.getElementById("bottom"); 


var canvas = document.createElement('canvas');

canvas.width  = 500;
canvas.height = 282;

var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, 500, 282); 

bottom.innerHTML = '';
bottom.appendChild(canvas);

On IE it works excellent but on Chrome I've always got black canvas... 在IE上效果很好,但在Chrome上我总是有黑色画布...

Demo here: 演示在这里:

http://html5-canvas-test.vipserv.org/ http://html5-canvas-test.vipserv.org/

Any idea how to fix this? 任何想法如何解决这个问题?

Works perfect in Chrome for me! 对我来说,在Chrome中完美运行!

But you need to start the video, if the video isnt started you'll get a black screen. 但是您需要开始播放视频,如果未开始播放视频,则会出现黑屏。

You must use the event "seeked" ! 您必须使用事件“ seeked”!

$(video).seeked(function() {
    ctx.drawImage(video, 0, 0, 500, 282); 
});

Sorry for my English i'm french 对不起我的英语我是法语

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM