Open hailanglang opened 1 year ago
Something similar was happening to me, with a video created by AR.js. this library uses negative offsets to center the video and fill the container. This is a quick workaround:
DocumentCloner.prototype.createVideoClone = function (video) {
var canvas = video.ownerDocument.createElement('canvas');
canvas.width = video.offsetWidth;
canvas.height = video.offsetHeight;
let left = parseInt(video.style.marginLeft);
let top = parseInt(video.style.marginTop);
var ctx = canvas.getContext('2d');
try {
if (ctx) {
ctx.drawImage(video, left, top, canvas.width, canvas.height);
if (!this.options.allowTaint) {
ctx.getImageData(0, 0, canvas.width, canvas.height);
}
}
return canvas;
}
catch (e) {
this.context.logger.info("Unable to clone video as it is tainted", video);
}
var blankCanvas = video.ownerDocument.createElement('canvas');
blankCanvas.width = video.offsetWidth;
blankCanvas.height = video.offsetHeight;
return blankCanvas;
};
In this mod just the left
and top
vars are obtained, and then passed to ctx.drawImage
.
This is a quick solution, some check should probably be made to make sure those properties make sense (for example transforming them to pixels if they are percentaje, etc)
Bug reports:
The captured video is rendered on the canvas, and the position is wrong. Am I using it wrong? code segment:
Specifications: