<!DOCTYPE html>
<html>
<body>
<video width="400" controls>
<source src="mov_bbb.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
<p>These are the frames' images generated by getVideoImage():</p>
<ol id="olFrames"></ol>
<script type="text/JavaScript">
function getVideoImage(path, secs, callback) {
var me = this, video = document.createElement('video');
video.onloadedmetadata = function() {
if ('function' === typeof secs) {
secs = secs(this.duration);
}
this.currentTime = Math.min(Math.max(0, (secs < 0 ? this.duration : 0) + secs), this.duration);
};
video.onseeked = function(e) {
var canvas = document.createElement('canvas');
canvas.height = video.videoHeight;
canvas.width = video.videoWidth;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
var img = new Image();
img.src = canvas.toDataURL();
callback.call(me, img, this.currentTime, e);
};
video.onerror = function(e) {
callback.call(me, undefined, undefined, e);
};
video.src = path;
}
function showImageAt(secs) {
var duration;
getVideoImage(
"mov_bbb.mp4",
function(totalTime) {
duration = totalTime;
return secs;
},
function(img, secs, event) {
if (event.type == 'seeked') {
var li = document.createElement('li');
li.innerHTML += '<b>Frame at second ' + secs + ':</b><br />';
li.appendChild(img);
document.getElementById('olFrames').appendChild(li);
if (duration >= ++secs) {
showImageAt(secs);
};
}
}
);
}
showImageAt(0);
</script>
</body>
</html>
view raw
Code Example |
---|
Html :: rounded borders svg |
Html :: unordered list html |
Html :: double underline in html |
Html :: html small text |
Html :: use js variable in form action |
Html :: template html |
Html :: creating a table in html |
Html :: html new line without <br |
Html :: mailto html multiple addresses |
Html :: best html emmet extension for vs code |
Html :: change css angular binding |
Html :: HTML5 Video tag not working in Safari , iPhone and iPad |
Html :: change source of iframe attribute target |
Html :: the function tag in js |
Html :: elseif vuejs |
Html :: vue click escape key |
Html :: status 201 |
Html :: lorem ipsum generator |
Html :: smarty print html |
Html :: html article |
Html :: form row twig symfony |
Html :: table bootstrap |
Html :: liens hypertexte html mdn |
Html :: html radio input |
Html :: commento in html |
Html :: The <textarea Element |
Html :: react font color |
Html :: underline text html |
Html :: custom radio css |
Html :: justify content align items |