ViSP  2.6.2
vpFFMPEG.h
1 /****************************************************************************
2  *
3  * $Id: vpImagePoint.h 2359 2009-11-24 15:09:25Z nmelchio $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Class that manages the FFMPEG library.
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
48 #ifndef vpFFMPEG_H
49 #define vpFFMPEG_H
50 
51 #include <visp/vpImageIo.h>
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <vector>
55 
56 #ifdef VISP_HAVE_FFMPEG
57 
58 // Fix for the following compilation error:
59 // libavutil/common.h:154: error: UINT64_C was not declared in this scope
60 // libavutil/common.h is no more autosufficient for C++ program because
61 // stdint.h defines UINT64_C only for C program and not C++ program
62 #ifdef __cplusplus
63 # define __STDC_CONSTANT_MACROS
64 # ifdef _STDINT_H
65 # undef _STDINT_H
66 # endif
67 // On OS X
68 # ifdef _STDINT_H_
69 # undef _STDINT_H_
70 # endif
71 # include <stdint.h>
72 
73 # ifndef INT64_C
74 # define INT64_C(c) (c ## LL)
75 # endif
76 # ifndef UINT64_C
77 # define UINT64_C(c) (c ## ULL)
78 # endif
79 #endif
80 // end fix
81 
82 
83 extern "C"
84 {
85 #include <avcodec.h> // requested for CodecID enum
86 //#include <avformat.h>
87 //#include <swscale.h>
88 }
89 
90 struct AVFormatContext;
91 struct AVCodecContext;
92 struct AVCodec;
93 struct AVFrame;
94 struct AVFrame;
95 struct AVFrame;
96 struct AVPacket;
97 struct SwsContext;
98 
154 class VISP_EXPORT vpFFMPEG
155 {
156  public:
157  typedef enum
158  {
161  }vpFFMPEGColorType;
162 
163  private:
165  int width, height;
167  unsigned long frameNumber;
169  AVFormatContext *pFormatCtx;
170  AVCodecContext *pCodecCtx;
171  AVCodec *pCodec;
172  AVFrame *pFrame;
173  AVFrame *pFrameRGB;
174  AVFrame *pFrameGRAY;
175  AVPacket *packet;
176  SwsContext *img_convert_ctx ;
177  unsigned int videoStream;
178  int numBytes ;
179  uint8_t * buffer ;
180  std::vector<int64_t> index;
182  bool streamWasOpen;
184  bool streamWasInitialized;
186  vpFFMPEGColorType color_type;
187 
189  FILE *f;
191  uint8_t *outbuf, *picture_buf;
193  int outbuf_size;
195  int out_size;
197  unsigned int bit_rate;
199  bool encoderWasOpened;
200 
201  public:
202  vpFFMPEG();
203  ~vpFFMPEG();
204 
210  inline int getWidth() const {return width;}
211 
217  inline int getHeight() const {return height;}
218 
224  inline unsigned long getFrameNumber() const {return frameNumber;}
225 
231  inline void setBitRate(const unsigned int bit_rate) {this->bit_rate = bit_rate;}
232 
233  bool openStream(const char *filename,vpFFMPEGColorType color_type);
234  bool initStream();
235  void closeStream();
236 
237  bool acquire(vpImage<vpRGBa> &I);
238  bool acquire(vpImage<unsigned char> &I);
239 
240  bool getFrame(vpImage<vpRGBa> &I, unsigned int frameNumber);
241  bool getFrame(vpImage<unsigned char> &I, unsigned int frameNumber);
242 
243  bool openEncoder(const char *filename, unsigned int width, unsigned int height, CodecID codec = CODEC_ID_MPEG1VIDEO);
244  bool saveFrame(vpImage<vpRGBa> &I);
245  bool saveFrame(vpImage<unsigned char> &I);
246  bool endWrite();
247 
248  private:
249  void copyBitmap(vpImage<vpRGBa> &I);
250  void copyBitmap(vpImage<unsigned char> &I);
251  void writeBitmap(vpImage<vpRGBa> &I);
252  void writeBitmap(vpImage<unsigned char> &I);
253 };
254 #endif
255 #endif
void setBitRate(const unsigned int bit_rate)
Definition: vpFFMPEG.h:231
unsigned long getFrameNumber() const
Definition: vpFFMPEG.h:224
int getHeight() const
Definition: vpFFMPEG.h:217
This class interfaces the FFmpeg library to enable the reading of video files.
Definition: vpFFMPEG.h:154
int getWidth() const
Definition: vpFFMPEG.h:210