Rerun C++ SDK
Loading...
Searching...
No Matches
rerun::archetypes::AssetVideo Struct Reference

Archetype: A video binary. More...

#include <rerun/archetypes/asset_video.hpp>

Public Types

using IndicatorComponent = rerun::components::IndicatorComponent< IndicatorComponentName >
 Indicator component, used to identify the archetype when converting to a list of components.
 

Public Member Functions

Result< std::vector< std::chrono::nanoseconds > > read_frame_timestamps_ns () const
 Determines the presentation timestamps of all frames inside the video.
 
 AssetVideo (AssetVideo &&other)=default
 
 AssetVideo (const AssetVideo &other)=default
 
AssetVideooperator= (const AssetVideo &other)=default
 
AssetVideooperator= (AssetVideo &&other)=default
 
 AssetVideo (rerun::components::Blob _blob)
 
AssetVideo with_blob (const rerun::components::Blob &_blob) &&
 The asset's bytes.
 
AssetVideo with_many_blob (const Collection< rerun::components::Blob > &_blob) &&
 This method makes it possible to pack multiple blob in a single component batch.
 
AssetVideo with_media_type (const rerun::components::MediaType &_media_type) &&
 The Media Type of the asset.
 
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.
 
Collection< ComponentColumncolumns (const Collection< uint32_t > &lengths_)
 Partitions the component data into multiple sub-batches.
 
Collection< ComponentColumncolumns ()
 Partitions the component data into unit-length sub-batches.
 

Static Public Member Functions

static Result< AssetVideofrom_file (const std::filesystem::path &path)
 Creates a new AssetVideo from the file contents at path.
 
static AssetVideo from_bytes (rerun::Collection< uint8_t > bytes, std::optional< rerun::components::MediaType > media_type={})
 Creates a new AssetVideo from the given bytes.
 
static AssetVideo update_fields ()
 Update only some specific fields of a AssetVideo.
 
static AssetVideo clear_fields ()
 Clear all the fields of a AssetVideo.
 

Public Attributes

std::optional< ComponentBatchblob
 The asset's bytes.
 
std::optional< ComponentBatchmedia_type
 The Media Type of the asset.
 

Static Public Attributes

static constexpr const char IndicatorComponentName []
 
static constexpr const char ArchetypeName [] = "rerun.archetypes.AssetVideo"
 The name of the archetype as used in ComponentDescriptors.
 
static constexpr auto Descriptor_blob
 ComponentDescriptor for the blob field.
 
static constexpr auto Descriptor_media_type
 ComponentDescriptor for the media_type field.
 

Detailed Description

Archetype: A video binary.

Only MP4 containers with AV1 are generally supported, though the web viewer supports more video codecs, depending on browser.

See https://rerun.io/docs/reference/video for details of what is and isn't supported.

In order to display a video, you also need to log a archetypes::VideoFrameReference for each frame.

Examples

Video with automatically determined frames

image

#include <rerun.hpp>
#include <iostream>
using namespace std::chrono_literals;
int main(int argc, char* argv[]) {
if (argc <2) {
// TODO(#7354): Only mp4 is supported for now.
std::cerr <<"Usage: " <<argv[0] <<" <path_to_video.[mp4]>" <<std::endl;
return 1;
}
const auto path = argv[1];
const auto rec = rerun::RecordingStream("rerun_example_asset_video_auto_frames");
rec.spawn().exit_on_failure();
// Log video asset which is referred to by frame references.
auto video_asset = rerun::AssetVideo::from_file(path).value_or_throw();
rec.log_static("video", video_asset);
// Send automatically determined video frame timestamps.
std::vector<std::chrono::nanoseconds> frame_timestamps_ns =
video_asset.read_frame_timestamps_ns().value_or_throw();
// Note timeline values don't have to be the same as the video timestamps.
auto time_column =
rerun::TimeColumn::from_times("video_time", rerun::borrow(frame_timestamps_ns));
std::vector<rerun::components::VideoTimestamp> video_timestamps(frame_timestamps_ns.size());
for (size_t i = 0; i <frame_timestamps_ns.size(); i++) {
video_timestamps[i] = rerun::components::VideoTimestamp(frame_timestamps_ns[i]);
}
auto video_frame_reference_indicators =
rerun::ComponentColumn::from_indicators<rerun::VideoFrameReference>(
static_cast<uint32_t>(video_timestamps.size())
);
rec.send_columns(
"video",
time_column,
rerun::VideoFrameReference().with_many_timestamp(rerun::borrow(video_timestamps)).columns()
);
}
A RecordingStream handles everything related to logging data into Rerun.
Definition recording_stream.hpp:60
Collection< TElement > borrow(const TElement *data, size_t num_instances=1)
Borrows binary data into a Collection from a pointer.
Definition collection.hpp:462
static TimeColumn from_times(std::string timeline_name, const Collection< std::chrono::duration< TRep, TPeriod > > &chrono_times, SortingStatus sorting_status=SortingStatus::Unknown)
Creates a time column from an array of arbitrary std::chrono durations.
Definition time_column.hpp:135
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Archetype: References a single video frame.
Definition video_frame_reference.hpp:111
Component: Timestamp inside a archetypes::AssetVideo.
Definition video_timestamp.hpp:16

