Rust rscam crate: "Could not load image.jpg"

Hi again Rust community :smiley: I hope everyone is good in these bad days of virus!!
Now i need help, When I run ;

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

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

camera.start(&Config {
interval: (1, 30),      // 30 fps.
resolution: (640, 480),
format: b"RGB3",
..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 executes without any problem,and its saves 10 captured images with jpg format.
But when i try opening image with eye of gnome it prints me a message ;

Could not load frame-1.jpg.
Error interpreting JPEG image file (Not a JPEG file: starts with 0xfc 0xfc)
Anyone can help me how to fix this issue ?

The image data is not encoded in the jpg format, so you will have to convert it.

1 Like

any command to do this ?
or any software for linux todo this ?

The example on the front page of the documentation of the rscam crate appears to be able to perform the conversion by setting the format to "MJPG". You can try that.

1 Like

Well when i run with MJPG formatt it outputs me a compile error ;

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadResolution', src/main.rs:8:2
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I don't know anything about the rscam crate. You can try to look into the various image crates and see if any of them can do it for you.

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