Crates.io | bevy_capture |
lib.rs | bevy_capture |
version | 0.2.0 |
source | src |
created_at | 2024-08-16 23:52:09.757837 |
updated_at | 2024-12-06 23:22:28.175605 |
description | A Bevy plugin for capturing frames from a Bevy application. |
homepage | |
repository | https://github.com/jannik4/bevy_capture |
max_upload_size | |
id | 1341127 |
size | 169,826 |
A Bevy plugin for capturing frames from a Bevy application. It comes with some built-in encoders, e.g. for creating gifs or videos, and can be easily extended with custom encoders.
Name | Description | Required Features |
---|---|---|
FramesEncoder |
Encodes frames into individual images. | |
GifEncoder |
Encodes frames into a gif. | gif |
Mp4Openh264Encoder |
Encodes frames into an mp4 using openh264. | mp4_openh264 |
Mp4FfmpegCliEncoder |
Encodes frames into an mp4 using the ffmpeg CLI (ffmpeg must be in PATH). | mp4_ffmpeg_cli |
For a complete example, see the simple example.
// Add plugins
app.add_plugins((
DefaultPlugins
.build()
// Disable the WinitPlugin to prevent the creation of a window
.disable::<WinitPlugin>()
// Make sure pipelines are ready before rendering
.set(RenderPlugin {
synchronous_pipeline_compilation: true,
..default()
}),
// Add the ScheduleRunnerPlugin to run the app in loop mode
ScheduleRunnerPlugin {
run_mode: RunMode::Loop { wait: None },
},
// Add the CapturePlugin
bevy_capture::CapturePlugin,
));
// Spawn a camera with the CaptureBundle
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
commands.spawn((
Camera2d,
Camera::default().target_headless(512, 512, &mut images),
CaptureBundle::default(),
));
}
// Start capturing
fn update(mut capture: Query<&mut Capture>) {
let mut capture = capture.single_mut();
if !capture.is_capturing() {
capture.start(
GifEncoder::new(File::create("my_capture.gif").unwrap())
.with_repeat(gif::Repeat::Infinite)
);
}
}
struct MyCustomEncoder;
impl Encoder for MyCustomEncoder {
fn encode(&mut self, image: &Image) -> Result<()> {
// Called for each frame.
todo!("Encode the image into your custom format.")
}
fn finish(self: Box<Self>) {
// Called when the encoder is stopped.
todo!("Finish encoding the frames, if necessary.")
}
}
Licensed under either of
at your option.