Gazebo Common

API Reference

4.7.0
gz/common/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 GZ_COMMON_VIDEOENCODER_HH_
18 #define GZ_COMMON_VIDEOENCODER_HH_
19 
20 #include <chrono>
21 #include <string>
22 #include <memory>
23 #include <optional>
24 
25 #include <gz/common/config.hh>
26 #include <gz/common/FlagSet.hh>
27 #include <gz/common/av/Export.hh>
29 #include <gz/common/HWVideo.hh>
30 
31 // Default bitrate (0) indicates that a bitrate should be calculated when
32 // Start is called.
33 #define VIDEO_ENCODER_BITRATE_DEFAULT 0
34 #define VIDEO_ENCODER_WIDTH_DEFAULT 1280
35 #define VIDEO_ENCODER_HEIGHT_DEFAULT 720
36 #define VIDEO_ENCODER_FPS_DEFAULT 25
37 #define VIDEO_ENCODER_FORMAT_DEFAULT "mp4"
38 
39 namespace ignition
40 {
41  namespace common
42  {
43  // Forward declare private data class
44  class VideoEncoderPrivate;
45 
48  class IGNITION_COMMON_AV_VISIBLE VideoEncoder
49  {
51  public: VideoEncoder();
52 
54  public: virtual ~VideoEncoder();
55 
97  public: bool Start(
99  const std::string &_filename = "",
100  const unsigned int _width = VIDEO_ENCODER_WIDTH_DEFAULT,
101  const unsigned int _height = VIDEO_ENCODER_HEIGHT_DEFAULT,
102  const unsigned int _fps = VIDEO_ENCODER_FPS_DEFAULT,
103  const unsigned int _bitRate = VIDEO_ENCODER_BITRATE_DEFAULT);
104 
131  public: bool Start(
132  const std::string &_format,
133  const std::string &_filename,
134  const unsigned int _width,
135  const unsigned int _height,
136  const unsigned int _fps,
137  const unsigned int _bitRate,
138  const bool _allowHwAccel);
139 
168  public: bool Start(
169  const std::string &_format,
170  const std::string &_filename,
171  unsigned int _width,
172  unsigned int _height,
173  unsigned int _fps,
174  unsigned int _bitRate,
175  const FlagSet<HWEncoderType>& _allowedHwAccel,
176  const std::string& _hwAccelDevice = "",
177  std::optional<bool> _useHwSurface = {});
178 
182  public: bool Stop();
183 
186  public: bool IsEncoding() const;
187 
193  public: bool AddFrame(const unsigned char *_frame,
194  const unsigned int _width,
195  const unsigned int _height);
196 
203  public: bool AddFrame(const unsigned char *_frame,
204  const unsigned int _width,
205  const unsigned int _height,
206  const std::chrono::steady_clock::time_point &_timestamp);
207 
211  public: bool SaveToFile(const std::string &_filename);
212 
215  public: std::string Format() const;
216 
219  public: unsigned int BitRate() const;
220 
223  public: void Reset();
224 
228  private: std::unique_ptr<VideoEncoderPrivate> dataPtr;
230  };
231  }
232 }
233 #endif
Forward declarations for the common classes.
STL class.
Set of flags defined by a C++11 enum class.
Definition: gz/common/FlagSet.hh:61
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: gz/common/SuppressWarning.hh:65
#define VIDEO_ENCODER_FORMAT_DEFAULT
Definition: gz/common/VideoEncoder.hh:37
#define VIDEO_ENCODER_HEIGHT_DEFAULT
Definition: gz/common/VideoEncoder.hh:35
#define VIDEO_ENCODER_WIDTH_DEFAULT
Definition: gz/common/VideoEncoder.hh:34
#define VIDEO_ENCODER_BITRATE_DEFAULT
Definition: gz/common/VideoEncoder.hh:33
#define VIDEO_ENCODER_FPS_DEFAULT
Definition: gz/common/VideoEncoder.hh:36
The VideoEncoder class supports encoding a series of images to a video format, and then writing the v...
Definition: gz/common/VideoEncoder.hh:48
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68