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