Rust: How to record a video

Hi rust community :smiley:
I am using camera-capture crate(, but it won't finish the build. It says ;

   Compiling camera_capture v0.5.0
   Compiling crossbeam-queue v0.2.1
   Compiling memoffset v0.5.3
   Compiling num-iter v0.1.40
error: failed to run custom build command for `camera_capture v0.5.0`

Caused by:
  process didn't exit successfully: `/home/eqelibari/Projects/1/testsavefile/target/debug/build/camera_capture-fa6eea4c9a055251/build-script-build` (exit code: 101)
--- stdout

--- stderr
thread 'main' panicked at 'library `v4l2` not found: Failure { command: "\"pkg-config\" \"--static\" \"--libs\" \"--cflags\" \"libv4l2\"", output: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "Package libv4l2 was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libv4l2.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'libv4l2\' found\n" } }', src/libcore/
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed

But i have already install v4l-utils ..

You probably need libv4l-dev / libv4l-devel to support pkg-config.


Yes thank you, and here the two steps for fixing this issue ! :smiley:

  1. sudo apt-get update -y
  2. sudo apt-get install -y libv4l-dev

When i execute rscam;

use rscam::{Camera, Config};
use std::fs;
use std::io::Write;

fn main() {
let mut camera = rscam::new("/dev/video0").unwrap();

camera.start(&rscam::Config {
    interval: (1, 30),      // 30 fps.
    resolution: (1280, 720),
    format: b"MJPG",

for i in 0..10 {
    let frame = camera.capture().unwrap();
    let mut file = fs::File::create(&format!("frame-{}.jpg", i)).unwrap();

it outputs ;

   Compiling testsavefile v0.1.0 (/home/eqelibari/Projects/1/testsavefile)
    Finished dev [unoptimized + debuginfo] target(s) in 0.55s
     Running `target/debug/testsavefile`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadResolution', src/libcore/
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

I tried to change the resolution in higher pixels,but it still panic with the same error..

When I saw the title, I thought β€œno way did someone actually show up here looking for the video game”.

So this was a pleasant surprise :slight_smile:

EDIT: Sorry for the slightly off-topic. I was just floored.


Haha :stuck_out_tongue:

1 Like

I don't know anything about using that crate, but it looks like Camera::resolutions will tell you what it's capable of.

1 Like

@cuviper I just had to change the format, from MJPEG to RGB3 or Default (in my case).
Its capture 10 jpg images and saves them,but now when i try opening these images , an error message is printing me: Could not load Image: frame-1.jpg. Error interpreting JPEG image file (Not a JPEG file: starts with 0xfc 0xfc). How can i fix this..

My guess is that you've got raw RGB pixel values, not encoded in any image format.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.