From 5d0dbb41b66792662170ce86334bf4cba87ed700 Mon Sep 17 00:00:00 2001 From: Comment Date: Mon, 4 Nov 2013 00:58:36 +0000 Subject: video bank --- rotord/src/rotor.h | 100 ++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'rotord/src') 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:"<value); + + if (image.w>0) return ℑ //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:"<value); - - if (image.w>0) return ℑ //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 ℑ + if (get_frame(wanted,frame)) return ℑ } return nullptr; }; Video_loader* clone(map &_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 &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; -- cgit v1.2.3