Get frame numbers in HTML5 Video

前端 未结 3 1338
萌比男神i
萌比男神i 2020-12-08 16:30

I am trying to capture each frame number of the video however it looks like there is no way of achieving it. So I started my own clock to match the frame numbers of the vid

3条回答
  •  孤街浪徒
    2020-12-08 17:16

    I found something on github for this. https://github.com/allensarkisyan/VideoFrame

    I have implemented it in this fiddle: https://jsfiddle.net/k0y8tp2v/

    var currentFrame = $('#currentFrame');
    var video = VideoFrame({
        id : 'video',
        frameRate: 25,
        callback : function(frame) {
            currentFrame.html(frame);
        }
    });
    
    $('#play-pause').click(function(){
        if(video.video.paused){
            video.video.play();
            video.listen('frame');
            $(this).html('Pause');
        }else{
            video.video.pause();
            video.stopListen();
            $(this).html('Play');
        }
    });
    

    EDIT: updated fiddle to new video so it works again.

    EDIT: As pointed out, the video is 25fps, so I updated it, and while I was there removed reliance on jQuery.
    Non jQuery version:
    https://jsfiddle.net/k0y8tp2v/1/

    var currentFrame = document.getElementById('currentFrame');
    var video = VideoFrame({
        id : 'video',
        frameRate: 25,
        callback : function(frame) {
            currentFrame.innerHTML = frame ;
        }
    });
    
    document.getElementById('play-pause').addEventListener('click', function(e){
        if(video.video.paused){
            video.video.play();
            video.listen('frame');
            e.target.innerHTML = 'Pause';
        }else{
            video.video.pause();
            video.stopListen();
            e.target.innerHTML = 'Play';
        }
    });
    

提交回复
热议问题