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