diff options
Diffstat (limited to 'rotord')
| -rw-r--r-- | rotord/Makefile | 2 | ||||
| -rw-r--r-- | rotord/cvimage.h | 5 | ||||
| -rwxr-xr-x | rotord/rotor.cpp | 66 | ||||
| -rwxr-xr-x | rotord/rotor.h | 69 |
4 files changed, 76 insertions, 66 deletions
diff --git a/rotord/Makefile b/rotord/Makefile index 86ae740..270cd8c 100644 --- a/rotord/Makefile +++ b/rotord/Makefile @@ -9,7 +9,7 @@ MY_CFLAGS = -fpermissive -std=c++11 -I /usr/include/opencv # -I ../ffmpeg # The linker options.libgstaasinklibgstaasink.so -MY_LIBS = -lopencv_core -lopencv_video -lopencv_highgui -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil -lstdc++ -lm +MY_LIBS = -lopencv_core -lopencv_video -lopencv_imgproc -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil -lstdc++ -lm #MY_LIBS = -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil $(shell pkg-config gstreamer-0.10 gstreamer-video-0.10 gstreamer-base-0.10 --libs) # -lgstreamer-0.10 -lgstreamer-video-0.10 -lgstreamer-base-0.10 -lglib-2.0 -lgstapp-0.10 #MY_LIBS = ../libavcodec/ffmpeg/libavcodec/libavcodec.a ../libavcodec/ffmpeg/libavutil/libavutil.a ../libavcodec/ffmpeg/libavformat/libavformat.a ../libavcodec/ffmpeg/libavfilter/libavfilter.a ../libavcodec/ffmpeg/libavdevice/libavdevice.a -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk diff --git a/rotord/cvimage.h b/rotord/cvimage.h index a538d4e..cbf2840 100644 --- a/rotord/cvimage.h +++ b/rotord/cvimage.h @@ -105,10 +105,11 @@ namespace Rotor { else return false; */ } - bool setup_fromRGB(int _w,int _h,uint8_t *pRGBdata){ + bool setup_fromRGB(int _w,int _h,uint8_t *pRGBdata,int linepadding=0){ //here the data belongs to libavcodec or other //could move to using cv::Mat there also and just passing cv:Mat over - rgb=cv::Mat(_w,_h,CV_8UC3,pRGBdata); + std::cerr<<"creating cv::Mat with step= "<<((_w*3)+linepadding)<<std::endl; + rgb=cv::Mat(_w,_h,CV_8UC3,pRGBdata,(_w*3)+linepadding); RGBdata=rgb.data; //can move to use the bare pointer eventually ownsRGBdata=false; //will not be necessary w=_w; diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index dd98ac3..36ce750 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -29,6 +29,7 @@ Node_factory::Node_factory(){ add_type("blend",new Blend()); add_type("mirror",new Mirror()); add_type("monochrome",new Monochrome()); + add_type("transform",new Transform()); } bool Signal_input::connect(Signal_node* source) { @@ -183,68 +184,6 @@ void Audio_analysis::print_features(){ } cerr<<endl; } -/* - -bool Video_output::render(const float duration, const float framerate,const string &output_filename,const string &audio_filename,float& progress){ - - // - //setup defaults - int outW=640; - int outH=360; - int bitRate=4000000; - int frameRate=25; - AVCodecID codecId=AV_CODEC_ID_MPEG4; - std::string container ="mov"; - - bool usingaudio=audioloader.setup(audio_filename); - //at the moment it crashes if you render before audio is loaded - - float spct=100.0f/duration; - - //if (exporter->setup(outW,outH,bitRate,frameRate,container)) { //codecId, - // if (exporter->record(output_filename)) { - libav::encoder encoder=libav::encoder(output_filename.c_str(),outW,outH,framerate); - - //cerr << "Rotor: Video_output rendering " << duration << " seconds at " << framerate << " fps, audio frame size: " << exporter->get_audio_framesize()<<endl; - //25fps video and 43.06640625fps audio? hmm - //how to get the timecodes correct for the interleaved files - - float vstep=1.0f/framerate; - float v=0.0f; - float vf=0.0f; - float af=0.0f; - while (vf<duration-vstep) { - if (usingaudio) { - while (!fless(af,vf)) { - //insert audio frames until we are ahead of the video - //exporter->encodeFrame(audioloader.get_samples(exporter->get_audio_framesize())); - //af+=exporter->get_audio_step(); - int fs=encoder.get_audio_framesize(); - uint16_t *s=audioloader.get_samples(fs); - encoder.write_frame(af,s); //crashes - s seems to be 0x00 - af+=encoder.get_audio_step(); - } - } - Image* i=get_output(Frame_spec(vf,framerate,duration,outW,outH)); - if (i) { - //exporter->encodeFrame(i->RGBdata); - - //encoder->picture_rgb.pts=; - encoder.write_frame(vf,i->RGBdata); - } - vf+=vstep; - progress=vf/duration; - } - - //exporter->finishRecord(); - cerr << "Rotor: Video_output finished "<< endl; - return true; - // } - //} - - //return false; -} -*/ bool Video_output::render(const float duration, const float framerate,const string &output_filename,const string &audio_filename,float& progress,int outW,int outH){ @@ -397,7 +336,8 @@ Image* Video_loader::output(const Frame_spec &frame){ 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]); + cerr<<"setting up frame: lineoffset="<<(player.pFrameRGB->linesize[0]-(frame.w*3))<<endl; + image.setup_fromRGB(frame.w,frame.h,player.pFrameRGB->data[0],player.pFrameRGB->linesize[0]-(frame.w*3)); return ℑ } diff --git a/rotord/rotor.h b/rotord/rotor.h index 953a69b..3f51d79 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -1160,6 +1160,75 @@ namespace Rotor { private: Image image; }; + class Transform: public Image_node { + //what is the best coordinate system to use? + //origin: corner or centre + //units: pixel or fractional + //aspect: scaled or homogenous + public: + Transform(){}; + Transform(map<string,string> &settings) { + base_settings(settings); + tX=find_setting(settings,"transformX",0.0f); + tY=find_setting(settings,"transformY",0.0f); + oX=find_setting(settings,"originX",0.5f); + oY=find_setting(settings,"originX",0.5f); + r=find_setting(settings,"rotation",0.0f); + s=find_setting(settings,"scale",1.0f); + }; + ~Transform(){ + }; + Transform* clone(map<string,string> &_settings) { return new Transform(_settings);}; + Image *output(const Frame_spec &frame){ + if (image_inputs.size()) { + if (image_inputs[0]->connection){ + Image *other=(((Image_node*)image_inputs[0]->connection)->get_output(frame)); + if (other) { + image.setup(other->w,other->h); + //do opencv transform + cv::Point2f srcTri[3], dstTri[3]; + cv::Mat rot_mat(2,3,CV_32FC1); + cv::Mat trans_mat(2,3,CV_32FC1); + + /* + Image inter; + inter.setup(other->w,other->h); + // Compute matrix by creating triangle and transforming + //is there a better way - combine the 2? Just a bit of geometry + srcTri[0].x=0; + srcTri[0].y=0; + srcTri[1].x=other->w-1; + srcTri[1].y=0; + srcTri[2].x=0; + srcTri[2].y=other->h-1; + for (int i=0;i<3;i++){ + dstTri[i].x=srcTri[i].x+(tX*other->w); + dstTri[i].y=srcTri[i].y+(tY*other->h); + } + trans_mat=getAffineTransform( srcTri, dstTri ); + warpAffine( other->rgb, inter.rgb, trans_mat, inter.rgb.size() ); + */ + + // Compute rotation matrix + // + cv::Point centre = cv::Point( oX*other->w, oY*other->h ); + + rot_mat = getRotationMatrix2D( centre, r, s ); + // Do the transformation + // + warpAffine( other->rgb, image.rgb, rot_mat, image->rgb.size() ); + + return ℑ + } + } + } + return nullptr; + } + private: + Image image; + float tX,tY,oX,oY,r,s; + //todo - quality settings + }; //------------------------------------------------------------------- class Node_factory{ public: |
