summaryrefslogtreecommitdiff
path: root/rotord/src/rotor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/src/rotor.cpp')
-rwxr-xr-xrotord/src/rotor.cpp30
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;