I'm trying to generate a thumbnail image from a video file. This is my code:
let canvas: HTMLCanvasElement = document.createElement('canvas');
let video: HTMLVideoElement = document.createElement('video');
video.src = video_url;
video.currentTime = 4;
video.onloadedmetadata = () => {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
video.currentTime = 4;
};
video.onloadeddata = () => {
video.currentTime = 4;
canvas.getContext('2d').drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
canvas.toBlob(thumbnailBlob => { grabThumbnail(thumbnailBlob) }, 'image/png');
};
It creates the image, but just a blank image. Doesn't get the video frame from the currentTime property. What am I doing wrong?