From f85ec9a68e6fab7265c3c2b78ab0fabf8310dacd Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 3 Jul 2013 15:41:25 +0100 Subject: squashed frame retieval bug --- rotord/libavwrapper.cpp | 23 ++++++++++++++++++++++- rotord/rotor.cpp | 3 +-- rotord/rotor.h | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/rotord/libavwrapper.cpp b/rotord/libavwrapper.cpp index 97315a6..08d943f 100755 --- a/rotord/libavwrapper.cpp +++ b/rotord/libavwrapper.cpp @@ -211,9 +211,30 @@ bool libav::decoder::openUsingInitializedContainer(enum PixelFormat formatParam) if( pCtx->time_base.num > 1000 && pCtx->time_base.den == 1 ) pCtx->time_base.den = 1000; + //cerr<<"stream frame rate:"<streams[videoStream]->r_frame_rate.num<<"/"<streams[videoStream]->r_frame_rate.den<duration<time_base.num<<"/"<time_base.den<duration / (double)AV_TIME_BASE ) * pCtx->time_base.den + 0.5); + //numFrames = (int)(( container->duration / (double)AV_TIME_BASE ) * pCtx->time_base.den + 0.5); + //this approach just seems wrong! + + + + numFrames=container->streams[videoStream]->nb_frames-1; + + if (numFrames<1){ + //some codecs don't keep this info in the header + float fr=((float)container->streams[videoStream]->r_frame_rate.num)/container->streams[videoStream]->r_frame_rate.den; + numFrames = (int)(( container->duration / (double)AV_TIME_BASE ) * fr ); + //this approach still doesn't seem to give quite the right answer- comes out a little too big + //could alternatively just redefine the length if the reader fails + } + + init_buffers_and_scaler(); diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 67918f5..c929fae 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -250,7 +250,6 @@ bool Video_output::render(const float duration, const float framerate,const stri // //setup defaults int bitRate=5000000; - int frameRate=25; AVCodecID codecId=AV_CODEC_ID_H264; //MPEG4; std::string container ="mp4"; @@ -260,7 +259,7 @@ bool Video_output::render(const float duration, const float framerate,const stri float spct=100.0f/duration; - if (exporter.setup(outW,outH,bitRate,frameRate,container)) { //codecId, + if (exporter.setup(outW,outH,bitRate,framerate,container)) { //codecId, if (exporter.record(output_filename)) { libav::audioloader audioloader; diff --git a/rotord/rotor.h b/rotord/rotor.h index 92d6e45..b24ae51 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -1178,9 +1178,9 @@ namespace Rotor { }; class Graph{ public: - Graph(){duration=5.0f;loaded = false;outW=640;outH=360;}; + Graph(){duration=20.0f;loaded = false;outW=640;outH=360;}; Graph(const string& _uid,const string& _desc){init(_uid,_desc);}; - void init(const string& _uid,const string& _desc){ uid=_uid;description=_desc;duration=5.0f;}; + void init(const string& _uid,const string& _desc){ uid=_uid;description=_desc;duration=20.0f;}; string uid; //every version of a graph has a UUID, no particular need to actually read its data(?) //?? is it faster than using strings?? string description; -- cgit v1.2.3