Visual Servoing Platform  version 3.0.0
vpVideoWriter.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Write videos and sequences of images.
32  *
33  * Authors:
34  * Nicolas Melchior
35  *
36  *****************************************************************************/
37 
43 #ifndef vpVideoWriter_H
44 #define vpVideoWriter_H
45 
46 #include <string>
47 
48 #include <visp3/io/vpImageIo.h>
49 #include <visp3/io/vpFFMPEG.h>
50 
51 #if VISP_HAVE_OPENCV_VERSION >= 0x020200
52 # include <opencv2/highgui/highgui.hpp>
53 #elif VISP_HAVE_OPENCV_VERSION >= 0x020000
54 # include <opencv/highgui.h>
55 #endif
56 
57 
146 class VISP_EXPORT vpVideoWriter
147 {
148  private:
149 #ifdef VISP_HAVE_FFMPEG
150  vpFFMPEG *ffmpeg;
153 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
154  CodecID codec;
155 #else
156  AVCodecID codec;
157 #endif
158  unsigned int bit_rate;
160  int framerate;
161 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
162  cv::VideoWriter writer;
163  int fourcc;
164  double framerate;
165 #endif
166  typedef enum
168  {
169  FORMAT_PGM,
170  FORMAT_PPM,
171  FORMAT_JPEG,
172  FORMAT_PNG,
173  FORMAT_AVI,
174  FORMAT_MPEG,
175  FORMAT_MPEG4,
176  FORMAT_MOV,
177  FORMAT_UNKNOWN
178  } vpVideoFormatType;
179 
181  vpVideoFormatType formatType;
182 
184  char fileName[FILENAME_MAX];
185 
187  bool initFileName;
188 
190  bool isOpen;
191 
193  unsigned int frameCount;
194 
196  unsigned int firstFrame;
197 
199  unsigned int width;
200  unsigned int height;
201 
202  public:
203  vpVideoWriter();
204  ~vpVideoWriter();
205 
206  void close();
207 
213  inline unsigned int getCurrentFrameIndex() const {return frameCount;}
214 
215  void open (vpImage< vpRGBa > &I);
216  void open (vpImage< unsigned char > &I);
222  inline void resetFrameCounter() {frameCount = firstFrame;}
223 
224  void saveFrame (vpImage< vpRGBa > &I);
225  void saveFrame (vpImage< unsigned char > &I);
226 
227 #ifdef VISP_HAVE_FFMPEG
228 
235  inline void setBitRate(const unsigned int bitrate) {this->bit_rate = bitrate;}
236 
248 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
249  inline void setCodec(const CodecID codec_id) {this->codec = codec_id;}
250 #else
251  inline void setCodec(const AVCodecID codec_id) {this->codec = codec_id;}
252 #endif
253 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
254  inline void setCodec(const int fourcc_codec) {this->fourcc = fourcc_codec;}
255 #endif
256 
257  void setFileName(const char *filename);
258  void setFileName(const std::string &filename);
264  inline void setFirstFrameIndex(const unsigned int first_frame) {this->firstFrame = first_frame;}
265 #ifdef VISP_HAVE_FFMPEG
266 
273  inline void setFramerate(const int frame_rate) {
274  this->framerate = frame_rate;
275  }
276 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
277 
284  inline void setFramerate(const double frame_rate) {
285  this->framerate = frame_rate;
286  }
287 #endif
288 
289  private:
290  vpVideoFormatType getFormat(const char *filename);
291  static std::string getExtension(const std::string &filename);
292 };
293 
294 #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:145
void setFramerate(const int frame_rate)