Skip to content

pradeepsr029/video-Thumbnail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

video-Thumbnail

javascript video thumbnail canvas

How to use

capture(video) {
    let w = video.videoWidth * this.scaleFactor;
    let h = video.videoHeight * this.scaleFactor;
    let canvas = document.createElement('canvas');
    canvas.width = w;
    canvas.height = h;
    let ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0, w, h);
    let dataURI = canvas.toDataURL('image/jpeg');
    // let a = 
    let boj={
      canvas:canvas,
      file:this.dataURLtoFile(dataURI, `${+new Date()}.jpg`),
      base64:dataURI
    }
    return boj;
  }

  dataURLtoFile(dataurl, filename) {
    var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
      bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
    while (n--) {
      u8arr[n] = bstr.charCodeAt(n);
    }
    return new File([u8arr], filename, { type: mime });
  }

About

javascript video thumbnail canvas

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published