Gazebo Common

API Reference

7.4.0
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 <optional>
23
24#include <gz/common/FlagSet.hh>
25#include <gz/common/av/Export.hh>
26#include <gz/common/HWVideo.hh>
27#include <gz/utils/ImplPtr.hh>
28
29// Default bitrate (0) indicates that a bitrate should be calculated when
30// Start is called.
31#define VIDEO_ENCODER_BITRATE_DEFAULT 0
32#define VIDEO_ENCODER_WIDTH_DEFAULT 1280
33#define VIDEO_ENCODER_HEIGHT_DEFAULT 720
34#define VIDEO_ENCODER_FPS_DEFAULT 25
35#define VIDEO_ENCODER_FORMAT_DEFAULT "mp4"
36
37namespace gz
38{
39 namespace common
40 {
43 class GZ_COMMON_AV_VISIBLE VideoEncoder
44 {
46 public: VideoEncoder();
47
49 public: virtual ~VideoEncoder();
50
93 public: bool Start(
95 const std::string &_filename = "",
96 const unsigned int _width = VIDEO_ENCODER_WIDTH_DEFAULT,
97 const unsigned int _height = VIDEO_ENCODER_HEIGHT_DEFAULT,
98 const unsigned int _fps = VIDEO_ENCODER_FPS_DEFAULT,
99 const unsigned int _bitRate = VIDEO_ENCODER_BITRATE_DEFAULT);
100
128 public: bool Start(
129 const std::string &_format,
130 const std::string &_filename,
131 const unsigned int _width,
132 const unsigned int _height,
133 const unsigned int _fps,
134 const unsigned int _bitRate,
135 const bool _allowHwAccel);
136
170 public: bool Start(
171 const std::string &_format,
172 const std::string &_filename,
173 unsigned int _width,
174 unsigned int _height,
175 unsigned int _fps,
176 unsigned int _bitRate,
177 const FlagSet<HWEncoderType>& _allowedHwAccel,
178 const std::string& _hwAccelDevice = "",
179 std::optional<bool> _useHwSurface = {});
180
184 public: bool Stop();
185
188 public: bool IsEncoding() const;
189
195 public: bool AddFrame(const unsigned char *_frame,
196 const unsigned int _width,
197 const unsigned int _height);
198
205 public: bool AddFrame(const unsigned char *_frame,
206 const unsigned int _width,
207 const unsigned int _height,
208 const std::chrono::steady_clock::time_point &_timestamp);
209
213 public: bool SaveToFile(const std::string &_filename);
214
217 public: std::string Format() const;
218
221 public: unsigned int BitRate() const;
222
225 public: void Reset();
226
228 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
229 };
230 }
231}
232#endif