diff options
Diffstat (limited to 'rotord')
| -rw-r--r-- | rotord/graph.cpp | 2 | ||||
| -rwxr-xr-x | rotord/rotor.cpp | 34 | ||||
| -rwxr-xr-x | rotord/rotor.h | 28 |
3 files changed, 53 insertions, 11 deletions
diff --git a/rotord/graph.cpp b/rotord/graph.cpp index 69c4811..fc9a129 100644 --- a/rotord/graph.cpp +++ b/rotord/graph.cpp @@ -54,8 +54,8 @@ bool Graph::load(string &filename){ settings["description"]=xml.getValue("node","",i1); Node* node=factory.create(settings); if (node) { - cerr << "Rotor: created '" << xml.getAttribute("node","type","",i1) << "'" << endl; string nodeID=xml.getAttribute("node","ID","",i1); + cerr << "Rotor: created node '"<<nodeID<<"': '"<< xml.getAttribute("node","type","",i1) << "'" << endl; nodes[nodeID]=node; if(xml.pushTag("node",i1)) { int n2=xml.getNumTags("signal_input"); diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 23e2196..84578db 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -166,9 +166,9 @@ bool Video_output::render(const float duration, const float framerate,const stri int frameRate=25; AVCodecID codecId=AV_CODEC_ID_MPEG4; std::string container ="mov"; - std::string input ="01.mp3"; - bool usingaudio=audioloader.setup(input); + bool usingaudio=audioloader.setup(audio_filename); + //at the moment it crashes if you render before audio is loaded if (exporter->setup(outW,outH,bitRate,frameRate,container)) { //codecId, if (exporter->record(output_filename)) { @@ -177,7 +177,9 @@ bool Video_output::render(const float duration, const float framerate,const stri float step=1.0f/framerate; float v=0.0f; for (float f=0.0f;f<duration;f+=step) { - if (!exporter->encodeFrame(get_output(Frame_spec(f,framerate,outW,outH))->RGBdata,audioloader.get_samples(exporter->get_audio_framesize()))){ + uint16_t* s=audioloader.get_samples(exporter->get_audio_framesize()); + Image* i=get_output(Frame_spec(f,framerate,outW,outH)); + if (!exporter->encodeFrame(i->RGBdata,s)){ //if (!exporter->encodeFrame(get_output(Frame_spec(f,framerate,outW,outH))->RGBdata,audioloader.get_packet())){ cerr << "Rotor: video output failed"<<endl; break; @@ -193,10 +195,17 @@ bool Video_output::render(const float duration, const float framerate,const stri } bool Video_input::load(const string &filename){ - if (player->loadMovie(filename)){ + //gstreamer needs absolute paths ALWAYS + //string uri="file:///home/tim/workspace/rotor/rotord/"+filename; + Poco::Path path; + string uri="file://"+path.current()+filename; + //cerr << "video input: loading "<<uri<<endl; + if (player->loadMovie(uri)){ player->play(); player->setPaused(true); - cerr<<"loaded "<<filename<<", "<<player->getDuration()<<" seconds "<<", "<<player->getWidth()<<"x"<<player->getWidth()<<endl; + player->update(); + cerr<<"Rotor::Video_input loaded "<<filename<<", "<<player->getDuration()<<" seconds "<<", "<<player->getWidth()<<"x"<<player->getHeight()<<endl; + image->setup_fromRGB(player->getWidth(),player->getHeight(),(uint8_t*) player->getPixels()); return true; } return false; @@ -209,5 +218,20 @@ Image* Video_input::get_output(const Frame_spec &frame){ // image.setup(player) //} + + //deal with reolution: swscale from avcodec or put scaler in pipeline? + //can image node point to buffer in gst rather than copying the pixels? + + //to test using fp time to seek: need a short movie with synced audio + + //fix actual duration and audio file + //trace frame that is being read + if (player->isLoaded()){ + //player->setPosition(frame.time); + player->setFrame((int) (frame.time*frame.framerate)); + player->update(); + cerr<<"Video_input: retrieving frame "<<((int) (frame.time*frame.framerate))<<endl; + return image; + } return nullptr; }; diff --git a/rotord/rotor.h b/rotord/rotor.h index f530bc3..2915fb6 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -66,6 +66,7 @@ main definitions of libavcodec.h are in utils.c #include "Poco/AutoPtr.h" #include "Poco/File.h" #include "Poco/Base64Encoder.h" +#include "Poco/Path.h" #include <iostream> using Poco::UUID; @@ -160,9 +161,9 @@ namespace Rotor { free(); }; void free(){ - if (RGBdata) delete[] RGBdata; - if (Adata) delete[] Adata; - if (Zdata) delete[] Zdata; + if (RGBdata&&ownsRGBdata) delete[] RGBdata; + if (Adata&&ownsAdata) delete[] Adata; + if (Zdata&&ownsZdata) delete[] Zdata; zero(); } void zero(){ @@ -171,23 +172,40 @@ namespace Rotor { Zdata=nullptr; w=0; h=0; + ownsRGBdata=ownsAdata=ownsZdata=false; } - bool setup(int _w,int _h){ - if (w!=_w||h!=_h){ + bool setup(int _w,int _h){ //set up with internal data + if (w!=_w||h!=_h||!ownsRGBdata||!ownsAdata||!ownsZdata){ free(); w=_w; h=_h; RGBdata=new uint8_t[w*h*3]; Adata=new uint8_t[w*h]; Zdata=new uint16_t[w*h]; + ownsRGBdata=ownsAdata=ownsZdata=true; return true; } else return false; } + bool setup_fromRGB(int _w,int _h,uint8_t *pRGBdata){ //possibility of just resetting pointer? + if (w!=_w||h!=_h||ownsRGBdata||!ownsAdata||!ownsZdata){ + free(); + w=_w; + h=_h; + RGBdata=pRGBdata; + Adata=new uint8_t[w*h]; + Zdata=new uint16_t[w*h]; + ownsRGBdata=false; + ownsAdata=ownsZdata=true; + return true; + } + return false; + } uint8_t *RGBdata; uint8_t *Adata; uint16_t *Zdata; int h,w; + bool ownsRGBdata,ownsAdata,ownsZdata; //better done through auto_ptr? }; class Time_spec{ public: |
