{"id":13578612,"url":"https://github.com/NiiightmareXD/windows-capture","last_synced_at":"2025-04-05T19:33:19.795Z","repository":{"id":196185893,"uuid":"695057398","full_name":"NiiightmareXD/windows-capture","owner":"NiiightmareXD","description":"Fastest Windows Screen Capture Library For Rust And Python 🔥","archived":false,"fork":false,"pushed_at":"2024-06-07T03:58:22.000Z","size":1493,"stargazers_count":142,"open_issues_count":10,"forks_count":18,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-06-08T15:42:12.073Z","etag":null,"topics":["game-capture","python","python-library","rust","rust-lang","screen-capture","screen-recorder","screenshot","screenshots","video-recording"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NiiightmareXD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["BTC: bc1q9l3h8ld329skh9ajv5vz2hslfm3s2nv540yn8p","ETH: 0x3a9d72f341d03Eb8C5be9aC69A0236f71DD48192"]}},"created_at":"2023-09-22T09:02:58.000Z","updated_at":"2024-07-09T09:12:19.017Z","dependencies_parsed_at":"2023-11-23T07:30:26.648Z","dependency_job_id":"d0a2a0fc-906a-470c-88ca-ff78eccdf19b","html_url":"https://github.com/NiiightmareXD/windows-capture","commit_stats":null,"previous_names":["niiightmarexd/windows-capture"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NiiightmareXD%2Fwindows-capture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NiiightmareXD%2Fwindows-capture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NiiightmareXD%2Fwindows-capture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NiiightmareXD%2Fwindows-capture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NiiightmareXD","download_url":"https://codeload.github.com/NiiightmareXD/windows-capture/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393094,"owners_count":20931804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game-capture","python","python-library","rust","rust-lang","screen-capture","screen-recorder","screenshot","screenshots","video-recording"],"created_at":"2024-08-01T15:01:32.229Z","updated_at":"2025-04-05T19:33:19.785Z","avatar_url":"https://github.com/NiiightmareXD.png","language":"Rust","funding_links":["BTC: bc1q9l3h8ld329skh9ajv5vz2hslfm3s2nv540yn8p","ETH: 0x3a9d72f341d03Eb8C5be9aC69A0236f71DD48192"],"categories":["Rust"],"sub_categories":[],"readme":"# Windows Capture \u0026emsp; [![Licence]][Licence URL] [![Build Status]][repository] [![Latest Version]][crates.io]\n\n[Licence]: https://img.shields.io/crates/l/windows-capture\n[Licence URL]: https://github.com/NiiightmareXD/windows-capture/blob/main/LICENCE\n[Build Status]: https://img.shields.io/github/actions/workflow/status/NiiightmareXD/windows-capture/rust.yml\n[repository]: https://github.com/NiiightmareXD/windows-capture\n[Latest Version]: https://img.shields.io/crates/v/windows-capture\n[crates.io]: https://crates.io/crates/windows-capture\n\n**Windows Capture** is a highly efficient Rust and Python library that enables you to capture the screen using the Graphics Capture API effortlessly. This library allows you to easily capture the screen of your Windows-based computer and use it for various purposes, such as creating instructional videos, taking screenshots, or recording your gameplay. With its intuitive interface and robust functionality, Windows Capture is an excellent choice for anyone looking for a reliable, easy-to-use screen-capturing solution.\n\n**Note** this README.md is for [Rust library](https://github.com/NiiightmareXD/windows-capture) Python library can be found [here](https://github.com/NiiightmareXD/windows-capture/tree/main/windows-capture-python)\n\n## Features\n\n- Only updates the frame when required.\n- High performance.\n- Easy to use.\n- Latest Screen Capturing API.\n\n## Installation\n\nAdd this dependency to your `Cargo.toml`:\n\n```toml\n[dependencies]\nwindows-capture = \"1.4.2\"\n```\n\nor run this command\n\n```\ncargo add windows-capture\n```\n\n## Usage\n\n```rust\nuse std::{\n    io::{self, Write},\n    time::Instant,\n};\n\nuse windows_capture::{\n    capture::{Context, GraphicsCaptureApiHandler},\n    encoder::{AudioSettingsBuilder, ContainerSettingsBuilder, VideoEncoder, VideoSettingsBuilder},\n    frame::Frame,\n    graphics_capture_api::InternalCaptureControl,\n    monitor::Monitor,\n    settings::{ColorFormat, CursorCaptureSettings, DrawBorderSettings, Settings},\n};\n\n// Handles capture events.\nstruct Capture {\n    // The video encoder that will be used to encode the frames.\n    encoder: Option\u003cVideoEncoder\u003e,\n    // To measure the time the capture has been running\n    start: Instant,\n}\n\nimpl GraphicsCaptureApiHandler for Capture {\n    // The type of flags used to get the values from the settings.\n    type Flags = String;\n\n    // The type of error that can be returned from `CaptureControl` and `start` functions.\n    type Error = Box\u003cdyn std::error::Error + Send + Sync\u003e;\n\n    // Function that will be called to create a new instance. The flags can be passed from settings.\n    fn new(ctx: Context\u003cSelf::Flags\u003e) -\u003e Result\u003cSelf, Self::Error\u003e {\n        println!(\"Created with Flags: {}\", ctx.flags);\n\n        let encoder = VideoEncoder::new(\n            VideoSettingsBuilder::new(1920, 1080),\n            AudioSettingsBuilder::default().disabled(true),\n            ContainerSettingsBuilder::default(),\n            \"video.mp4\",\n        )?;\n\n        Ok(Self {\n            encoder: Some(encoder),\n            start: Instant::now(),\n        })\n    }\n\n    // Called every time a new frame is available.\n    fn on_frame_arrived(\n        \u0026mut self,\n        frame: \u0026mut Frame,\n        capture_control: InternalCaptureControl,\n    ) -\u003e Result\u003c(), Self::Error\u003e {\n        print!(\n            \"\\rRecording for: {} seconds\",\n            self.start.elapsed().as_secs()\n        );\n        io::stdout().flush()?;\n\n        // Send the frame to the video encoder\n        self.encoder.as_mut().unwrap().send_frame(frame)?;\n\n        // Note: The frame has other uses too, for example, you can save a single frame to a file, like this:\n        // frame.save_as_image(\"frame.png\", ImageFormat::Png)?;\n        // Or get the raw data like this so you have full control:\n        // let data = frame.buffer()?;\n\n        // Stop the capture after 6 seconds\n        if self.start.elapsed().as_secs() \u003e= 6 {\n            // Finish the encoder and save the video.\n            self.encoder.take().unwrap().finish()?;\n\n            capture_control.stop();\n\n            // Because there wasn't any new lines in previous prints\n            println!();\n        }\n\n        Ok(())\n    }\n\n    // Optional handler called when the capture item (usually a window) closes.\n    fn on_closed(\u0026mut self) -\u003e Result\u003c(), Self::Error\u003e {\n        println!(\"Capture session ended\");\n\n        Ok(())\n    }\n}\n\nfn main() {\n    // Gets the foreground window, refer to the docs for other capture items\n    let primary_monitor = Monitor::primary().expect(\"There is no primary monitor\");\n\n    let settings = Settings::new(\n        // Item to capture\n        primary_monitor,\n        // Capture cursor settings\n        CursorCaptureSettings::Default,\n        // Draw border settings\n        DrawBorderSettings::Default,\n        // The desired color format for the captured frame.\n        ColorFormat::Rgba8,\n        // Additional flags for the capture settings that will be passed to user defined `new` function.\n        \"Yea this works\".to_string(),\n    );\n\n    // Starts the capture and takes control of the current thread.\n    // The errors from handler trait will end up here\n    Capture::start(settings).expect(\"Screen capture failed\");\n}\n```\n\n## Documentation\n\nDetailed documentation for each API and type can be found [here](https://docs.rs/windows-capture).\n\n## Contributing\n\nContributions are welcome! If you find a bug or want to add new features to the library, please open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNiiightmareXD%2Fwindows-capture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNiiightmareXD%2Fwindows-capture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNiiightmareXD%2Fwindows-capture/lists"}