l1npengtul / nokhwa

Cross Platform Rust Library for Powerful Webcam/Camera Capture
Apache License 2.0
533 stars 137 forks source link

Can´t save a decoded frame to fs... #185

Open Dreadlord1981 opened 2 weeks ago

Dreadlord1981 commented 2 weeks ago

Hi There i am trying to run it on window 10 and i get an error Here is it the code

       // first camera in system
    let index = CameraIndex::Index(0); 
    // request the absolute highest resolution CameraFormat that can be decoded to RGB.
    let requested = RequestedFormat::new::<RgbFormat>(RequestedFormatType::AbsoluteHighestFrameRate);
    // make the camera
    let mut camera = Camera::new(index, requested).unwrap();

    // get a frame
    camera.stop_stream().unwrap();
    camera.open_stream().unwrap();
    let frame = camera.frame().unwrap();
    camera.stop_stream().unwrap();
    println!("Captured Single Frame of {}", frame.buffer().len());

    // decode into an ImageBuffer
    let decoded = frame.decode_image::<RgbFormat>().unwrap();
    println!("Decoded Frame of {}", decoded.len());

    decoded.save("cam.jpeg").unwrap(); <-- this is the line that causes the error

The error is

thread 'main' panicked at src\main.rs:24:34:
called `Result::unwrap()` on an `Err` value: Unsupported(UnsupportedError { format: Unknown, kind: Format(Name("Jpeg")) })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\rscam.exe` (exit code: 101)

i have traced it down to this part of the code... Where its does not match the format...

#[allow(unused_variables)]
// Most variables when no features are supported
pub(crate) fn write_buffer_impl<W: std::io::Write + Seek>(
    buffered_write: &mut W,
    buf: &[u8],
    width: u32,
    height: u32,
    color: ExtendedColorType,
    format: ImageFormat,
) -> ImageResult<()> {
    match format {

Hope this help :-)