Skip to main content

Crate bevy_v4l2

Crate bevy_v4l2 

Source
Expand description

Low-latency V4L2 webcam capture for Bevy.

  • capture: V4L2 streaming with kernel MMAP buffers 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 (feature dmabuf): enables the Vulkan extensions during Bevy’s device creation and wraps a DMA-BUF as a wgpu::Texture with no copy.
  • plugin: WebcamPlugin and the Webcam component, 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 (feature mjpeg).
  • 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
WebcamPlugin and the Webcam component: a V4L2 camera on a plane.
select
Picking a capture mode.

Structs§

FourCC
Four character code representing a pixelformat