function b64toBlob(base64) {
var mimeString = base64.split(",")[0].split(":")[1].split(";")[0];
var byteString = atob(base64.split(",")[1]);
var arrayBuffer = new ArrayBuffer(byteString.length);
var intArray = new Uint8Array(arrayBuffer);
for (var i = 0; i < byteString.length; i++) {
intArray[i] = byteString.charCodeAt(i);
}
return new Blob([intArray], { type: mimeString });
}
function blobToFile(theBlob, fileName) {
return new window.File([theBlob], fileName + ".jpg", {
type: "image/jpg",
lastModified: Date.now(),
});
}
function createVideoImg(e) {
return new Promise((resolve, reject) => {
const files = e;
const reader = new FileReader();
reader.readAsDataURL(files);
reader.onload = function (t: any) {
let video = document.createElement("video");
video.setAttribute("src", t.target.result);
video.setAttribute("controls", "controls");
video.setAttribute("width", '708px');
video.setAttribute("height", '300px');
video.currentTime = 7;
video.addEventListener("loadeddata", async function () {
let canvas = document.createElement("canvas"),
width = video.width * 2,
height = video.height * 2;
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(video, 0, 0, width, height);
let dataURL = canvas.toDataURL("image/jpg", 2.0);
let url = b64toBlob(dataURL);
let file = blobToFile(url, new Date().getTime());
resolve(file)
});
};
})
}