当前位置:网站首页>Requestvideoframecallback() simple instance
Requestvideoframecallback() simple instance
2022-07-29 00:36:00 【InfoQ】
<template>
<div id="app">
<div class="player-container">
<div class="title">requestVideoFrameCallback() Simple example </div>
<div class="item-container left">
<div class="item-container-in">
<video controls playsinline muted autoplay></video>
<div class="item-header">Video</div>
</div>
</div>
<div class="item-container right">
<div class="item-container-in">
<canvas></canvas>
<div class="item-header">Canvas</div>
</div>
</div>
<div class="fps-info" v-if="fpsInfo">
<strong>FPS:</strong>
<i>{{ fpsInfo }}</i>
</div>
<div class="metadata-info" v-if="metadata">
<textarea readonly v-model="metadata"></textarea>
</div>
</div>
</div>
</template>
<script>
export default {
name: "App",
data() {
return {
fpsInfo: null,
metadata: null,
};
},
mounted() {
this.init();
},
methods: {
init() {
const video = document.querySelector("video");
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
video.addEventListener("play", () => {
if (
!("requestVideoFrameCallback" in HTMLVideoElement.prototype)
) {
return alert(
" Your browser does not support interfaces `Video.requestVideoFrameCallback()`"
);
}
});
let width = canvas.width;
let height = canvas.height;
let paintCount = 0;
let startTime = 0.0;
const updateCanvas = (now, metadata) => {
if (startTime === 0.0) {
startTime = now;
}
ctx.drawImage(video, 0, 0, width, height);
const elapsed = (now - startTime) / 1000.0;
const fps = (++paintCount / elapsed).toFixed(3);
this.fpsInfo = !isFinite(fps) ? 0 : fps;
this.metadata = JSON.stringify(metadata, null, 2);
video.requestVideoFrameCallback(updateCanvas);
};
video.src = "https://vjs.zencdn.net/v/oceans.mp4";
video.requestVideoFrameCallback(updateCanvas);
},
},
};
</script>
<style>
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
background: #000;
}
.title {
position: absolute;
left: 0;
top: 30;
height: 60px;
line-height: 60px;
font-size: 24px;
color: #fff;
text-align: center;
width: auto;
right: 0px;
background-color: #000;
z-index: 100;
border-bottom: 1px rgba(255, 255, 255, 0.6) solid;
}
.player-container {
width: 100%;
height: 100vh;
overflow: hidden;
position: relative;
}
.item-container {
position: absolute;
width: 50%;
height: 100%;
padding: 50px;
top: 0px;
z-index: 1;
}
.item-container.left {
left: -5px;
border-right: 1px rgba(255, 255, 255, 0.6) solid;
}
.item-container-in {
width: 100%;
height: 100%;
position: relative;
}
.item-header {
position: absolute;
width: 100%;
height: 100%;
top: 100px;
z-index: 9;
color: rgba(255, 255, 255, 0.8);
font-weight: 700;
}
.item-container.right {
right: -5px;
border-left: 1px rgba(255, 255, 255, 0.6) solid;
}
.item-container canvas,
.item-container video {
position: absolute;
left: 50%;
top: 50%;
margin: -180px 0px 0px -320px;
width: 640px;
height: 360px;
}
.item-container::before {
position: absolute;
content: "";
width: 1px;
height: 100%;
overflow: hidden;
background-color: rgba(#fff, 0.6);
}
.fps-info {
position: absolute;
width: 200px;
height: 50px;
line-height: 20px;
font-family: Arial, Helvetica, sans-serif;
left: 50px;
bottom: 50px;
z-index: 10;
padding: 15px;
background-color: rgba(255, 255, 255, 0.5);
text-align: left;
color: #000;
}
.fps-info i {
font-style: normal;
}
.metadata-info {
position: absolute;
width: 600px;
height: 180px;
line-height: 20px;
font-family: Arial, Helvetica, sans-serif;
right: 50px;
bottom: 50px;
z-index: 10;
padding: 15px;
background-color: rgba(255, 255, 255, 0.5);
text-align: left;
color: #000;
}
.metadata-info textarea {
display: block;
width: 100%;
height: 100%;
background-color: transparent;
border: none;
}
</style>

requestVideoFrameCallback()边栏推荐
- PTA (daily question) 7-73 turning triangle
- Camera Hal OEM module ---- CMR_ preview.c
- [untitled]
- MySQL事务(transaction) (有这篇就足够了..)
- DCAT in laravel_ Admin preliminary use record
- SAP vl02n delivery note posting function WS_ DELIVERY_ UPDATE
- pnpm的安装与使用
- Brief introduction to compressed sensing
- Idea connection database
- MySQL的存储过程
猜你喜欢

Simple use and understanding of laravel message queue

I was asked several questions about string in the interview. Can you answer them?
![[basic course of flight control development 8] crazy shell · open source formation uav-i2c (laser ranging)](/img/0b/d6defd524f83e69b40b5878ffe2e3c.png)
[basic course of flight control development 8] crazy shell · open source formation uav-i2c (laser ranging)

"Food alliance ordering system"

2022DASCTF7月赋能赛(复现)

递归/回溯刷题(下)

Html+css+php+mysql realize registration + login + change password (with complete code)

Idea2021.2 installation and configuration (continuous update)

Linux下安装Mysql5.7,超详细完整教程,以及云mysql连接

I don't know how lucky the boy who randomly typed the log is. There must be a lot of overtime!
随机推荐
MQ 消息丢失、重复、积压问题,如何解决?
flask结合容联云发送验证码
Dynamic programming problem (6)
动态规划问题(六)
Basic knowledge of PHP language (super detailed)
ORACLE not available如何解决
PTA (daily question) 7-73 turning triangle
还在写大量 if 来判断?一个规则执行器干掉项目中所有的 if 判断...
15.模型评估和选择问题
Dynamic programming problem (1)
ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
flyway的快速入门教程
110 MySQL interview questions and answers (continuously updated)
Application and principle of distributed current limiting redistribution rratelimiter
NPM run serve stuck at 40%
Multimodal model sketch (1)
动态规划问题(三)
Mock.js essay
[ESN] learning echo state network
乱打日志的男孩运气怎么样我不知道,加班肯定很多!