I get live video from the webcam and, in order to fit a div
with width/height that I want, the best solution I found was use object-fit: cover
like this:
<video id="videoId" style='object-fit: cover;' autoplay="true" playsInline></video>
<img id="myImage" src="">
The problem arises when I try to get the EXACT bitmap content of that video, using
var video = document.getElementById('videoId');
var canvas = document.createElement("canvas");
canvas.width = video.width;
canvas.height = video.height;
canvas.getContext('2d').drawImage(video, 0, 0, video.width, video.height);
document.getElementById('myImage').src = canvas.toDataURL();
I do not get the video content, but the "real" video stream, which is different because I am using the object-fit: cover
style.
Is there a way to grab a screenshot so to speak of that video? In theory, I could play with width/height offsets because "in theory" I know the original resolution of the video, but when I tried, it became messy. DPI, pixels, zoom...
Thank you