我有一个视频元素,它在流期间被复制到画布元素。
<div id="video-panel">
<canvas id="main-canvas" width="640" height="320"></canvas>
<video id="video-remote" autoplay="autoplay" src=""></video>
<video id="video-local" autoplay="autoplay" muted="true" src=""></video>
</div>
我遇到的问题是保持全屏的纵横比。视频保持其比例,但画布没有。
代码的 CSS 部分是:
#video-panel {
width: 100%;
height: 100%;
}
#video-remote {
width: 100%;
height: 100%;
}
#video-local {
width: 24%;
position: absolute;
z-index: 1;
right: 10px;
bottom: 10px;
border: 1px solid white;
}
#main-canvas {
position: absolute;
background: url(https://.../image1.png) no-repeat;
background-size: cover;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
我正在测试色度键效果,视频播放中调用的 JS 部分是:
/////
this.video = document.getElementById('video-remote');
this.canvas = document.getElementById('main-canvas');
this.context = this.canvas.getContext('2d');
////
computeFrame() {
this.context.drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
...
this.context.putImageData(frame, 0, 0);
}
我能做些什么来完成这项工作吗?