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.
-
Install
vcpkgpackage manager.git clone https://github.com/microsoft/vcpkg.git cd vcpkg && bootstrap-vcpkg.bat
-
Specify the
vcpkgrepository location as the following environment variable and add it to the path.$env:VCPKG_ROOT="C:\Git\vcpkg" $env:PATH += $env:VCPKG_ROOT + ";"
-
Install
llvmandopencvpackages (be patient - it took two hours on my laptop).vcpkg install llvm opencv4[contrib,nonfree]
-
Find
clang.exein thevcpkgdirectory and add its location to the path.$env:PATH += $env:VCPKG_ROOT + "\installed\x64-windows\tools\llvm" + ";"
-
Set the following environment variable.
$env:VCPKGRS_DYNAMIC=1
-
Build with
cargo build -vv.
-
icapture-rs uses env_logger for logging and tracing. Set the
RUST_LOGenvironment variable to manage the logging level and scope. For instance,$env:RUST_LOG="debug"
-
Run with
cargo run -p icapture_clioricapture_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
-
Run with
cargo runoricapture_srv.exe. -
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 capturingThe
initendpoint requires a request body containing capturing configuration, see theconfig.jsonfile for reference. If the body is empty or its content is invalid, default capturing parameters will be used.
-
Few existing unit tests can be run with
cargo test. -
The solution has been developed and tested on Windows 10, version 22H2 with Magewell USB Capture HDMI 4K Plus card.