#screen-capture #capture #screen #recording #media #graphics

bin+lib scap

Modern, high-performance screen capture library for Rust. Cross-platform.

1 unstable release

0.0.3 Feb 23, 2024

#75 in Video

MIT license

68KB
1.5K SLoC

A Rust library to leverage native OS APIs for optimal performance and high-quality screen recordings. We use Apple's ScreenCaptureKit on macOS and Graphics.Capture APIs on Windows. Linux support is planned but not underway yet, PRs welcome!

🚧 WIP. Unsuitable for production use, APIs are being iterated on.

Discord


features

  1. Cross-platform support: Windows and Mac now, Linux soon.
  2. Check for support and user permissions.
  3. Utilize native OS APIs for screen capture.
  4. Different capture modes: audio, display or window.

contributing

I found most of Rust's tooling around screen capture either non-performant, outdated or very platform-specific. This project is my attempt to change that. It's early days and the code is fairly simple, I'll gladly accept any contributions/PRs.

If you'd like to chip in, here's a kickstart guide:

  1. Clone the repo and run it with cargo run.
  2. Explore the API and library code in lib.rs.
  3. Platform-specific code is in the win and mac modules.
  4. There's a small program in main.rs that "consumes" the library for dev-testing.

usage

use scap::{Options, Recorder};

fn main() {
    // Check if the platform is supported
    let supported = scap::is_supported();
    if !supported {
        println!("❌ Platform not supported");
        return;
    } else {
        println!("✅ Platform supported");
    }

    // Check if we have permission to capture the screen
    let has_permission = scap::has_permission();
    if !has_permission {
        println!("❌ Permission not granted");
        return;
    } else {
        println!("✅ Permission granted");
    }

    // Get recording targets (WIP)
    let targets = scap::get_targets();
    println!("🎯 Targets: {:?}", targets);

    // Create Options
    let options = Options {
        fps: 60,
        targets,
        show_cursor: true,
        show_highlight: true,
        excluded_targets: None,
    };

    // Create Recorder
    let mut recorder = Recorder::init(options);

    // Start Capture
    recorder.start_capture();

    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();

    // Stop Capture
    recorder.stop_capture();
}

roadmap

  • Check for support and user permissions.
  • Capture frames
  • Capture targets: monitors, windows, region and audio.
  • Encoding: encode frames to file.

license

The code in this repository is open-sourced under the MIT license. However, it may rely on dependencies that are licensed differently. Please consult their documentations for exact terms.

Contributors

Pranav Joglekar
Pranav Joglekar

💻
Rohan Punjani
Rohan Punjani

💻
Siddharth
Siddharth

💻
NiiightmareXD
NiiightmareXD

💻
MAlba124
MAlba124

💻
Anubhav Singhal
Anubhav Singhal

💻

credits

This project builds on top of the fabulous work done by @svtlabs and @NiiightmareXD.

Dependencies

~14–61MB
~808K SLoC