#windows #capturing #fps #icapture-rs

icapture_core

Library for capturing images and video on Windows

1 unstable release

0.1.0 Oct 17, 2024

#470 in Video


Used in 2 crates

MIT license

22KB
464 lines

icapture-rs

icapture-rs is a client-server application for capturing images and video on Windows. It uses Microsoft Media Foundation (unsafe) to detect available capturing devices and OpenCV Rust bindings to communicate with the selected device.

Build

  1. Install vcpkg package manager.

    git clone https://github.com/microsoft/vcpkg.git
    cd vcpkg && bootstrap-vcpkg.bat
    
  2. Specify the vcpkg repository location as the following environment variable and add it to the path.

    $env:VCPKG_ROOT="C:\Git\vcpkg"
    $env:PATH += $env:VCPKG_ROOT + ";"
    
  3. Install llvm and opencv packages (be patient - it took two hours on my laptop).

    vcpkg install llvm opencv4[contrib,nonfree]
    
  4. Find clang.exe in the vcpkg directory and add its location to the path.

    $env:PATH += $env:VCPKG_ROOT + "\installed\x64-windows\tools\llvm" + ";"
    
  5. Set the following environment variable.

    $env:VCPKGRS_DYNAMIC=1
    
  6. Build with cargo build -vv.

Run

Command Line

  1. icapture-rs uses env_logger for logging and tracing. Set the RUST_LOG environment variable to manage the logging level and scope. For instance,

    $env:RUST_LOG="debug"
    
  2. Run with cargo run -p icapture_cli or icapture_cli.exe. Examples:

    cargo run -p icapture_cli -- --help
    cargo run -p icapture_cli -- list-devices
    cargo run -p icapture_cli -- --config-file .\config.json grab-frame
    cargo run -p icapture_cli -- --config-file .\config.json grab-video --duration 5
    

REST Server

  1. Run with cargo run or icapture_srv.exe.

  2. The available endpoints are the following.

    GET http://localhost:1212/list      # list available capturing devices
    POST http://localhost:1212/init     # initialize capturing
    POST http://localhost:1212/preview  # preview the capturing stream
    POST http://localhost:1212/frame    # grab the current frame
    POST http://localhost:1212/start    # start grabbing frames
    POST http://localhost:1212/stop     # stop grabbing frames
    POST http://localhost:1212/deinit   # de-initialize capturing
    

    The init endpoint requires a request body containing capturing configuration, see the config.json file for reference. If the body is empty or its content is invalid, default capturing parameters will be used.

Test

  1. Few existing unit tests can be run with cargo test.

  2. The solution has been developed and tested on Windows 10, version 22H2 with Magewell USB Capture HDMI 4K Plus card.

Dependencies

~127MB
~2M SLoC