【发布时间】:2013-06-07 07:55:00
【问题描述】:
我需要检测 HTML 5 中视频的所有帧变化,我尝试了以下代码,但我无法获得所有变化,我每秒只能获得 8 或 9 次更新..
<body>
<canvas id="Canvas" width="800" height="450" style="position:absolute; left:5; top:5">Can't Load Canvas</canvas>
<video id="videoPlay" muted controls>
<source src="assets/soccer.webm" type="video/webm">
<source src="assets/soccer.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
<script type="text/javascript">
videoPlay.addEventListener('timeupdate', function (){
putOverlay();
});
function putOverlay(){
console.log(videoPlay.currentTime);
console.log("another frame");
}
</script>
</html>
我也尝试了以下代码,但是随着时间的推移,随着时间的推移,帧和计时器给出的值之间会失去同步。
<body>
<canvas id="LeCanvas" width="800" height="450" style="position:absolute; left:5; top:5">Can't Load Canvas</canvas>
<!-- Video -->
<video id="videoPlay" controls>
<source src="assets/soccer.webm" type="video/webm">
<source src="assets/soccer.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
<!-- Play Video-->
<script>
//Play Damn Video
var videoPlay = $('#videoPlay')[0];
videoPlay.play(1);
</script>
<!-- Canvas Animation -->
<script>
//Animation
function animate() {
console.log("frame change");
}
setInterval(animate, 1000/29.97);
</script>
对我的问题有什么建议吗?
对不起我的英语
问候 亚历克斯
【问题讨论】:
-
信息可能不再是 100% 最新的,但请参阅 How often does the timeupdate event fire for an html5 video?,并查看链接的 Bugzilla 页面。
-
根据 HTML5 规范,浏览器必须每隔 15 到 250 毫秒触发一次 timeupdate 事件——但这与您的帧数无关。 setInterval 不会同步 1 到 1。如果您绝对需要帧精度,您可以尝试尽可能快地运行 setInterval。请注意,登录到控制台可能会减慢速度,具体取决于浏览器。
-
这就是我对我的第二个代码所做的事情。问题是,随着时间的推移,差异会越来越大..
标签: javascript html html5-video