Rerun C++ SDK
Loading...
Searching...
No Matches
asset_video.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_sdk_types/definitions/rerun/archetypes/asset_video.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/blob.hpp"
10#include "../components/media_type.hpp"
11#include "../result.hpp"
12
13#include <chrono>
14#include <cstdint>
15#include <filesystem>
16#include <optional>
17#include <utility>
18#include <vector>
19
20namespace rerun::archetypes {
21 /// **Archetype**: A video binary.
22 ///
23 /// Only MP4 containers are currently supported.
24 ///
25 /// See <https://rerun.io/docs/reference/video> for codec support and more general information.
26 ///
27 /// In order to display a video, you also need to log a `archetypes::VideoFrameReference` for each frame.
28 ///
29 /// ## Examples
30 ///
31 /// ### Video with automatically determined frames
32 /// ![image](https://static.rerun.io/video_manual_frames/320a44e1e06b8b3a3161ecbbeae3e04d1ccb9589/full.png)
33 ///
34 /// ```cpp
35 /// #include <rerun.hpp>
36 ///
37 /// #include <iostream>
38 ///
39 /// using namespace std::chrono_literals;
40 ///
41 /// int main(int argc, char* argv[]) {
42 /// if (argc <2) {
43 /// // TODO(#7354): Only mp4 is supported for now.
44 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_video.[mp4]>"
45 /// <<std::endl;
46 /// return 1;
47 /// }
48 ///
49 /// const auto path = argv[1];
50 ///
51 /// const auto rec =
52 /// rerun::RecordingStream("rerun_example_asset_video_auto_frames");
53 /// rec.spawn().exit_on_failure();
54 ///
55 /// // Log video asset which is referred to by frame references.
56 /// auto video_asset = rerun::AssetVideo::from_file(path).value_or_throw();
57 /// rec.log_static("video", video_asset);
58 ///
59 /// // Send automatically determined video frame timestamps.
60 /// std::vector<std::chrono::nanoseconds> frame_timestamps_ns =
61 /// video_asset.read_frame_timestamps_nanos().value_or_throw();
62 /// // Note timeline values don't have to be the same as the video timestamps.
63 /// auto time_column = rerun::TimeColumn::from_durations(
64 /// "video_time",
65 /// rerun::borrow(frame_timestamps_ns)
66 /// );
67 ///
68 /// std::vector<rerun::components::VideoTimestamp> video_timestamps(
69 /// frame_timestamps_ns.size()
70 /// );
71 /// for (size_t i = 0; i <frame_timestamps_ns.size(); i++) {
72 /// video_timestamps[i] =
73 /// rerun::components::VideoTimestamp(frame_timestamps_ns[i]);
74 /// }
75 ///
76 /// rec.send_columns(
77 /// "video",
78 /// time_column,
79 /// rerun::VideoFrameReference()
80 /// .with_many_timestamp(rerun::borrow(video_timestamps))
81 /// .columns()
82 /// );
83 /// }
84 /// ```
85 ///
86 /// ### Demonstrates manual use of video frame references
87 /// ![image](https://static.rerun.io/video_manual_frames/9f41c00f84a98cc3f26875fba7c1d2fa2bad7151/full.png)
88 ///
89 /// ```cpp
90 /// #include <rerun.hpp>
91 ///
92 /// #include <iostream>
93 ///
94 /// using namespace std::chrono_literals;
95 ///
96 /// int main(int argc, char* argv[]) {
97 /// if (argc <2) {
98 /// // TODO(#7354): Only mp4 is supported for now.
99 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_video.[mp4]>"
100 /// <<std::endl;
101 /// return 1;
102 /// }
103 ///
104 /// const auto path = argv[1];
105 ///
106 /// const auto rec =
107 /// rerun::RecordingStream("rerun_example_asset_video_manual_frames");
108 /// rec.spawn().exit_on_failure();
109 ///
110 /// // Log video asset which is referred to by frame references.
111 /// rec.log_static(
112 /// "video_asset",
113 /// rerun::AssetVideo::from_file(path).value_or_throw()
114 /// );
115 ///
116 /// // Create two entities, showing the same video frozen at different times.
117 /// rec.log(
118 /// "frame_1s",
119 /// rerun::VideoFrameReference(1.0s).with_video_reference("video_asset")
120 /// );
121 /// rec.log(
122 /// "frame_2s",
123 /// rerun::VideoFrameReference(2.0s).with_video_reference("video_asset")
124 /// );
125 ///
126 /// // TODO(#5520): log blueprint once supported
127 /// }
128 /// ```
129 struct AssetVideo {
130 /// The asset's bytes.
131 std::optional<ComponentBatch> blob;
132
133 /// The Media Type of the asset.
134 ///
135 /// Supported values:
136 /// * `video/mp4`
137 ///
138 /// If omitted, the viewer will try to guess from the data blob.
139 /// If it cannot guess, it won't be able to render the asset.
140 std::optional<ComponentBatch> media_type;
141
142 public:
143 /// The name of the archetype as used in `ComponentDescriptor`s.
144 static constexpr const char ArchetypeName[] = "rerun.archetypes.AssetVideo";
145
146 /// `ComponentDescriptor` for the `blob` field.
147 static constexpr auto Descriptor_blob = ComponentDescriptor(
149 );
150 /// `ComponentDescriptor` for the `media_type` field.
152 ArchetypeName, "AssetVideo:media_type",
154 );
155
156 public: // START of extensions from asset_video_ext.cpp:
157 /// Creates a new `AssetVideo` from the file contents at `path`.
158 ///
159 /// The `MediaType` will be guessed from the file extension.
160 ///
161 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
162 /// from the data at render-time. If it can't, rendering will fail with an error.
163 static Result<AssetVideo> from_file(const std::filesystem::path& path);
164
165 /// Creates a new `AssetVideo` from the given `bytes`.
166 ///
167 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
168 /// at render-time. If it can't, rendering will fail with an error.
171 std::optional<rerun::components::MediaType> media_type = {}
172 ) {
173 AssetVideo asset = AssetVideo(std::move(bytes));
174 // TODO(jan): we could try and guess using magic bytes here, like rust does.
175 if (media_type.has_value()) {
176 return std::move(asset).with_media_type(media_type.value());
177 }
178 return asset;
179 }
180
181 /// Determines the presentation timestamps of all frames inside the video.
182 ///
183 /// Returned timestamps are in nanoseconds since start and are guaranteed to be monotonically increasing.
185
186 /// DEPRECATED: Use `read_frame_timestamps_nanos` instead.
187 [[deprecated("Renamed to `read_frame_timestamps_nanos`"
191 }
192
193 // END of extensions from asset_video_ext.cpp, start of generated code:
194
195 public:
196 AssetVideo() = default;
197 AssetVideo(AssetVideo&& other) = default;
198 AssetVideo(const AssetVideo& other) = default;
199 AssetVideo& operator=(const AssetVideo& other) = default;
200 AssetVideo& operator=(AssetVideo&& other) = default;
201
202 explicit AssetVideo(rerun::components::Blob _blob)
203 : blob(ComponentBatch::from_loggable(std::move(_blob), Descriptor_blob).value_or_throw()
204 ) {}
205
206 /// Update only some specific fields of a `AssetVideo`.
208 return AssetVideo();
209 }
210
211 /// Clear all the fields of a `AssetVideo`.
213
214 /// The asset's bytes.
216 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
217 return std::move(*this);
218 }
219
220 /// This method makes it possible to pack multiple `blob` in a single component batch.
221 ///
222 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
223 /// be used when logging a single row's worth of data.
225 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
226 return std::move(*this);
227 }
228
229 /// The Media Type of the asset.
230 ///
231 /// Supported values:
232 /// * `video/mp4`
233 ///
234 /// If omitted, the viewer will try to guess from the data blob.
235 /// If it cannot guess, it won't be able to render the asset.
237 media_type =
238 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
239 return std::move(*this);
240 }
241
242 /// This method makes it possible to pack multiple `media_type` in a single component batch.
243 ///
244 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
245 /// be used when logging a single row's worth of data.
247 ) && {
248 media_type =
249 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
250 return std::move(*this);
251 }
252
253 /// Partitions the component data into multiple sub-batches.
254 ///
255 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
256 /// instead, via `ComponentBatch::partitioned`.
257 ///
258 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
259 ///
260 /// The specified `lengths` must sum to the total length of the component batch.
262
263 /// Partitions the component data into unit-length sub-batches.
264 ///
265 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
266 /// where `n` is automatically guessed.
268 };
269
270} // namespace rerun::archetypes
271
272namespace rerun {
273 /// \private
274 template <typename T>
275 struct AsComponents;
276
277 /// \private
278 template <>
279 struct AsComponents<archetypes::AssetVideo> {
280 /// Serialize all set component batches.
281 static Result<Collection<ComponentBatch>> as_batches(const archetypes::AssetVideo& archetype
282 );
283 };
284} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:87
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Arrow-encoded data of a single batch of components together with a component descriptor.
Definition component_batch.hpp:28
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: A video binary.
Definition asset_video.hpp:129
static constexpr auto Descriptor_media_type
ComponentDescriptor for the media_type field.
Definition asset_video.hpp:151
static AssetVideo clear_fields()
Clear all the fields of a AssetVideo.
AssetVideo with_many_blob(const Collection< rerun::components::Blob > &_blob) &&
This method makes it possible to pack multiple blob in a single component batch.
Definition asset_video.hpp:224
std::optional< ComponentBatch > media_type
The Media Type of the asset.
Definition asset_video.hpp:140
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static AssetVideo from_bytes(rerun::Collection< uint8_t > bytes, std::optional< rerun::components::MediaType > media_type={})
Creates a new AssetVideo from the given bytes.
Definition asset_video.hpp:169
static Result< AssetVideo > from_file(const std::filesystem::path &path)
Creates a new AssetVideo from the file contents at path.
AssetVideo with_media_type(const rerun::components::MediaType &_media_type) &&
The Media Type of the asset.
Definition asset_video.hpp:236
static AssetVideo update_fields()
Update only some specific fields of a AssetVideo.
Definition asset_video.hpp:207
static constexpr auto Descriptor_blob
ComponentDescriptor for the blob field.
Definition asset_video.hpp:147
AssetVideo with_blob(const rerun::components::Blob &_blob) &&
The asset's bytes.
Definition asset_video.hpp:215
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition asset_video.hpp:144
Result< std::vector< std::chrono::nanoseconds > > read_frame_timestamps_nanos() const
Determines the presentation timestamps of all frames inside the video.
AssetVideo with_many_media_type(const Collection< rerun::components::MediaType > &_media_type) &&
This method makes it possible to pack multiple media_type in a single component batch.
Definition asset_video.hpp:246
std::optional< ComponentBatch > blob
The asset's bytes.
Definition asset_video.hpp:131
Result< std::vector< std::chrono::nanoseconds > > read_frame_timestamps_ns() const
DEPRECATED: Use read_frame_timestamps_nanos instead.
Definition asset_video.hpp:189
Component: A binary blob of data.
Definition blob.hpp:16
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:20