]> sjero.net Git - qpsnr/blob - src/qav.h
Initial Commit of QPSNR (version 0.2.1)
[qpsnr] / src / qav.h
1 /*
2 *       qpsnr (C) 2010 E. Oriani, ema <AT> fastwebnet <DOT> it
3 *
4 *       This file is part of qpsnr.
5 *
6 *       qpsnr is free software: you can redistribute it and/or modify
7 *       it under the terms of the GNU General Public License as published by
8 *       the Free Software Foundation, either version 3 of the License, or
9 *       (at your option) any later version.
10 *
11 *       qpsnr is distributed in the hope that it will be useful,
12 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *       GNU General Public License for more details.
15 *
16 *       You should have received a copy of the GNU General Public License
17 *       along with qpsnr.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef _QAV_H_
21 #define _QAV_H_
22
23 // libavcodec is a C library without C++ guards...
24 extern "C" {
25 #include <libavcodec/avcodec.h>
26 #include <libavformat/avformat.h>
27 #include <libswscale/swscale.h>
28 }
29
30 #include <string>
31 #include <vector>
32
33 namespace qav {
34         struct scr_size {
35                 int     x,
36                         y;
37                 scr_size(const int& _x = 0, const int& _y = 0) : x(_x), y(_y) {
38                 }
39
40                 inline friend bool operator==(const scr_size& lhs, const scr_size& rhs) {
41                         return lhs.x==rhs.x && lhs.y==rhs.y;
42                 }
43         };
44
45         class qvideo {
46                 int                     frnum,
47                                         videoStream,
48                                         out_width,
49                                         out_height;
50                 AVFormatContext         *pFormatCtx;
51                 AVCodecContext          *pCodecCtx;
52                 AVCodec                 *pCodec;
53                 AVFrame                 *pFrame;
54                 struct SwsContext       *img_convert_ctx;
55                 std::string             fname;
56         public:
57                 qvideo(const char* file, int _out_width = -1, int _out_height = -1);
58                 scr_size get_size(void) const;
59                 int get_fps_k(void) const;
60                 bool get_frame(std::vector<unsigned char>& out, int *_frnum = 0);
61                 void save_frame(const unsigned char *buf, const char* __fname = 0);
62                 ~qvideo();
63         };
64 }
65
66
67 #endif /*_QAV_H_*/
68