专注前端,专注网页设计制作教程: http://www.dede168.com
当前位置: 葡京娱乐场 > 网页设计 > HTML5+CSS3 > > >文章

HTML5 视频截图

时间:2013-02-07 15:22点击: 次 【

HTML5 视频截图

http://odetocode.com/blogs/scott/archive/2013/01/04/capturing-html-5-video-to-an-image.aspx

<video id="video" controls="controls">
    <source src=".mp4" />
</video>
 
<button id="capture">Capture</button>
 
<div id="output"></div>

点击按钮时触发如下代码

(function() {
    "use strict";
 
    var video, $output;
    var scale = 0.25;
 
    var initialize = function() {
        $output = $("#output");
        video = $("#video").get(0);
        $("#capture").click(captureImage);               
    };
 
    var captureImage = function() {
        var canvas = document.createElement("canvas");
        canvas.width = video.videoWidth * scale;
        canvas.height = video.videoHeight * scale;
        canvas.getContext('2d')
              .drawImage(video, 0, 0, canvas.width, canvas.height);
 
        var img = document.createElement("img");
        img.src = canvas.toDataURL();
        $output.prepend(img);
    };
 
    $(initialize);           
 
}());
------分隔线----------------------------
-