JSFiddle - React, Tailwind, and code Playground
by trung ken
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<video id="video" width="320" height="176" src="https://li-thuyet-bng-2.kentrung.repl.co/phim-hot.mp4" type="video/mp4" controls></video>
<button onclick="capture()">Capture</button>
<canvas id="canvas" style="overflow:auto"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
function capture() {
var canvas = document.getElementById('canvas')
var video = document.getElementById('video')
canvas.width = video.videoWidth
canvas.height = video.videoHeight
canvas.getContext('2d').drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
/** Code to merge image **/
/** For instance, if I want to merge a play image on center of existing image **/
const playImage = new Image();
playImage.src = '';
playImage.onload = () => {
const startX = (video.videoWidth / 2) - (playImage.width / 2);
const startY = (video.videoHeight / 2) - (playImage.height / 2);
canvas.getContext('2d').drawImage(playImage, startX, startY, playImage.width, playImage.height);
canvas.toBlob() = (blob) => {
const img = new Image();
img.src = window.URL.createObjectUrl(blob);
};
};
}
</script>
</body>
</html>