Gazebo Common

API Reference

3.17.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/FlagSet.hh>
26 #include <gz/common/av/Export.hh>
28 #include <gz/common/HWVideo.hh>
29 
30 // Default bitrate (0) indicates that a bitrate should be calculated when
31 // Start is called.
32 #define VIDEO_ENCODER_BITRATE_DEFAULT 0
33 #define VIDEO_ENCODER_WIDTH_DEFAULT 1280
34 #define VIDEO_ENCODER_HEIGHT_DEFAULT 720
35 #define VIDEO_ENCODER_FPS_DEFAULT 25
36 #define VIDEO_ENCODER_FORMAT_DEFAULT "mp4"
37 
38 namespace ignition
39 {
40  namespace common
41  {
42  // Forward declare private data class
43  class VideoEncoderPrivate;
44 
47  class IGNITION_COMMON_AV_VISIBLE VideoEncoder
48  {
50  public: VideoEncoder();
51 
53  public: virtual ~VideoEncoder();
54 
96  public: bool Start(
98  const std::string &_filename = "",
99  const unsigned int _width = VIDEO_ENCODER_WIDTH_DEFAULT,
100  const unsigned int _height = VIDEO_ENCODER_HEIGHT_DEFAULT,
101  const unsigned int _fps = VIDEO_ENCODER_FPS_DEFAULT,
102  const unsigned int _bitRate = VIDEO_ENCODER_BITRATE_DEFAULT);
103 
130  public: bool Start(
131  const std::string &_format,
132  const std::string &_filename,
133  const unsigned int _width,
134  const unsigned int _height,
135  const unsigned int _fps,
136  const unsigned int _bitRate,
137  const bool _allowHwAccel);
138 
167  public: bool Start(
168  const std::string &_format,
169  const std::string &_filename,
170  unsigned int _width,
171  unsigned int _height,
172  unsigned int _fps,
173  unsigned int _bitRate,
174  const FlagSet<HWEncoderType>& _allowedHwAccel,
175  const std::string& _hwAccelDevice = "",
176  std::optional<bool> _useHwSurface = {});
177 
181  public: bool Stop();
182 
185  public: bool IsEncoding() const;
186 
192  public: bool AddFrame(const unsigned char *_frame,
193  const unsigned int _width,
194  const unsigned int _height);
195 
202  public: bool AddFrame(const unsigned char *_frame,
203  const unsigned int _width,
204  const unsigned int _height,
205  const std::chrono::steady_clock::time_point &_timestamp);
206 
210  public: bool SaveToFile(const std::string &_filename);
211 
214  public: std::string Format() const;
215 
218  public: unsigned int BitRate() const;
219 
222  public: void Reset();
223 
227  private: std::unique_ptr<VideoEncoderPrivate> dataPtr;
229  };
230  }
231 }
232 #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:36
#define VIDEO_ENCODER_HEIGHT_DEFAULT
Definition: gz/common/VideoEncoder.hh:34
#define VIDEO_ENCODER_WIDTH_DEFAULT
Definition: gz/common/VideoEncoder.hh:33
#define VIDEO_ENCODER_BITRATE_DEFAULT
Definition: gz/common/VideoEncoder.hh:32
#define VIDEO_ENCODER_FPS_DEFAULT
Definition: gz/common/VideoEncoder.hh:35
The VideoEncoder class supports encoding a series of images to a video format, and then writing the v...
Definition: gz/common/VideoEncoder.hh:47
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68