-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples for manual logging of video reference + needed extension…
…s etc.
- Loading branch information
Showing
18 changed files
with
334 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
crates/store/re_types/src/components/video_timestamp_ext.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
use super::VideoTimestamp; | ||
|
||
impl VideoTimestamp { | ||
/// Create new timestamp from seconds since video start. | ||
#[inline] | ||
pub fn from_seconds(seconds: f64) -> Self { | ||
crate::datatypes::VideoTimestamp::from_nanoseconds((seconds * 1e9) as i64).into() | ||
} | ||
|
||
/// Create new timestamp from milliseconds since video start. | ||
#[inline] | ||
pub fn from_milliseconds(milliseconds: f64) -> Self { | ||
crate::datatypes::VideoTimestamp::from_nanoseconds((milliseconds * 1e6) as i64).into() | ||
} | ||
|
||
/// Create new timestamp from nanoseconds since video start. | ||
#[inline] | ||
pub fn new_nanoseconds(nanos: i64) -> Self { | ||
crate::datatypes::VideoTimestamp::new_nanoseconds(nanos).into() | ||
pub fn from_nanoseconds(nanos: i64) -> Self { | ||
crate::datatypes::VideoTimestamp::from_nanoseconds(nanos).into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Log a video asset using manually created frame references. | ||
// TODO(#7298): ⚠️ Video is currently only supported in the Rerun web viewer. | ||
|
||
#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. | ||
// Make sure it's available on the timeline used for the frame references. | ||
rec.set_time_seconds("video_time", 0.0); | ||
rec.log("video", rerun::AssetVideo::from_file(path).value_or_throw()); | ||
|
||
// Send frame references for every 0.1 seconds over a total of 10 seconds. | ||
// Naturally, this will result in a choppy playback and only makes sense if the video is 10 seconds or longer. | ||
// TODO(#7368): Point to example using `send_video_frames`. | ||
// | ||
// Use `send_columns` to send all frame references in a single call. | ||
std::vector<std::chrono::milliseconds> times(10 * 10); | ||
std::vector<rerun::components::VideoTimestamp> video_timestamps(10 * 10); | ||
for (size_t i = 0; i < times.size(); i++) { | ||
times[i] = 100ms * i; | ||
video_timestamps[i] = rerun::components::VideoTimestamp(times[i]); | ||
} | ||
rec.send_columns( | ||
"video", | ||
rerun::TimeColumn::from_times("video_time", rerun::borrow(times)), | ||
{ | ||
rerun::ComponentColumn::from_indicators<rerun::VideoFrameReference>(times.size()) | ||
.value_or_throw(), | ||
rerun::ComponentColumn::from_loggable(rerun::borrow(video_timestamps)).value_or_throw(), | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
Log a video asset using manually created frame references. | ||
TODO(#7298): ⚠️ Video is currently only supported in the Rerun web viewer. | ||
""" | ||
|
||
import sys | ||
|
||
import rerun as rr | ||
import numpy as np | ||
|
||
if len(sys.argv) < 2: | ||
# TODO(#7354): Only mp4 is supported for now. | ||
print(f"Usage: {sys.argv[0]} <path_to_video.[mp4]>") | ||
sys.exit(1) | ||
|
||
rr.init("rerun_example_asset_video_manual_frames", spawn=True) | ||
|
||
# Log video asset which is referred to by frame references. | ||
rr.set_time_seconds("video_time", 0) # Make sure it's available on the timeline used for the frame references. | ||
rr.log("video", rr.AssetVideo(path=sys.argv[1])) | ||
|
||
# Send frame references for every 0.1 seconds over a total of 10 seconds. | ||
# Naturally, this will result in a choppy playback and only makes sense if the video is 10 seconds or longer. | ||
# TODO(#7368): Point to example using `send_video_frames`. | ||
# | ||
# Use `send_columns` to send all frame references in a single call. | ||
times = np.arange(0.0, 10.0, 0.1) | ||
rr.send_columns( | ||
"video", | ||
times=[rr.TimeSecondsColumn("video_time", times)], | ||
components=[rr.VideoFrameReference.indicator(), rr.components.VideoTimestamp.seconds(times)], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! Log a video asset using manually created frame references. | ||
//! TODO(#7298): ⚠️ Video is currently only supported in the Rerun web viewer. | ||
use rerun::{external::anyhow, TimeColumn}; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let args = _args; | ||
let Some(path) = args.get(1) else { | ||
// TODO(#7354): Only mp4 is supported for now. | ||
anyhow::bail!("Usage: {} <path_to_video.[mp4]>", args[0]); | ||
}; | ||
|
||
let rec = | ||
rerun::RecordingStreamBuilder::new("rerun_example_asset_video_manual_frames").spawn()?; | ||
|
||
// Log video asset which is referred to by frame references. | ||
rec.set_time_seconds("video_time", 0.0); // Make sure it's available on the timeline used for the frame references. | ||
rec.log("video", &rerun::AssetVideo::from_file_path(path)?)?; | ||
|
||
// Send frame references for every 0.1 seconds over a total of 10 seconds. | ||
// Naturally, this will result in a choppy playback and only makes sense if the video is 10 seconds or longer. | ||
// TODO(#7368): Point to example using `send_video_frames`. | ||
// | ||
// Use `send_columns` to send all frame references in a single call. | ||
let times = (0..(10 * 10)).map(|t| t as f64 * 0.1).collect::<Vec<_>>(); | ||
let time_column = TimeColumn::new_seconds("video_time", times.iter().copied()); | ||
let frame_reference_indicators = | ||
<rerun::VideoFrameReference as rerun::Archetype>::Indicator::new_array(times.len()); | ||
let video_timestamps = times | ||
.into_iter() | ||
.map(rerun::components::VideoTimestamp::from_seconds) | ||
.collect::<Vec<_>>(); | ||
rec.send_columns( | ||
"video", | ||
[time_column], | ||
[&frame_reference_indicators as _, &video_timestamps as _], | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.