Creating thumbnails only with the video link

Asked

Viewed 311 times

0

Is it possible to create a thumbnails just by using the javascript video link? Without having to use php, or other tools when I want to use it in Blogger, it’s a bit limited to this side. Link template: http://blogger.com/video-play.mp4?contentId=6ffdd7d2229f9172

1 answer

0


You can use the following code to take a frame of a specific time and create one canvas with the thumbnail image, change the variable time for the second desired.

var time = 6;
var video = document.createElement("video");
var thumbs = document.getElementById("thumbs");

video.addEventListener('loadeddata', function() {
	thumbs.innerHTML = "";
    video.currentTime = time;
}, false);

video.addEventListener('seeked', function() {
    generateThumbnail(time); 
}, false);

video.preload = "auto";
video.src = "http://blogger.com/video-play.mp4?contentId=6ffdd7d2229f9172";

function generateThumbnail() {
  var c = document.createElement("canvas");
  var ctx = c.getContext("2d");
  c.width = 160;
  c.height = 90;
  ctx.drawImage(video, 0, 0, 160, 90);
  thumbs.appendChild(c);
}
#video {width:320px}
<div id=thumbs>Carregando o video...</div>

  • The problem is that the links will look like this: http://blogger.com/video-play.mp4?contentId=6ffdd7d2229f9172

  • I updated the answer

  • wow, it looks really good!

  • i tried to create using multiple videos at once but is pointing error in generateThumbnail(time) and in the appendChild https://answall.com/questions/321301/erro-ao-criar-thumbnails-em-uma-lista

Browser other questions tagged

You are not signed in. Login or sign up in order to post.