diff options
| author | Tim Redfern <tim@herge.(none)> | 2013-08-08 13:32:46 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@herge.(none)> | 2013-08-08 13:32:46 +0100 |
| commit | a2254447b138af7fc0719e5a107816487255736b (patch) | |
| tree | fc72463364bd158b5a042ac821766f466efdfcb0 /rotord/src/rotor.cpp | |
| parent | 1f8aca919df6ab2d2636cddaa30de1e388b4c09d (diff) | |
basic speed control for video_loader
Diffstat (limited to 'rotord/src/rotor.cpp')
| -rwxr-xr-x | rotord/src/rotor.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp index f96fbc3..c7e7bc7 100755 --- a/rotord/src/rotor.cpp +++ b/rotord/src/rotor.cpp @@ -282,7 +282,7 @@ bool Video_loader::load(const string &_filename){ string uri="file://"+_filename; isLoaded=player.open(uri); if (isLoaded){ - logger.information("Video_loader loaded "+filename+": "+ofToString(player.getNumberOfFrames())+" frames, "+ofToString(player.getWidth())+"x"+ofToString(player.getHeight())); + logger.information("Video_loader loaded "+filename+": "+ofToString(player.getNumberOfFrames())+" frames, "+ofToString(player.getFrameRate())+" fps, "+ofToString(player.getWidth())+"x"+ofToString(player.getHeight())); return true; } @@ -293,16 +293,26 @@ bool Video_loader::load(const string &_filename){ Image* Video_loader::output(const Frame_spec &frame){ if (isLoaded){ - int wanted=(((int) ((frame.time*frame.framerate)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1? + //this approach is running into the inability to seek when requesting playback speed > 1. + //need to cache frames so as to avoid asking for a frame other than the next one. + //need an algorithm to find the previous keyframe and seek forward - if (!player.fetchFrame(frame.w,frame.h,wanted)) { //seek fail - Logger& logger = Logger::get("Rotor"); - logger.error("Video_loader failed to seek frame "+ofToString(wanted)+" of "+filename); - - if (image.w>0) return ℑ //just return the previous frame if possible - else return nullptr; - }; - image.setup_fromRGB(frame.w,frame.h,player.pFrameRGB->data[0],player.pFrameRGB->linesize[0]-(frame.w*3)); + float clipframerate=(framerate==0.0f?player.getFrameRate():framerate); + + float clipspeed=(clipframerate/frame.framerate)*speed; + + int wanted=(((int) ((frame.time*frame.framerate*clipspeed)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1? + if (wanted!=lastframe){ + if (!player.fetchFrame(frame.w,frame.h,wanted)) { //seek fail + Logger& logger = Logger::get("Rotor"); + logger.error("Video_loader failed to seek frame "+ofToString(wanted)+" of "+filename); + + if (image.w>0) return ℑ //just return the previous frame if possible + else return nullptr; + } + image.setup_fromRGB(frame.w,frame.h,player.pFrameRGB->data[0],player.pFrameRGB->linesize[0]-(frame.w*3)); + lastframe=wanted; + } return ℑ } return nullptr; |
