ViSP  2.10.0
vpVideoWriter.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 - 2014 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  * Write videos and sequences of images.
36  *
37  * Authors:
38  * Nicolas Melchior
39  *
40  *****************************************************************************/
41 
47 #ifndef vpVideoWriter_H
48 #define vpVideoWriter_H
49 
50 #include <string>
51 
52 #include <visp/vpImageIo.h>
53 #include <visp/vpFFMPEG.h>
54 
55 #if VISP_HAVE_OPENCV_VERSION >= 0x020200
56 # include <opencv2/highgui/highgui.hpp>
57 #elif VISP_HAVE_OPENCV_VERSION >= 0x020000
58 # include <opencv/highgui.h>
59 #endif
60 
61 
150 class VISP_EXPORT vpVideoWriter
151 {
152  private:
153 #ifdef VISP_HAVE_FFMPEG
154  vpFFMPEG *ffmpeg;
157 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
158  CodecID codec;
159 #else
160  AVCodecID codec;
161 #endif
162  unsigned int bit_rate;
164  int framerate;
165 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
166  cv::VideoWriter writer;
167  int fourcc;
168  double framerate;
169 #endif
170  typedef enum
172  {
173  FORMAT_PGM,
174  FORMAT_PPM,
175  FORMAT_JPEG,
176  FORMAT_PNG,
177  FORMAT_AVI,
178  FORMAT_MPEG,
179  FORMAT_MPEG4,
180  FORMAT_MOV,
181  FORMAT_UNKNOWN
182  } vpVideoFormatType;
183 
185  vpVideoFormatType formatType;
186 
188  char fileName[FILENAME_MAX];
189 
191  bool initFileName;
192 
194  bool isOpen;
195 
197  unsigned int frameCount;
198 
200  unsigned int firstFrame;
201 
203  unsigned int width;
204  unsigned int height;
205 
206  public:
207  vpVideoWriter();
208  ~vpVideoWriter();
209 
210  void close();
211 
217  inline unsigned int getCurrentFrameIndex() const {return frameCount;}
218 
219  void open (vpImage< vpRGBa > &I);
220  void open (vpImage< unsigned char > &I);
226  inline void resetFrameCounter() {frameCount = firstFrame;}
227 
228  void saveFrame (vpImage< vpRGBa > &I);
229  void saveFrame (vpImage< unsigned char > &I);
230 
231 #ifdef VISP_HAVE_FFMPEG
232 
239  inline void setBitRate(const unsigned int bitrate) {this->bit_rate = bitrate;}
240 
252 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
253  inline void setCodec(const CodecID codec_id) {this->codec = codec_id;}
254 #else
255  inline void setCodec(const AVCodecID codec_id) {this->codec = codec_id;}
256 #endif
257 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
258  inline void setCodec(const int fourcc_codec) {this->fourcc = fourcc_codec;}
259 #endif
260 
261  void setFileName(const char *filename);
262  void setFileName(const std::string &filename);
268  inline void setFirstFrameIndex(const unsigned int first_frame) {this->firstFrame = first_frame;}
269 #ifdef VISP_HAVE_FFMPEG
270 
277  inline void setFramerate(const int frame_rate) {
278  this->framerate = frame_rate;
279  }
280 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
281 
288  inline void setFramerate(const double frame_rate) {
289  this->framerate = frame_rate;
290  }
291 #endif
292 
293  private:
294  vpVideoFormatType getFormat(const char *filename);
295  static std::string getExtension(const std::string &filename);
296 };
297 
298 #endif
void setBitRate(const unsigned int bitrate)
unsigned int getCurrentFrameIndex() const
void setFirstFrameIndex(const unsigned int first_frame)
void setCodec(const AVCodecID codec_id)
void resetFrameCounter()
Class that enables to write easily a video file or a sequence of images.
This class interfaces the FFmpeg library to enable video stream reading or writing.
Definition: vpFFMPEG.h:149
void setFramerate(const int frame_rate)