HTML5 drawimage from video to canvas

老子叫甜甜 提交于 2019-12-23 09:49:40

问题


I was trying to capture a frame from video and drawing it in canvas using HTML5, but the below code is not working. when i click on the start button the canvas is filled with black color

    <video src="video2.mp4" autoplay="true" type="video/mp4" width="300" height="200" id="vid">
        </video>
        <canvas id="cvs"> </canvas>
        <button onclick="start()">Start</button>
        <script>
        var video=document.getElementById("vid");
        var cvs=document.getElementById("cvs");
        function start(){
        cvs.getContext("2d").drawImage(video, 0, 0, 300,200);
        }
</script>

回答1:


I had the exact same problem, and I think it had to with the video format. My video was H264 in an .mp4 container. When I used an .ogg video, the exact same code worked perfectly. I'm using the code from the link that was provided by Romin.



来源:https://stackoverflow.com/questions/12256668/html5-drawimage-from-video-to-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!