Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Capture thumbnail on client side and prepare file to upload
<!DOCTYPE html>
<script type='text/javascript'>
window.onload = function () {
var video = document.getElementById('videoId')
var canvas = document.getElementById('canvasId') = 'block'
// fake loading
setTimeout(() => {
// start when video loaded
draw(video, canvas)
}, 2000)
function draw(video, canvas) {
var context = canvas.getContext('2d')
context.drawImage(video, 0, 0, canvas.width, canvas.height)
var dataURL = canvas.toDataURL()
var blobBin = atob(dataURL.split(',')[1])
var array = []
for (var i = 0; i < blobBin.length; i++) {
var file = new Blob([new Uint8Array(array)], {type: 'image/png'})
// this is working file
<video id="videoId" autoplay loop controls crossorigin="anonymous">
<source src="http://localhost:3978/test.webm" type="video/webm">
<source src="http://localhost:3978/test.mp4" type="video/mp4">
Your browser does not support the video tag.
<canvas id="canvasId"></canvas>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment