Video
A stream of images (like those produced by a camera) can be logged to Rerun in several different ways:
- Uncompressed, as many
Images - Compressed as many
EncodedImages, using e.g. JPEG. - Compressed as a single
AssetVideo, using e.g. MP4. - Compressed as a series of encoded video samples using
VideoStream, using e.g. H.264 encoded frames.
These alternatives range on a scale of "simple, lossless, and big" to "complex, lossy, and small".
If you want lossless encoded images (with no compression artifacts), then you should log each video frame as Image.
This will use up a lot of space and bandwidth. You can also encode them as PNG and log them as EncodedImage,
though it should be noted that PNG encoding usually does very little for the file size of photographic images.
If you want to reduce bandwidth and storage cost, you can encode each frame as a JPEG and log it using EncodedImage. This can easily reduce the file sizes by almost two orders of magnitude with minimal perceptual loss.
This is also very simple to do, and the Python logging SDK has built-in support for it using Image.compress.
Finally, for the best compression ratio, you can encode the images as an encoded video. There are two options to choose from:
- Raw video frames
VideoStream - Video files using
AssetVideo
⚠️ Do not use compressed video if you need accurate pixel replication: this is not only due to the obvious detail loss on encoding, but also since the exact display of the same video is not consistent across platforms and decoder versions.
Streaming video / raw encoded video frames
The following example illustrates how to encode uncompressed video frames (represented by numpy arrays)
using pyAV into H.264 and directly log them to Rerun using VideoStream.
snippet: archetypes/video_stream_synthetic
Using VideoStream requires deeper knowledge of the encoding process
but unlike AssetVideo,
allows the Rerun Viewer to show incomplete or open ended video streams.
In contrast, AssetVideo requires the entire
video asset file to be in Viewer memory before decoding can begin.
Refer to the video camera streaming example to learn how to stream live video to Rerun.
Current limitations of VideoStream:
- #9815: Decoding on native is generally slower than decoding in the browser right now. This can cause increased latency and in some cases may even stop video playback.
- #10184, #10186:
VideoStreamonly supports H.264 & H.265 at this point. - #10090: B-frames are not yet supported for
VideoStream. - #10422:
VideoFrameReferencedoes not yet work withVideoStream.
Export MP4 from RRD (remuxing)
Sample data from VideoStream can be queried
and remuxed to mp4 without re-encoding the video as demonstrated in this sample.
Check the doc page on retrieving data to learn more about dataframe queries in general.
Video files
You can use AssetVideo to log readily encoded video files.
Rerun ignores the timestamp at which the video asset itself is logged and requires you
to log VideoFrameReference to establish a
correlation of video time to the Rerun timeline.
To ease this, the SDK's read_frame_timestamps_nanos utility allows to read out timestamps from in-memory video assets:
snippet: archetypes/video_auto_frames
#7354: Currently, only MP4 files are supported.
Codec support in detail
Overview
Codec support varies in the web & native viewer:
| Browser | Native | |
|---|---|---|
| AV1 | ✅ | 🟧 |
| H.264/avc | ✅ | ✅ |
| H.265/hevc | 🟧 | ✅ |
| VP9 | ✅ | ❌ |
Details see below.
When choosing a codec, we recommend AV1, as it seems to have the best overall playback support while also having very high compression quality.
Since AV1 can have very long encoding times, it is often not suitable for streaming. In cases where encoding time matters, we recommend H.264/avc.
Native viewer
AV1
AV1 is supported out of the box using a software decoder paired with gpu based image conversion.
Current limitations:
- #7755: AV1 is supported on all native builds exception on Linux ARM.
- #10184: AV1 is not yet supported for the
VideoStreamarchetype.
H.264/avc & H.265/hevc
H.264/avc and H.265/hevc are supported via a separately installed FFmpeg binary, requiring a minimum version of 5.1.
The viewer does intentionally not come bundled with FFmpeg to avoid licensing issues.
By default rerun will look for a system installed FFmpeg installation in PATH,
but you can specify a custom path in the viewer's settings.
If you select a video that failed to play due to missing or incompatible FFmpeg binaries it will offer a download link to a build of FFmpeg for your platform.
Web viewer
Video playback in the Rerun Web Viewer is done using the browser's own video decoder, so the exact supported codecs depend on your browser.
Overall, we recommend using Chrome or another Chromium-based browser, as it seems to have the best video support as of writing.
For decoding video in the Web Viewer, we use the WebCodecs API. This API enables us to take advantage of the browser's hardware accelerated video decoding capabilities. It is implemented by all modern browsers, but with varying levels of support for different codecs, and varying levels of quality.
When it comes to codecs, we aim to support any codec which the browser supports, but we currently cannot guarantee that all of them will work. For more information about which codecs are supported by which browser, see Video codecs on MDN.
We tested the following codecs in more detail:
| Linux Firefox | Linux Chrome1 | macOS Firefox | macOS Chrome | macOS Safari | Windows Firefox | Windows Chrome2 | |
|---|---|---|---|---|---|---|---|
| AV1 | ✅ | ✅ | ✅ | ✅ | 🚧3 | ✅ | ✅ |
| H.264/avc | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| H.265/hevc | ❌ | ❌ | ❌ | ✅ | 🚧4 | ❌ | 🚧5 |
Any Chromium-based browser should work, but we don't test all of them.
Chrome on Windows has been observed to stutter on playback. It can be mitigated by using software decoding, but this may lead to high memory usage. See #7595.
Safari/WebKit does not support AV1 decoding except on Apple Silicon devices with hardware support.
Safari/WebKit has been observed suttering when playing hvc1 but working fine with hevc1. Despite support being advertised Safari 16.5 has been observed not support H.265 decoding.
Only supported if hardware encoding is available. Therefore always affected by Windows stuttering issues, see above.
Beyond this, for best compatibility we recommend:
- prefer YUV over RGB & monochrome formats
- don't use more than 8bit per color channel
- keep resolutions at 8k & lower (see also #3782)
Other limitations
There are still some limitations to encoded Video in Rerun which will be addressed in the future:
- #7594: HDR video is not supported
- #5181: There is no audio support
- There is no video encoder in the Rerun SDK, so you need to create the video stream or file yourself.
Refer to the video camera streaming example to learn how to encode video using
pyAV.