有没办法获取video视频里的图片

当上传完视频的时候获取里面随便一帧当做封面,有办法做到没?

慕盖茨4494581
浏览 1158回答 1
1回答

陪伴而非守候

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>capture screen</title></head><body><video id="video" controls="controls"><source src="123.MP4"></video><div id="output"></div><script type="text/javascript">(function(){var video, output;var scale = 0.8;var initialize = function() {output = document.getElementById("output");video = document.getElementById("video");video.addEventListener('loadeddata',captureImage);};&nbsp;var captureImage = function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var canvas = document.createElement("canvas");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; canvas.width = video.videoWidth * scale;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; canvas.height = video.videoHeight * scale;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var img = document.createElement("img");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; img.src = canvas.toDataURL("image/png");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.appendChild(img);};&nbsp;initialize();})();</script></body></html>也是在这里面找到的。你试下
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript