VideoEncoder.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GAZEBO_COMMON_VIDEOENCODER_HH_
18 #define GAZEBO_COMMON_VIDEOENCODER_HH_
19 
20 #include <chrono>
21 #include <string>
22 #include <memory>
23 #include <gazebo/util/system.hh>
24 
25 // Default bitrate (0) indicates that a bitrate should be calculated when
26 // Start is called.
27 #define VIDEO_ENCODER_BITRATE_DEFAULT 0
28 #define VIDEO_ENCODER_WIDTH_DEFAULT 1280
29 #define VIDEO_ENCODER_HEIGHT_DEFAULT 720
30 #define VIDEO_ENCODER_FPS_DEFAULT 25
31 #define VIDEO_ENCODER_FORMAT_DEFAULT "mp4"
32 
33 namespace gazebo
34 {
35  namespace common
36  {
37  // Forward declare private data class
38  class VideoEncoderPrivate;
39 
42 
46  class GZ_COMMON_VISIBLE VideoEncoder
47  {
49  public: VideoEncoder();
50 
52  public: virtual ~VideoEncoder();
53 
71  public: bool Start(
72  const std::string &_format = VIDEO_ENCODER_FORMAT_DEFAULT,
73  const std::string &_filename = "",
74  const unsigned int _width = VIDEO_ENCODER_WIDTH_DEFAULT,
75  const unsigned int _height = VIDEO_ENCODER_HEIGHT_DEFAULT,
76  const unsigned int _fps = VIDEO_ENCODER_FPS_DEFAULT,
77  const unsigned int _bitRate = VIDEO_ENCODER_BITRATE_DEFAULT);
78 
82  public: bool Stop();
83 
86  public: bool IsEncoding() const;
87 
93  public: bool AddFrame(const unsigned char *_frame,
94  const unsigned int _width,
95  const unsigned int _height);
96 
103  public: bool AddFrame(const unsigned char *_frame,
104  const unsigned int _width,
105  const unsigned int _height,
106  const std::chrono::steady_clock::time_point &_timestamp);
107 
111  public: bool SaveToFile(const std::string &_filename);
112 
115  public: std::string Format() const;
116 
119  public: unsigned int BitRate() const;
120 
123  public: void Reset();
124 
127  private: std::unique_ptr<VideoEncoderPrivate> dataPtr;
128  };
130  }
131 }
132 #endif
The VideoEncoder class supports encoding a series of images to a video format, and then writing the v...
Definition: VideoEncoder.hh:46
Forward declarations for the common classes.
Definition: Animation.hh:26
#define VIDEO_ENCODER_FPS_DEFAULT
Definition: VideoEncoder.hh:30
#define VIDEO_ENCODER_BITRATE_DEFAULT
Definition: VideoEncoder.hh:27
#define VIDEO_ENCODER_HEIGHT_DEFAULT
Definition: VideoEncoder.hh:29
#define VIDEO_ENCODER_WIDTH_DEFAULT
Definition: VideoEncoder.hh:28
#define VIDEO_ENCODER_FORMAT_DEFAULT
Definition: VideoEncoder.hh:31