如何精确计算您在元素中的位置?
我们知道:
CurrentTime
不提供精确的时间-请参阅https://github.com/w3C/media-and-entertainment/issues/4显示浏览器可变性的示例:https://daiz.github.io/frame-acculary-ish/
示例如下:https://glitch.com/~omniscient-shell-iguana
我们可以看到在整个示例视频中获得精确的frame
计数的以下工作--这是通过CurrentTime
参数无法完成的。
const updateCanvas = (now, metadata) => {
if (startTime === 0.0) {
startTime = now;
}
ctx.drawImage(video, 0, 0, width, height);
let frameOffset = 2
const frames = Math.round(metadata.mediaTime * fps) - frameOffset
fpsInfo.innerText = !isFinite(frames) ? 0 : frames;
metadataInfo.innerText = JSON.stringify(metadata, null, 2);
video.requestVideoFrameCallback(updateCanvas);
};
video.src =
"https://daiz.github.io/frame-accurate-ish/time.mp4";
video.requestVideoFrameCallback(updateCanvas);
frameoffset
必须通过查看const frames=Math.round(Metadata.mediatime*fps)
在time=0
时等于什么来确定。
感谢博文:https://Blog.tomayac.com/2020/05/15/The-RequestVideoFrameCallback-api/