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