let ctx = canvas.getContext("2d");
let scale_factor = Math.min(canvas.width / video.videoWidth, canvas.height / video.videoHeight);
let newWidth = video.videoWidth * scale_factor;
let newHeight = video.videoHeight * scale_factor;
ctx.drawImage(video, 0, 0, newWidth, newHeight);