1 unstable release
0.1.0 | Oct 17, 2024 |
---|
#470 in Video
Used in 2 crates
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
-
Install
vcpkg
package manager.git clone https://github.com/microsoft/vcpkg.git cd vcpkg && bootstrap-vcpkg.bat
-
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 + ";"
-
Install
llvm
andopencv
packages (be patient - it took two hours on my laptop).vcpkg install llvm opencv4[contrib,nonfree]
-
Find
clang.exe
in thevcpkg
directory 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
.
Run
Command Line
-
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"
-
Run with
cargo run -p icapture_cli
oricapture_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
-
Run with
cargo run
oricapture_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 capturing
The
init
endpoint requires a request body containing capturing configuration, see theconfig.json
file for reference. If the body is empty or its content is invalid, default capturing parameters will be used.
Test
-
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.
Dependencies
~127MB
~2M SLoC