diff options
| -rw-r--r-- | rotord/libavaudioloader.h | 7 | ||||
| -rw-r--r-- | rotord/rendercontext.cpp | 10 | ||||
| -rwxr-xr-x | rotord/rotor.cpp | 33 | ||||
| -rw-r--r-- | rotord/utils.cpp | 7 | ||||
| -rw-r--r-- | rotord/utils.h | 1 |
5 files changed, 41 insertions, 17 deletions
diff --git a/rotord/libavaudioloader.h b/rotord/libavaudioloader.h index 1197fbb..8c4ddf1 100644 --- a/rotord/libavaudioloader.h +++ b/rotord/libavaudioloader.h @@ -22,12 +22,15 @@ namespace libav { AVPacket* get_packet(); bool close(); bool ready; + + AVCodecContext* codecContext; + AVFormatContext* formatContext; private: std::vector<uint16_t> buffer; AVFrame* frame; - AVFormatContext* formatContext; + AVStream* audioStream; - AVCodecContext* codecContext; + AVPacket packet; int sample_end; int sample_start; diff --git a/rotord/rendercontext.cpp b/rotord/rendercontext.cpp index cdb1cf7..fc5936b 100644 --- a/rotord/rendercontext.cpp +++ b/rotord/rendercontext.cpp @@ -18,7 +18,7 @@ void Render_context::runTask() { for (auto a: analysers) { processors.push_back(dynamic_cast<Base_audio_processor*>(a)); } - if (load_audio(audio_filename,processors)) { + if (_load_audio(audio_filename,processors)) { audio_loaded=true; state=IDLE; } @@ -272,10 +272,16 @@ Command_response Render_context::session_command(const std::vector<std::string>& //http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/ //great to use c++11 features bool Render_context::load_audio(const string &filename,vector<Base_audio_processor*> processors){ + audioloader.setup(filename); + av_dump_format(audioloader.formatContext, 0, 0, false); //avformat.h line 1256 + int samples = ((audioloader.formatContext->duration + 5000)*audioloader.codecContext->sample_rate)/AV_TIME_BASE; + graph.duration=((float)audioloader.formatContext->duration)/AV_TIME_BASE; + + for (auto p: processors) { - if(!p->init(codecContext->channels,16,samples,codecContext->sample_rate) ){ + if(!p->init(audioloader.codecContext->channels,audioloader.codecContext->bits_per_raw_sample,samples,audioloader.codecContext->sample_rate) ){ cerr<<"Plugin failed to initialse"<<endl; return false; } diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 46bc9c9..67f8c0c 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -182,24 +182,32 @@ bool Video_output::render(const float duration, const float framerate,const stri float vf=0.0f; float af=0.0f; while (vf<duration) { //float f=0.0f;f<duration;f+=step) { - //seems to be that the audio frames have to be a little ahead - //and the frame->pts comes from video - while (flessorequal(vf,af)) { - //insert audio frames until we are ahead of the video - uint16_t* s=audioloader.get_samples(exporter->get_audio_framesize()); - exporter->encodeFrame(s); - af+=exporter->get_audio_step(); - } + cerr << "Rotor: rendering frame "<<progress<< endl; + if (progress>0.998) { + //stop here + int nothing=0; + //seems that the last frame of samples causes std::max to have <error reading variables> + } + else { //DIRTY HACK + //seems to be that the audio frames have to be a little ahead + //and the frame->pts comes from video + while (fless(vf,af)) { + //insert audio frames until we are ahead of the video + uint16_t* s=audioloader.get_samples(exporter->get_audio_framesize()); + if (s) { + exporter->encodeFrame(s); + } + af+=exporter->get_audio_step(); + } + } Image* i=get_output(Frame_spec(vf,framerate,outW,outH)); if (i) { exporter->encodeFrame(i->RGBdata); } vf+=vstep; progress=vf/duration; - if (progress>0.99) { - //stop here - //seems that the last frame of samples causes std::max to have <error reading variables> - } + + /* if (!exporter->encodeFrame(i->RGBdata)){ //if (!exporter->encodeFrame(get_output(Frame_spec(f,framerate,outW,outH))->RGBdata,audioloader.get_packet())){ @@ -215,6 +223,7 @@ bool Video_output::render(const float duration, const float framerate,const stri } */ } + exporter->finishRecord(); cerr << "Rotor: Video_output finished "<< endl; return true; diff --git a/rotord/utils.cpp b/rotord/utils.cpp index d357319..9e8beb6 100644 --- a/rotord/utils.cpp +++ b/rotord/utils.cpp @@ -1,4 +1,4 @@ -#include "utils.h" +#include "utils.h" using namespace std; @@ -17,3 +17,8 @@ bool fmoreorequal(const float u,const float v){ if (v-u>-.001) return true; else return false; }; +bool fless(const float u,const float v){ + //v is less or equal to u + if (u-v>.001) return true; + else return false; +}; diff --git a/rotord/utils.h b/rotord/utils.h index e9084ff..c0c9752 100644 --- a/rotord/utils.h +++ b/rotord/utils.h @@ -4,3 +4,4 @@ bool fequal(const float u,const float v); bool flessorequal(const float u,const float v); bool fmoreorequal(const float u,const float v); +bool fless(const float u,const float v); |
