agentleFS
chrisgliddonchrisgliddon/bevy-skills/skills/bevy-capture/SKILL.md

bevy-capture

Skill16 starsChanged 3 months agoMITView on GitHub

Use when adding `CapturePlugin`, attaching `CaptureBundle` and `RenderTarget::target_headless` to a camera, starting or stopping `Capture`, choosing `Mp4Openh264Encoder`/`Mp4FfmpegCliPipeEncoder`/`FramesEncoder`, or diagnosing empty off-screen recordings in Bevy 0.19.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Wait at least one frame before starting.

    line 123

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

bevy-capture — recording Bevy 0.19 cameras

When to use this skill

  • Record deterministic gameplay, cinematics, or render-test evidence.
  • Capture a headless Camera2d/Camera3d to MP4, GIF, or numbered PNGs.
  • Choose between in-process OpenH264, ffmpeg, and lossless frame output.
  • Diagnose a missing encoder module, an empty output, or an unflushed recording.

bevy_capture = "0.6" natively targets Bevy 0.19. Do not carry forward the 0.4.x Bevy patch or its old CameraTargetHeadless API.

Canonical pattern

[dependencies]
bevy = "0.19"
bevy_capture = { version = "0.6", features = ["mp4_openh264"] }
use bevy::{
    app::{RunMode, ScheduleRunnerPlugin},
    camera::RenderTarget,
    prelude::*,
    render::RenderPlugin,
    winit::WinitPlugin,
};
use bevy_capture::{
    encoder::mp4_openh264::Mp4Openh264Encoder,
    Capture, CaptureBundle, CapturePlugin, RenderTargetHeadless,
};
use std::fs::{self, File};

const WIDTH: u16 = 1280;
const HEIGHT: u16 = 720;

fn main() -> AppExit {
    App::new()
        .add_plugins((
            DefaultPlugins.build().disable::<WinitPlugin>().set(RenderPlugin {
                synchronous_pipeline_compilation: true,
                ..default()
            }),
            ScheduleRunnerPlugin {
                run_mode: RunMode::Loop { wait: None },
            },
            CapturePlugin,
        ))
        .add_systems(Startup, setup)
        .add_systems(Update, record)
        .run()
}

fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
    commands.spawn((
        Camera2d,
        RenderTarget::target_headless(WIDTH.into(), HEIGHT.into(), &mut images),
        CaptureBundle::default(),
    ));
}

fn record(
    mut captures: Query<&mut Capture>,
    mut waited_for_pipeline: Local<bool>,
    mut frame: Local<u32>,
) {
    // Allow the render pipeline one frame to become ready.
    if !*waited_for_pipeline {
        *waited_for_pipeline = true;
        return;
    }

    let Ok(mut capture) = captures.single_mut() else { return };
    if !capture.is_capturing() && *frame == 0 {
        fs::create_dir_all("captures").expect("create captures directory");
        let encoder = Mp4Openh264Encoder::new(
            File::create("captures/run.mp4").expect("create output"),
            WIDTH,
            HEIGHT,
        )
        .expect("initialize OpenH264");
        capture.start(encoder);
    }

    *frame += 1;
    if *frame == 300 {
        capture.stop(); // drops the encoder and finalizes the MP4
    }
}

Encoder choice

EncoderFeatureExternal programBest fit
Mp4Openh264Encodermp4_openh264NoIn-process H.264
Mp4FfmpegCliEncodermp4_ffmpeg_cliffmpegShort/offline clips
Mp4FfmpegCliPipeEncodermp4_ffmpeg_cli_pipeffmpegLong streaming captures
GifEncodergifNoSmall previews
FramesEncodernoneNoLossless PNG sequence

See encoder details before choosing a production codec or distribution model.

Gotchas

  • RenderTargetHeadless is implemented for RenderTarget; call RenderTarget::target_headless(...). The old helper on Camera is stale.
  • Attach Camera2d/Camera3d, the headless RenderTarget, and CaptureBundle to the same entity.
  • Wait at least one frame before starting. Synchronous pipeline compilation improves deterministic batch capture but can increase startup time.
  • Encoder modules are feature-gated. Enable exactly the features you import.
  • Capture::stop() or dropping Capture finalizes encoders. Abrupt process termination can leave an invalid MP4 or GIF.
  • The ffmpeg encoders require ffmpeg on PATH; constructors return Result.
  • Match the encoder dimensions to the headless target. OpenH264 takes u16.
  • Browser WASM has no ordinary filesystem or child processes. Design an explicit JS download/streaming path instead of assuming these encoders work.

See also

  • bevy-cameras — cameras and render targets.
  • bevy-cargo-features — feature selection.
  • bevy-wasm-webgpu — browser constraints.
  • Encoder comparison.
  • 0.19 compatibility.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.