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_ns().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_times("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 // END of extensions from asset_video_ext.cpp, start of generated code:
178
179 public:
180 AssetVideo() = default;
181 AssetVideo(AssetVideo&& other) = default;
182 AssetVideo(const AssetVideo& other) = default;
183 AssetVideo& operator=(const AssetVideo& other) = default;
184 AssetVideo& operator=(AssetVideo&& other) = default;
185
186 explicit AssetVideo(rerun::components::Blob _blob)
187 : blob(ComponentBatch::from_loggable(std::move(_blob), Descriptor_blob).value_or_throw()
188 ) {}
189
190 /// Update only some specific fields of a `AssetVideo`.
192 return AssetVideo();
193 }
194
195 /// Clear all the fields of a `AssetVideo`.
197
198 /// The asset's bytes.
200 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
201 return std::move(*this);
202 }
203
204 /// This method makes it possible to pack multiple `blob` in a single component batch.
205 ///
206 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
207 /// be used when logging a single row's worth of data.
209 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
210 return std::move(*this);
211 }
212
213 /// The Media Type of the asset.
214 ///
215 /// Supported values:
216 /// * `video/mp4`
217 ///
218 /// If omitted, the viewer will try to guess from the data blob.
219 /// If it cannot guess, it won't be able to render the asset.
221 media_type =
222 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
223 return std::move(*this);
224 }
225
226 /// This method makes it possible to pack multiple `media_type` in a single component batch.
227 ///
228 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
229 /// be used when logging a single row's worth of data.
231 ) && {
232 media_type =
233 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
234 return std::move(*this);
235 }
236
237 /// Partitions the component data into multiple sub-batches.
238 ///
239 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
240 /// instead, via `ComponentBatch::partitioned`.
241 ///
242 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
243 ///
244 /// The specified `lengths` must sum to the total length of the component batch.
246
247 /// Partitions the component data into unit-length sub-batches.
248 ///
249 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
250 /// where `n` is automatically guessed.
252 };
253
254} // namespace rerun::archetypes
255
256namespace rerun {
257 /// \private
258 template <typename T>
259 struct AsComponents;
260
261 /// \private
262 template <>
263 struct AsComponents<archetypes::AssetVideo> {
264 /// Serialize all set component batches.
265 static Result<Collection<ComponentBatch>> as_batches(const archetypes::AssetVideo& archetype
266 );
267 };
268} // 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:208
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:220
static AssetVideo update_fields()
Update only some specific fields of a AssetVideo.
Definition asset_video.hpp:191
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:199
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
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:230
std::optional< ComponentBatch > blob
The asset's bytes.
Definition asset_video.hpp:117
Result< std::vector< std::chrono::nanoseconds > > read_frame_timestamps_ns() const
Determines the presentation timestamps of all frames inside the video.
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