-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVideoStreamDecoder.h
50 lines (45 loc) · 1.22 KB
/
VideoStreamDecoder.h
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
#ifndef VIDEOSTREAMDECODER_H
#define VIDEOSTREAMDECODER_H
#include <opencv/cv.h>
#include <opencv/highgui.h>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
#include "Params.h"
/**
* Video Decoder
* Decodes encoded data
*/
class VideoStreamDecoder{
public:
/***
* @param bufSize: buf size of internal buffer size
* @param fps: frame per second
* @param pixelFormat: the pixel format of opencv IplImage; usually it's BGR24
*/
VideoStreamDecoder(int bufSize, int fps = FRAME_PER_SECOND, PixelFormat pixelFormat = PIX_FMT_BGR24);
virtual ~VideoStreamDecoder();
/**
* Decode a buffer to an IplImage
* @param buf: encoded data
* @param size: buffer size of encoded data
* @return: an IplImage, which is the next image in the decoded video stream.
*/
IplImage *decodeVideoFrame(const unsigned char *buf, int size);
private:
bool initDecoder();
AVFrame *createAVFrame(PixelFormat pixelFormat, int frameWidth, int frameHeight);
private:
bool initialized;
unsigned char *buffer;
int bufSize;
int fps;
AVCodec *decodeCodec;
AVCodecContext *codecContext;
AVFrame *decodeFrame;
AVFrame *openCVFrame;
PixelFormat openCVPixelFormat;
};
#endif