summaryrefslogtreecommitdiff
path: root/rotord/src
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/src')
-rw-r--r--rotord/src/rotor.h100
1 files changed, 52 insertions, 48 deletions
diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h
index a3e65ae..3bbf5b4 100644
--- a/rotord/src/rotor.h
+++ b/rotord/src/rotor.h
@@ -471,7 +471,49 @@ namespace Rotor {
logger.error("libav::decoder failed to load "+filename);
return false;
}
+ bool get_frame(float wanted,const Frame_spec &frame){
+ if (attributes["frame_mode"]->intVal==VIDEOFRAMES_blend){
+ if (((int)wanted)!=Base_video::lastframe){
+ //get a new pair of frames possibly by switching the next one
+ //darn peculiar, as if copying wasn't actually copying
+ if ((Base_video::lastframe==(((int)wanted)-1))&&(in2.w>0)) {
+ in1=in2;
+ }
+ else {
+ player.fetch_frame(frame.w,frame.h,(int)wanted);
+ //use a temp image because setup_fromRGB just copies pointer
+ temp.setup_fromRGB(frame.w,frame.h,player.frame->Data[0],player.frame->Linesize[0]-(frame.w*3));
+ in1=temp;
+ }
+ player.fetch_frame(frame.w,frame.h,((int)wanted+1)%max(1,player.get_number_frames()));
+ temp.setup_fromRGB(frame.w,frame.h,player.frame->Data[0],player.frame->Linesize[0]-(frame.w*3));
+ in2=temp;
+ lastframe=wanted;
+ }
+ float amt=1.0f-(wanted-((int)wanted));
+ //cout<<"video loader time:"<<frame.time<<" frames "<<((int)wanted)<<" (x"<<amt<<"),"<<(((int)wanted+1)%max(1,player.get_number_frames()))<<endl;
+ image=in1;
+ image*=amt;
+ //Image in2t=in2; //DOES NOT WORK, copies pointer by assignation
+ in2t=in2;
+ in2t*=(1.0f-amt);
+ image+=in2t;
+ }
+ else {
+ if (((int)wanted)!=Base_video::lastframe){
+ if (!player.fetch_frame(frame.w,frame.h,((int)wanted))) { //seek fail
+ Poco::Logger& logger = Poco::Logger::get("Rotor");
+ logger.error("Video_loader failed to seek frame "+toString(wanted)+" of "+attributes["filename"]->value);
+
+ if (image.w>0) return &image; //just return the previous frame if possible
+ else return nullptr;
+ }
+ image.setup_fromRGB(frame.w,frame.h,player.frame->Data[0],player.frame->Linesize[0]-(frame.w*3));
+ }
+ }
+ }
protected:
+ Image in1,in2,in2t,temp; //for blend frames;
libav::video_decoder player;
int lastframe;
bool isLoaded;
@@ -529,53 +571,13 @@ namespace Rotor {
break;
}
}
- if (attributes["frame_mode"]->intVal==VIDEOFRAMES_blend){
- if (((int)wanted)!=lastframe){
- //get a new pair of frames possibly by switching the next one
- //darn peculiar, as if copying wasn't actually copying
- if ((lastframe==(((int)wanted)-1))&&(in2.w>0)) {
- in1=in2;
- }
- else {
- player.fetch_frame(frame.w,frame.h,(int)wanted);
- //use a temp image because setup_fromRGB just copies pointer
- temp.setup_fromRGB(frame.w,frame.h,player.frame->Data[0],player.frame->Linesize[0]-(frame.w*3));
- in1=temp;
- }
- player.fetch_frame(frame.w,frame.h,((int)wanted+1)%max(1,player.get_number_frames()));
- temp.setup_fromRGB(frame.w,frame.h,player.frame->Data[0],player.frame->Linesize[0]-(frame.w*3));
- in2=temp;
- lastframe=wanted;
- }
- float amt=1.0f-(wanted-((int)wanted));
- //cout<<"video loader time:"<<frame.time<<" frames "<<((int)wanted)<<" (x"<<amt<<"),"<<(((int)wanted+1)%max(1,player.get_number_frames()))<<endl;
- image=in1;
- image*=amt;
- //Image in2t=in2; //DOES NOT WORK, copies pointer by assignation
- in2t=in2;
- in2t*=(1.0f-amt);
- image+=in2t;
- }
- else {
- if (((int)wanted)!=lastframe){
- if (!player.fetch_frame(frame.w,frame.h,((int)wanted))) { //seek fail
- Poco::Logger& logger = Poco::Logger::get("Rotor");
- logger.error("Video_loader failed to seek frame "+toString(wanted)+" of "+attributes["filename"]->value);
-
- if (image.w>0) return &image; //just return the previous frame if possible
- else return nullptr;
- }
- image.setup_fromRGB(frame.w,frame.h,player.frame->Data[0],player.frame->Linesize[0]-(frame.w*3));
- }
- }
- return &image;
+ if (get_frame(wanted,frame)) return &image;
}
return nullptr;
};
Video_loader* clone(map<string,string> &_settings) { return new Video_loader(_settings);};
bool isLoaded;
private:
- Image in1,in2,in2t,temp; //for blend frames;
string *filename;
};
class Video_bank: public Base_video {
@@ -584,12 +586,13 @@ namespace Rotor {
//blend mode etc
//there may be a total of 4 frames required
//and 2 videos open
+ //is there any way to re-use the parts which prepare frames
Video_bank(){
create_attribute("filenames","names of video files to load","File names","",{},"array");
UID="73616e66-4306-11e3-981e-74d02b29f6a6";
title="Video bank";
description="Loads a banks of video files";
- video_loaded=0;
+ clip_loaded=0; //uses 1-index
};
Video_bank(map<string,string> &settings): Video_bank() {
base_settings(settings);
@@ -600,13 +603,14 @@ namespace Rotor {
float ph=inputs[0]->get((Time_spec)frame);
int wv=((int)ph)%attributes["filenames"]->vals.size();
ph=fmod(ph,wv);
- if (video_loaded!=wv+1){
- if (load(media_path+attributes["filenames"]->vals[wv]){
- video_loaded=wv+1;
+ if (clip_loaded!=wv+1){
+ if (load(media_path+attributes["filenames"]->vals[wv] )) {
+ clip_loaded=wv+1;
}
- else video_loaded=0;
+ else clip_loaded=0;
}
- if (video_loaded){
+ if (clip_loaded){
+ int wanted=ph*player.get_number_frames();
}
@@ -618,7 +622,7 @@ namespace Rotor {
};
private:
- int video_loaded;
+ int clip_loaded;
int last_frame;
float segment_duration; //to allow play within a segment at original speed
string media_path;