Demonstrates manual use of video frame references

image

#include <rerun.hpp>
#include <iostream>
using namespace std::chrono_literals;
int main(int argc, char* argv[]) {
if (argc <2) {
// TODO(#7354): Only mp4 is supported for now.
std::cerr <<"Usage: " <<argv[0] <<" <path_to_video.[mp4]>" <<std::endl;
return 1;
}
const auto path = argv[1];
const auto rec = rerun::RecordingStream("rerun_example_asset_video_manual_frames");
rec.spawn().exit_on_failure();
// Log video asset which is referred to by frame references.
rec.log_static("video_asset", rerun::AssetVideo::from_file(path).value_or_throw());
// Create two entities, showing the same video frozen at different times.
rec.log("frame_1s", rerun::VideoFrameReference(1.0s).with_video_reference("video_asset"));
rec.log("frame_2s", rerun::VideoFrameReference(2.0s).with_video_reference("video_asset"));
// TODO(#5520): log blueprint once supported
}

Member Function Documentation

◆ from_file()

static Result< AssetVideo > rerun::archetypes::AssetVideo::from_file ( const std::filesystem::path &  path)
static

Creates a new AssetVideo from the file contents at path.

The MediaType will be guessed from the file extension.

If no MediaType can be guessed at the moment, the Rerun Viewer will try to guess one from the data at render-time. If it can't, rendering will fail with an error.

◆ from_bytes()

static AssetVideo rerun::archetypes::AssetVideo::from_bytes ( rerun::Collection< uint8_t >  bytes,
std::optional< rerun::components::MediaType media_type = {} 
)
inlinestatic

Creates a new AssetVideo from the given bytes.

If no MediaType is specified, the Rerun Viewer will try to guess one from the data at render-time. If it can't, rendering will fail with an error.

◆ read_frame_timestamps_ns()

Result< std::vector< std::chrono::nanoseconds > > rerun::archetypes::AssetVideo::read_frame_timestamps_ns ( ) const

Determines the presentation timestamps of all frames inside the video.

Returned timestamps are in nanoseconds since start and are guaranteed to be monotonically increasing.

◆ with_many_blob()

AssetVideo rerun::archetypes::AssetVideo::with_many_blob ( const Collection< rerun::components::Blob > &  _blob) &&
inline

This method makes it possible to pack multiple blob in a single component batch.

This only makes sense when used in conjunction with columns. with_blob should be used when logging a single row's worth of data.

◆ with_media_type()

AssetVideo rerun::archetypes::AssetVideo::with_media_type ( const rerun::components::MediaType _media_type) &&
inline

The Media Type of the asset.

Supported values:

  • video/mp4

If omitted, the viewer will try to guess from the data blob. If it cannot guess, it won't be able to render the asset.

◆ with_many_media_type()

AssetVideo rerun::archetypes::AssetVideo::with_many_media_type ( const Collection< rerun::components::MediaType > &  _media_type) &&
inline

This method makes it possible to pack multiple media_type in a single component batch.

This only makes sense when used in conjunction with columns. with_media_type should be used when logging a single row's worth of data.

◆ columns() [1/2]

Collection< ComponentColumn > rerun::archetypes::AssetVideo::columns ( const Collection< uint32_t > &  lengths_)

Partitions the component data into multiple sub-batches.

Specifically, this transforms the existing ComponentBatch data into ComponentColumns instead, via ComponentBatch::partitioned.

This makes it possible to use RecordingStream::send_columns to send columnar data directly into Rerun.

The specified lengths must sum to the total length of the component batch.

◆ columns() [2/2]

Collection< ComponentColumn > rerun::archetypes::AssetVideo::columns ( )

Partitions the component data into unit-length sub-batches.

This is semantically similar to calling columns with std::vector<uint32_t>(n, 1), where n is automatically guessed.

Member Data Documentation

◆ media_type

std::optional<ComponentBatch> rerun::archetypes::AssetVideo::media_type

The Media Type of the asset.

Supported values:

  • video/mp4

If omitted, the viewer will try to guess from the data blob. If it cannot guess, it won't be able to render the asset.

◆ IndicatorComponentName

constexpr const char rerun::archetypes::AssetVideo::IndicatorComponentName[]
staticconstexpr
Initial value:
=
"rerun.components.AssetVideoIndicator"

◆ Descriptor_blob

constexpr auto rerun::archetypes::AssetVideo::Descriptor_blob
staticconstexpr
Initial value:
= ComponentDescriptor(
ArchetypeName, "blob", Loggable<rerun::components::Blob>::Descriptor.component_name
)
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition asset_video.hpp:135

ComponentDescriptor for the blob field.

◆ Descriptor_media_type

constexpr auto rerun::archetypes::AssetVideo::Descriptor_media_type
staticconstexpr
Initial value:
= ComponentDescriptor(
ArchetypeName, "media_type",
Loggable<rerun::components::MediaType>::Descriptor.component_name
)

ComponentDescriptor for the media_type field.


The documentation for this struct was generated from the following file: