Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpVideoWriter.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
163 class VISP_EXPORT vpVideoWriter
164 {
165  private:
166 #ifdef VISP_HAVE_FFMPEG
167  vpFFMPEG *ffmpeg;
170 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
171  CodecID codec;
172 #else
173  AVCodecID codec;
174 #endif
175  unsigned int bit_rate;
177  int framerate;
178 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
179  cv::VideoWriter writer;
180  int fourcc;
181  double framerate;
182 #endif
183  typedef enum
185  {
186  FORMAT_PGM,
187  FORMAT_PPM,
188  FORMAT_JPEG,
189  FORMAT_PNG,
190  FORMAT_AVI,
191  FORMAT_MPEG,
192  FORMAT_MPEG4,
193  FORMAT_MOV,
194  FORMAT_UNKNOWN
195  } vpVideoFormatType;
196 
198  vpVideoFormatType formatType;
199 
201  char fileName[FILENAME_MAX];
202 
204  bool initFileName;
205 
207  bool isOpen;
208 
210  unsigned int frameCount;
211 
213  unsigned int firstFrame;
214 
216  unsigned int width;
217  unsigned int height;
218 
219  public:
220  vpVideoWriter();
221  ~vpVideoWriter();
222 
223  void close();
224 
230  inline unsigned int getCurrentFrameIndex() const {return frameCount;}
231 
232  void open (vpImage< vpRGBa > &I);
233  void open (vpImage< unsigned char > &I);
239  inline void resetFrameCounter() {frameCount = firstFrame;}
240 
241  void saveFrame (vpImage< vpRGBa > &I);
242  void saveFrame (vpImage< unsigned char > &I);
243 
244 #ifdef VISP_HAVE_FFMPEG
245 
252  inline void setBitRate(const unsigned int bitrate) {this->bit_rate = bitrate;}
253 
265 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
266  inline void setCodec(const CodecID codec_id) {this->codec = codec_id;}
267 #else
268  inline void setCodec(const AVCodecID codec_id) {this->codec = codec_id;}
269 #endif
270 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
271  inline void setCodec(const int fourcc_codec) {this->fourcc = fourcc_codec;}
272 #endif
273 
274  void setFileName(const char *filename);
275  void setFileName(const std::string &filename);
281  inline void setFirstFrameIndex(const unsigned int first_frame) {this->firstFrame = first_frame;}
282 #ifdef VISP_HAVE_FFMPEG
283 
290  inline void setFramerate(const int frame_rate) {
291  this->framerate = frame_rate;
292  }
293 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100
294 
301  inline void setFramerate(const double frame_rate) {
302  this->framerate = frame_rate;
303  }
304 #endif
305 
306  private:
307  vpVideoFormatType getFormat(const char *filename);
308  static std::string getExtension(const std::string &filename);
309 };
310 
311 #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)