diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-09-11 16:11:47 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-09-11 16:11:47 +0100 |
| commit | f9694b7d4f1648a0fa984e7cc428bbc9eea86ca0 (patch) | |
| tree | 59e14e57c52e82927963ef71bf83de0f665c42cb /rotord/src/libavwrapper.h | |
| parent | 1f52520db005e056e131f511418e4b71bc9e89fd (diff) | |
ffms2 library for video loader
Diffstat (limited to 'rotord/src/libavwrapper.h')
| -rw-r--r-- | rotord/src/libavwrapper.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/rotord/src/libavwrapper.h b/rotord/src/libavwrapper.h index d30ea95..870815f 100644 --- a/rotord/src/libavwrapper.h +++ b/rotord/src/libavwrapper.h @@ -69,6 +69,8 @@ extern "C" { #include <math.h> #include <vector> +#include <ffms.h> + namespace libav { @@ -154,6 +156,68 @@ namespace libav { }; + class ffms2_decoder + { + public: + ffms2_decoder(){ + maybeInitFFMpegLib(); + pixfmts[0] = FFMS_GetPixFmt("rgb24"); + pixfmts[1] = -1; + h=0; + w=0; + videosource=NULL; + loaded=false; + errinfo.Buffer = errmsg; + errinfo.BufferSize = sizeof(errmsg); + errinfo.ErrorType = FFMS_ERROR_SUCCESS; + errinfo.SubType = FFMS_ERROR_SUCCESS; + } + ~ffms2_decoder(){ + cleanup(); + } + void cleanup(); + bool open(const std::string& filename); + float getFrameRate(){ + if (loaded) return (((float)videoprops->FPSNumerator)/((float)videoprops->FPSDenominator)); + else return -1.0f; + } + int getNumberOfFrames(){ + if (loaded) return videoprops->NumFrames; + else return -1; + } + int getNumberOfChannels(){ + return 3; //this is what we convert to + } + int getWidth(){ + return w; + } + int getHeight(){ + return h; + } + bool fetchFrame(int width,int height,int wanted){ + if (FFMS_SetOutputFormatV2(videosource, pixfmts, width, height, FFMS_RESIZER_BICUBIC, &errinfo)) { + std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl; + return false; + } + frame = FFMS_GetFrame(videosource, wanted%videoprops->NumFrames, &errinfo); + if (frame == NULL) { + std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl; + return false; + } + return true; + + } + + FFMS_VideoSource *videosource; + FFMS_VideoProperties *videoprops; + FFMS_Frame *frame; + FFMS_ErrorInfo errinfo; + char errmsg[1024]; + int pixfmts[2]; + bool loaded; + int h,w; + }; + /* // TODO - finish refactoring based on // http://svn.gnumonks.org/trunk/21c3-video/ffmpeg/ffmpeg-0.4.9-pre1/output_example.c |
