2

canvas渲染video视频,并添加图像设置功能,

 2 years ago
source link: http://www.hywel.cn/2020/10/16/canvas%E6%B8%B2%E6%9F%93video%E8%A7%86%E9%A2%91%EF%BC%8C%E5%B9%B6%E6%B7%BB%E5%8A%A0%E5%9B%BE%E5%83%8F%E8%AE%BE%E7%BD%AE%E5%8A%9F%E8%83%BD%EF%BC%8C/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

canvas渲染video视频,并添加图像设置功能,

Posted on

2020-10-16 In Web前端

本文主要展示使用canvas来实时的获取video并动态播放的例子。

function drawCanvas() {
if (videoElement.paused videoElement.ended) {
return;
}
var canvas = $(“#canvas”);
var _canvas = canvas.get(0);
context = _canvas.getContext(“2d”);
canvas.attr({
width: videoElement.videoWidth,
height: videoElement.videoHeight
})

context.clearRect(0, 0, videoElement.videoWidth, videoElement.videoHeight);
context.fillStyle = ‘red’;
context.fillStyle = ‘rgba(255,255,0,0.5)’;
context.drawImage(videoElement, 0, 0, videoElement.videoWidth, videoElement.videoHeight, 0, 0, videoElement.videoWidth, videoElement.videoHeight);
if (videoElement.videoWidth > 0 && videoElement.videoHeight > 0) {
var filters = “blur(“ + (_blur.getCurVal() / 10) + “px) brightness(“ + (_brightness.getCurVal() / 10) + “) contrast(“ + (_contrast.getCurVal() / 10) + “) grayscale(“ + (_grayscale.getCurVal() / 100) + “) hue-rotate(“ + (_hue_rotate.getCurVal()) + “deg) invert(“ + (_invert.getCurVal() / 100) + “) saturate(“ + (_saturate.getCurVal() / 10) + “) sepia(“ + (_sepia.getCurVal() / 100) + “)”;
$(“#canvas”).css({
‘-webkit-filter’: filters,
‘max-width’: ‘100%’
});
}
setTimeout(drawCanvas, 24);
}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK