Search code examples
javascripthtml5-videoframe-rate

frames per second issue


Hi I have created a function which converts the hours, minutes and frames per second which is ->

 function toHHMMSS(seconds) {
    var sec_num = parseInt(seconds);
    var hours = Math.floor(sec_num / 3600);
    var parshours = parseInt(hours);


    var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
    var parsmin = parseInt(minutes);

    var seconds = sec_num - (hours * 3600) - (minutes * 60);
    var parssec = parseInt(seconds);       

    if (parshours < 10) { parshours = "0" + parshours; }
    if (parsmin < 10) { parsmin = "0" + parsmin; }
    if (parssec < 10) { parssec = "0" + parssec; }

    // calculation for frames
    var vidframes = document.getElementById('video');
    timeFloat = parseInt(vidframes.currentTime * 25).toPrecision(4) / 60;
    if (timeFloat > 25) {
        timeFloat = 0;
    }

    frametestout = timeFloatOut - timeFloat;
    frames = frametestout * frameRate;       

    var time = parshours + ':' + parsmin + ':' + parssec + ':' + timeFloat;       

    return time;
}
 var timeFloat;
var timeFloatOut;


function getCurTime(e) {
    var vid = document.getElementById('video');
    timeFloat = parseInt(vid.currentTime);
    var timeintime = document.getElementById('timein').innerHTML = toHHMMSS(timeFloat);
}

function getOutTime(e) {
    var vid = document.getElementById('video');
    timeFloatOut = parseInt(vid.currentTime);
    var timeouttime = document.getElementById('timeOut').innerHTML = toHHMMSS(timeFloatOut);
    var framecount = document.getElementById('frameCount').innerHTML = frames;
}

$("#btnTime").kendoButton({
    click: getCurTime
});


$("#btnTimeOut").kendoButton({
    click: getOutTime
});

}

The issue is I need the frames to reset after each second. rather than continuously incrementing.

Any help would be appreciated.


Solution

  • wouldn't that do the trick?

    setTimeout(function(){
      frames = 0;
    },1000);