Rust wrapper for gphoto2 with live preview functionality
  • Rust 98.5%
  • Shell 1.4%
Find a file
2025-09-18 00:29:31 +02:00
.github/workflows [CI] add missing packages for ubuntu 2025-03-04 09:02:35 +01:00
.vscode implement serialize for error 2022-12-14 20:57:00 +01:00
examples make global progress handle private 2023-07-11 01:13:49 +02:00
gphoto2-test bump version 2024-08-23 16:06:50 +00:00
libgphoto2-sys bump version 2024-08-23 16:06:50 +00:00
src expose functionality needed for live preview 2025-09-18 00:29:31 +02:00
.gitignore Why was Cargo.lock not comitted?? 2025-03-04 08:54:31 +01:00
Cargo.lock Why was Cargo.lock not comitted?? 2025-03-04 08:54:31 +01:00
Cargo.toml bump version 2024-08-23 16:06:50 +00:00
LICENSE Changed license to LGPL-v2.1 2022-08-31 09:17:30 +00:00
publish.sh add publish script 2024-08-23 16:09:53 +00:00
README.md attemp to fix CI & update readme 2024-08-23 15:23:14 +00:00
rustfmt.toml derive abstractions on debug, clone, hash, etc. 2022-08-15 19:56:17 +02:00

GPhoto2-rs

Rust bindings to libgphoto2

What about gphoto-rs?

I know about the other crate (gphoto and gphoto2-sys which was created by @dcuddeback, but it is missing a lot of features which make the crate unusable for me, most notably the ability to change camera settings and in memory file download.
The author hasn't been active since 2017 regardless of numerous pull- and feature requests, so I made a new project with a more up to date rust code and all the features from libgphoto2.

Features

  • Camera
    • Capture images
    • Capture preview images
    • Download images
    • Get port information
    • Get abilities (model, driver stability, permissions, ...)
    • Read configuration
    • Set configuration
    • Interact with filesystem on camera
    • Camera events
    • Usb port information
  • Context
    • Autodetect camera
    • Get list of available cameras
    • Get camera by model and port

Gettings started

Installation

Run cargo add gphoto2 to add gphoto2 to your project or add this to your Cargo.toml:

[dependencies]
gphoto2 = "3.3"

Install libgphoto2

The libgphoto2 library must be installed on your system to use this library.

To install libgphoto2 on Debian based systems run:

sudo apt install libgphoto2-dev

On Arch systems run:

sudo pacman -S libgphoto2

On MacOS systems with Homebrew run:

homebrew install libgphoto2
Windows

There is no official way to install libgphoto2 on windows, but you can install it with MSYS2 (link to the package: mingw-w64-libgphoto2).

Basic Usage

This example takes a picture and saves it to disk

use gphoto2::{Context, Result};
use std::path::Path;

fn main() -> Result<()> {
  // Create a new context and detect the first camera from it
  let camera = Context::new()?.autodetect_camera().wait().expect("Failed to autodetect camera");
  let camera_fs = camera.fs();


  // And take pictures
  let file_path = camera.capture_image().wait().expect("Could not capture image");
  camera_fs.download_to(&file_path.folder(), &file_path.name(), Path::new(&file_path.name().to_string())).wait()?;

  // For more advanced examples take a look at the examples/ folder

  Ok(())
}

You can find more examples here

Logging

To make your debugging life a bit easier, this crate hooks up the libgphoto2 log functions to the log crate.

To show the logs use a logging implementation like env_logger.

Additional logs

By default we use gp_context_set_log_func in a context to get the logs, but there is also gp_log_add_func which provides a lot more information and can be a lot more useful when debugging.

The reason this crate doesn't use gp_log_add_func by default is because it is disabled in most Linux distributions and Windows. You will have to check if your installed version does not disable this feature or build libgphoto2 yourself without passing the --disabled-debug flag to the configure command.

To use this feature, enable the extended_logs feature of this crate (the linker will fail if your version of libgphoto2 was not compiled without the --disabled-debug).

Testing

To run the tests of this crate the test feature must be enabled:

cargo test -F test

Note that test builds a very stripped down version of libgphoto2, which is only usable for testing (Don't enable this feature when using this crate).

Stability

In general all all APIs should be stable, I've tested the ones my camera supported and found no bugs so far.
If you encounter an error like BAD_PARAMETERS or found a bug, please create an issue on GitHub.

License

Copyright © 2022 Maxicarlos08 maxicarlos08@gmail.com

This library uses the libgphoto2 library, which is licensed under the LGPL version 2.1.