Skip to content

Instantly share code, notes, and snippets.

@ThinhVu
Created October 20, 2022 06:58
Show Gist options
  • Save ThinhVu/d1fe813b67944e85418f85cba93e1b62 to your computer and use it in GitHub Desktop.
Save ThinhVu/d1fe813b67944e85418f85cba93e1b62 to your computer and use it in GitHub Desktop.
Save current frame of a video into an image
function captureVideo(video) {
var canvas = document.createElement("canvas");
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
var canvasContext = canvas.getContext("2d");
canvasContext.drawImage(video, 0, 0);
const image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
window.location.href=image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment