blob: 4c8f96e717b644b105879f9a3fe8824c40487af3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#ifndef ffmpeg_fas_wrapper_H
#define ffmpeg_fas_wrapper_H
#include <string>
#include <iostream>
#include "ffmpeg_fas.c"
namespace ffmpeg_fas {
class decoder
{
public:
decoder(){
fas_initialize(FAS_TRUE,FAS_RGB24);
loaded=false;
framerate=0.0f;
numFrames=0;
}
bool open(std::string& filename){
fas_error_type e=fas_open_video(&context,filename.c_str());
if (e==FAS_SUCCESS){
loaded=true;
framerate=(((float)context->format_context->streams[context->stream_idx]->r_frame_rate.num)/((float)context->format_context->streams[context->stream_idx]->r_frame_rate.den));
numFrames=context->format_context->streams[context->stream_idx]->nb_frames;
if (numFrames<1){
//some codecs don't keep this info in the header
numFrames = (int)(( context->format_context->duration / (double)AV_TIME_BASE ) * framerate );
//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
}
}
else {
std::cerr<<"ffmpeg_fas ERROR: "<<fas_error_message(e)<<std::endl;
loaded=true;
}
return loaded;
}
float getFrameRate(){
return framerate;
}
int getNumberOfFrames();
int getNumberOfChannels();
int getWidth();
int getHeight();
bool fetchFrame(int width,int height,int wanted);
void cleanup(); //necessary?
fas_raw_image_type frame;
fas_context_ref_type context;
bool loaded;
float framerate;
int numFrames;
};
}
#endif
|