diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-09-16 14:31:04 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-09-16 14:31:04 +0100 |
| commit | 440ba17594d17736a56cac0d89be97fb63577989 (patch) | |
| tree | b3853fbba0a13a481c5c5247114a6a1170d5efb3 /rotord/src/libavwrapper.h | |
| parent | 1b37a3d71dabc451f48f05fce7ce2d300212c43c (diff) | |
ffmpegsource audio loading
Diffstat (limited to 'rotord/src/libavwrapper.h')
| -rw-r--r-- | rotord/src/libavwrapper.h | 107 |
1 files changed, 84 insertions, 23 deletions
diff --git a/rotord/src/libavwrapper.h b/rotord/src/libavwrapper.h index 870815f..2f1f31e 100644 --- a/rotord/src/libavwrapper.h +++ b/rotord/src/libavwrapper.h @@ -156,68 +156,129 @@ namespace libav { }; - class ffms2_decoder + class video_decoder { public: - ffms2_decoder(){ + video_decoder(){ maybeInitFFMpegLib(); pixfmts[0] = FFMS_GetPixFmt("rgb24"); pixfmts[1] = -1; h=0; w=0; - videosource=NULL; + source=NULL; loaded=false; - errinfo.Buffer = errmsg; - errinfo.BufferSize = sizeof(errmsg); - errinfo.ErrorType = FFMS_ERROR_SUCCESS; - errinfo.SubType = FFMS_ERROR_SUCCESS; + err.Buffer = errmsg; + err.BufferSize = sizeof(errmsg); + err.ErrorType = FFMS_ERROR_SUCCESS; + err.SubType = FFMS_ERROR_SUCCESS; } - ~ffms2_decoder(){ + ~video_decoder(){ cleanup(); } void cleanup(); bool open(const std::string& filename); - float getFrameRate(){ - if (loaded) return (((float)videoprops->FPSNumerator)/((float)videoprops->FPSDenominator)); + float get_framerate(){ + if (loaded) return (((float)props->FPSNumerator)/((float)props->FPSDenominator)); else return -1.0f; } - int getNumberOfFrames(){ - if (loaded) return videoprops->NumFrames; + int get_number_frames(){ + if (loaded) return props->NumFrames; else return -1; } - int getNumberOfChannels(){ + int get_number_channels(){ return 3; //this is what we convert to } - int getWidth(){ + int get_width(){ return w; } - int getHeight(){ + int get_height(){ 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; + bool fetch_frame(int width,int height,int wanted){ + if (FFMS_SetOutputFormatV2(source, pixfmts, width, height, FFMS_RESIZER_BICUBIC, &err)) { + std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl; return false; } - frame = FFMS_GetFrame(videosource, wanted%videoprops->NumFrames, &errinfo); + frame = FFMS_GetFrame(source, wanted%props->NumFrames, &err); if (frame == NULL) { - std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl; + std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl; return false; } return true; } - FFMS_VideoSource *videosource; - FFMS_VideoProperties *videoprops; + FFMS_VideoSource *source; + FFMS_VideoProperties *props; FFMS_Frame *frame; - FFMS_ErrorInfo errinfo; + FFMS_ErrorInfo err; char errmsg[1024]; int pixfmts[2]; bool loaded; int h,w; }; + class audio_decoder + { + public: + audio_decoder(){ + maybeInitFFMpegLib(); + source=nullptr; + props=nullptr; + loaded=false; + err.Buffer = errmsg; + err.BufferSize = sizeof(errmsg); + err.ErrorType = FFMS_ERROR_SUCCESS; + err.SubType = FFMS_ERROR_SUCCESS; + } + ~audio_decoder(){ + cleanup(); + } + void cleanup(); + bool open(const std::string& filename); + int get_format(){ + if (props) return props->SampleFormat; + else return 0; + } + int get_sample_rate(){ + if (props) return props->SampleRate; + else return 0; + } + int get_bit_depth(){ + if (props) return props->BitsPerSample; + else return 0; + } + int get_number_channels(){ + if (props) return props->Channels; + else return 0; + } + int64_t get_channel_layout(){ + if (props) return props->ChannelLayout; + else return 0; + } + float get_duration(){ + if (props) return ((float)props->NumSamples)/props->SampleRate; + else return 0; + } + bool get_samples(void *buf,int64_t start, int64_t count){ + if (source) { + if (FFMS_GetAudio(source, buf, start, count, &err)) { + std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl; + return false; + } + return true; + } + return false; + } + + FFMS_AudioSource *source; + FFMS_AudioProperties *props; + FFMS_Frame *frame; + FFMS_ErrorInfo err; + char errmsg[1024]; + bool loaded; + }; + /* // TODO - finish refactoring based on // http://svn.gnumonks.org/trunk/21c3-video/ffmpeg/ffmpeg-0.4.9-pre1/output_example.c |
