Rust: How to record a video

Hi rust community :smiley:
I am using camera-capture crate(https://crates.io/crates/camera_capture/0.5.0), 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
cargo:rerun-if-changed=Cargo.toml

--- 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/result.rs:1188:5
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.

2 Likes

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",
    ..Default::default()
}).unwrap();

for i in 0..10 {
    let frame = camera.capture().unwrap();
    let mut file = fs::File::create(&format!("frame-{}.jpg", i)).unwrap();
    file.write_all(&frame[..]).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/result.rs:1188:5
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.

4 Likes

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.