I'm going to generate video thumbnail from video url in javascript. I need this done via ajax. So I followed this approach.
var src = thumbnail; ///video url not youtube or vimeo,just video on server
var video = document.createElement('video');
video.src = src;
video.width = 360;
video.height = 240;
var canvas = document.createElement('canvas');
canvas.width = 360;
canvas.height = 240;
var context = canvas.getContext('2d');
context.drawImage(video, 0, 0, canvas.width, canvas.height);
var dataURI = canvas.toDataURL('image/jpeg');
html += '<figure>';
html += '<img src="' + dataURI + '' + '" alt="' + item.description + '" />';
html += '<figurecaption>'+item.description+'</figurecaption>'
html += '</figure>';
But what I get is just black image. I guess it's because load problem but can't find a solution. Looking forward to hearing from you.
Regards.
Approach: Sometimes the user wants to display a specific image of his choice as the thumbnail of the video. This can be simply done by using the poster attribute. All you have to do is create a poster attribute in the video tag and place the URL of the thumbnail image in it.
You can install the npm: video-metadata-thumbnails
, then use it like this:
import { getMetadata, getThumbnails } from 'video-metadata-thumbnails';
const thumbnails = await getThumbnails(blob, {
quality: 0.6
});
console.log('Thumbnails: ', thumbnails);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With