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 "../compiler_utils.hpp"
8#include "../component_batch.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 /// {
79 /// video_frame_reference_indicators.value_or_throw(),
80 /// rerun::ComponentColumn::from_loggable(rerun::borrow(video_timestamps)).value_or_throw(),
81 /// }
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]>" <<std::endl;
100 /// return 1;
101 /// }
102 ///
103 /// const auto path = argv[1];
104 ///
105 /// const auto rec = rerun::RecordingStream("rerun_example_asset_video_manual_frames");
106 /// rec.spawn().exit_on_failure();
107 ///
108 /// // Log video asset which is referred to by frame references.
109 /// rec.log_static("video_asset", rerun::AssetVideo::from_file(path).value_or_throw());
110 ///
111 /// // Create two entities, showing the same video frozen at different times.
112 /// rec.log("frame_1s", rerun::VideoFrameReference(1.0s).with_video_reference("video_asset"));
113 /// rec.log("frame_2s", rerun::VideoFrameReference(2.0s).with_video_reference("video_asset"));
114 ///
115 /// // TODO(#5520): log blueprint once supported
116 /// }
117 /// ```
118 struct AssetVideo {
119 /// The asset's bytes.
121
122 /// The Media Type of the asset.
123 ///
124 /// Supported values:
125 /// * `video/mp4`
126 ///
127 /// If omitted, the viewer will try to guess from the data blob.
128 /// If it cannot guess, it won't be able to render the asset.
129 std::optional<rerun::components::MediaType> media_type;
130
131 public:
132 static constexpr const char IndicatorComponentName[] =
133 "rerun.components.AssetVideoIndicator";
134
135 /// Indicator component, used to identify the archetype when converting to a list of components.
137
138 public: // START of extensions from asset_video_ext.cpp:
139 /// Creates a new `AssetVideo` from the file contents at `path`.
140 ///
141 /// The `MediaType` will be guessed from the file extension.
142 ///
143 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
144 /// from the data at render-time. If it can't, rendering will fail with an error.
145 static Result<AssetVideo> from_file(const std::filesystem::path& path);
146
147 /// Creates a new `AssetVideo` from the given `bytes`.
148 ///
149 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
150 /// at render-time. If it can't, rendering will fail with an error.
153 std::optional<rerun::components::MediaType> media_type = {}
154 ) {
155 // TODO(jan): we could try and guess using magic bytes here, like rust does.
156 AssetVideo asset = AssetVideo(std::move(bytes));
157 asset.media_type = media_type;
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 // END of extensions from asset_video_ext.cpp, start of generated code:
167
168 public:
169 AssetVideo() = default;
170 AssetVideo(AssetVideo&& other) = default;
171
172 explicit AssetVideo(rerun::components::Blob _blob) : blob(std::move(_blob)) {}
173
174 /// The Media Type of the asset.
175 ///
176 /// Supported values:
177 /// * `video/mp4`
178 ///
179 /// If omitted, the viewer will try to guess from the data blob.
180 /// If it cannot guess, it won't be able to render the asset.
182 media_type = std::move(_media_type);
183 // See: https://github.com/rerun-io/rerun/issues/4027
184 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
185 }
186 };
187
188} // namespace rerun::archetypes
189
190namespace rerun {
191 /// \private
192 template <typename T>
193 struct AsComponents;
194
195 /// \private
196 template <>
197 struct AsComponents<archetypes::AssetVideo> {
198 /// Serialize all set component batches.
199 static Result<std::vector<ComponentBatch>> serialize(const archetypes::AssetVideo& archetype
200 );
201 };
202} // 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:22
Archetype: A video binary.
Definition asset_video.hpp:118
AssetVideo with_media_type(rerun::components::MediaType _media_type) &&
The Media Type of the asset.
Definition asset_video.hpp:181
rerun::components::Blob blob
The asset's bytes.
Definition asset_video.hpp:120
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:151
static Result< AssetVideo > from_file(const std::filesystem::path &path)
Creates a new AssetVideo from the file contents at path.
Result< std::vector< std::chrono::nanoseconds > > read_frame_timestamps_ns() const
Determines the presentation timestamps of all frames inside the video.
std::optional< rerun::components::MediaType > media_type
The Media Type of the asset.
Definition asset_video.hpp:129
Component: A binary blob of data.
Definition blob.hpp:16
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:30
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:20