记录canvas获取video第一帧
export const getFirstFrame = (url): Promise<Blob> => {
return new Promise<Blob>((resolve) => {
const video = document.createElement("video")
video.setAttribute("crossOrigin", "anonymous")
video.setAttribute("src", url)
video.setAttribute("preload", "auto")
video.setAttribute("width", "300px")
video.setAttribute("height", "180px")
video.addEventListener("loadeddata", function () {
const canvas: HTMLCanvasElement = document.createElement("canvas"),
width = video.width,
height = video.height
canvas.width = width
canvas.height = height
canvas.getContext("2d")!.drawImage(video, 0, 0, width, height)
canvas.toBlob((blob) => resolve(blob as Blob), "image/jpeg")
canvas.toDataURL("image/jpeg")
})
})
}