I am using Affectiva's Emotion SDK for Javascript to play and analyze a video file. Currently, I am playing the video as a stream and capturing emotion features following their "Analyze a video frame stream" tutorial. However, I want to process the video file in batch rather than taking the whole duration of the video to analyze.
Increasing the playback rate of the video helped speed up this processes. I have also tried to skip frames by seeking ahead in the video but the performance was disappointing. Does anyone know of a way to process the video file that isn't bottlenecked by the playback rate of the video?
I was able to solve this problem (albeit probably not very efficient) by using seeking with a lower fps. Essentially in the detector's "onImageResultsSuccess" function, I call the function nextFrame which skips ahead in the video by an amount I set with the variable fps. Which calls the "seeked" event on the video element which can then call the captureImage function that triggers the detector creating a loop that runs until the whole video is analyzed. Below is a portion of the code as well as jsfiddle implementation.
var nextFrame = function() {
// when frame is captured, increase
vidTimeStamp = vidTimeStamp + (1 / fps);
// if we are not passed end, seek to next interval
if (vidTimeStamp <= video.duration) {
// this will trigger another seeked event
message_text.innerHTML = ((vidTimeStamp / video.duration) * 100).toFixed(2) + "% completed";
video.currentTime = vidTimeStamp;
} else {
// DONE!, next action
message_text.innerHTML = "100% Completed";
alert("Video Processed");
download_btn.click();
}
};
video.addEventListener("seeked", function(e) {
// now video has seeked and current frames will show
// at the time as we expect
captureImage(vidTimeStamp);
});