Expand description
Low-latency V4L2 webcam capture for Bevy.
capture: V4L2 streaming with kernelMMAPbuffers exported as DMA-BUF file descriptors, newest-frame-wins delivery, and the CPU cache write-back that keeps a non-snooping GPU coherent with the driver’s writes.dmabuf(featuredmabuf): enables the Vulkan extensions during Bevy’s device creation and wraps a DMA-BUF as awgpu::Texturewith no copy.plugin:WebcamPluginand theWebcamcomponent, which put the feed on a plane with a material whose shader converts packed YUV to RGB on the GPU; MJPEG streams are decoded on a thread (featuremjpeg).select: picks the best mode for a wanted size and rate, preferring raw (zero-copy).controls: device listing and V4L2 controls (brightness, focus, zoom, …).
use bevy::prelude::*;
use bevy_v4l2::{DmabufTexturePlugin, Webcam, WebcamPlugin};
App::new()
// Must come before DefaultPlugins so the Vulkan device gets the DMA-BUF extensions.
.add_plugins(DmabufTexturePlugin)
.add_plugins(DefaultPlugins)
.add_plugins(WebcamPlugin)
.add_systems(Startup, |mut commands: Commands| {
commands.spawn((Webcam::want(1280, 720, 60), Transform::from_xyz(0.0, 0.45, 0.0)));
})
.run();Linux only: everything here talks to /dev/video*.
Re-exports§
pub use calibration::Calibrate;pub use calibration::CalibrationPhase;pub use calibration::CalibrationPlugin;pub use calibration::CalibrationProgress;pub use calibration::CalibrationRun;pub use calibration::CameraCalibration;pub use calibration::ChessboardSpec;pub use calibration::Detection;pub use calibration::RollingShutter;pub use dmabuf::DmabufImportEnabled;pub use dmabuf::DmabufTexturePlugin;pub use capture::*;pub use controls::*;pub use plugin::*;pub use select::*;
Modules§
- calibration
- Lens and rolling-shutter calibration with a printed chessboard.
- capture
- Low-latency V4L2 capture with DMA-BUF export.
- controls
- Camera enumeration and V4L2 controls (brightness, focus, zoom, …).
- dmabuf
- Zero-copy DMA-BUF import for Bevy’s wgpu/Vulkan renderer.
- mjpeg
- MJPEG decode thread: dequeues JPEG frames, decodes the newest into RGBA, recycles buffers.
- plugin
WebcamPluginand theWebcamcomponent: a V4L2 camera on a plane.- select
- Picking a capture mode.
Structs§
- FourCC
- Four character code representing a pixelformat