Code Monkey home page Code Monkey logo

obs-rs's Introduction

obs-rs

Capture frames of any game using OBS.

Features

This projects uses the graphics-hook implementation from the obs-studio project, to capture frames of any game.

  • The graphics hook is signed and whitelisted by all anti-cheats as it's used by streamers and content creators as well.
  • Works for many graphics APIs (D3D9, D3D10, D3D11, Vulkan, ...) and thus also for many different games.
  • This implementation is extremely fast, because it only copies the pixels from the framebuffer. On my machine, this crate is almost 5 times faster compared to an implementation using BitBlt.

Example

use obs_client::Capture;

fn main() {
    simple_logger::SimpleLogger::new()
        .with_level(log::LevelFilter::Warn)
        .init()
        .unwrap();

    let mut capture = Capture::new("Rainbow Six");
    if capture.try_launch().is_err() {
        println!("Failed to launch the capture");
        return;
    }

    loop {
        let _ = capture.capture_frame::<u8>();
        std::thread::sleep(std::time::Duration::from_secs(5));
    }
}

obs-rs's People

Contributors

not-matthias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

obs-rs's Issues

C# wrapper or c# calling example?

Hello, I love your work. But I wouldn't use rust. I see that your repository has a C# project, can you make a C# wrapper, or c# call this library example.

Failed to createmapping(2)

I'm running this in my c++ Application however for some reason every time I launch the application I'm running into this error

"Failed to CreateMapping(2)"

I have no idea what the issue could be, I ran this in administrator mode, I've also ensured that the capture window is correct. So I have no idea what's going on.

Failed to open file mapping

I run code from example and have this error:
2024-01-31 15:35:27,236 WARN [obs_client::utils::file_mapping] Failed to open file mapping ("CaptureHook_HookInfo16452").
Failed to launch the capture

Anyone know what I did wrong?

I'd be interested in pairing on model training if you're interested

I came across this looking for methods to do dx11 screen cap. I don't know anything about rust, and I don't know that I have the bandwidth for that now.

I use the desktop duplication api for now, and I'll switch to dx11 based on the linked obs repo, but the real time sink (one of them) is model training. Right now I use yolov5 serialized to a tensorrt engine. If you're also using yolov5 I would be interested in sharing models.

It takes a lot of time to even clip and annotate 1k images. I've got about 3k for d2 right now and a decent model. I'm trying to get that to 10k and I'd imagine you're in a similar boat for whatever you're targeting.

If you're interested in discussing, maybe we can hop on discord or something.

[obs_client::utils::pipe] GetOverlappedResult failed with error code: 109 ERROR_BROKEN_PIPE

I can run your code and it starts capturing frames, but as soon as I alt tab or lose focus of the captured window, i get the aforementioned error:

[obs_client::utils::pipe] GetOverlappedResult failed with error code: 109 ERROR_BROKEN_PIPE

I think whenever I alt tab, the IO is blocked and pipe line is broken? Any ideas how you would go about fixing this? I am only using your example code and added in some error output logs

ProcessNotFound everytime

use obs_client::Capture;

fn main() {
    simple_logger::SimpleLogger::new()
        .with_level(log::LevelFilter::Warn)
        .init()
        .unwrap();

    let window_name = "VALORANT";
    let mut capture = Capture::new(window_name);
    if let Err(error) = capture.try_launch() {
        println!("Failed to launch the capture: {:?} {:?}", window_name,error);
        return;
    }

    let mut fps = fps_counter::FPSCounter::new();
    loop {
        let (buffer, (width, height)) = capture.capture_frame::<u8>().unwrap();
        println!("{:?} | {:?}x{:?} | {:?}", fps.tick(), width, height, buffer.len());
    }
}

OpenSharedResource failed

OpenSharedResource创建失败,我debug obs对比发现,obs获取到的IDXGIAdapter是我的gpu,但是你通过 D3D11CreateDevice(NULL,...)创建的,好像IDXGIAdapter是cpu的集显,导致OpenSharedResource失败。

`capture_free` not handled

When you use Fullscreen, the capture will be reset everytime you tab out of the game. In the logs you can even see that it creates the vulkan capture freed when you minimize the game.

15:20:04.172: load_graphics_offsets: Failed to start 'get-graphics-offsets32.exe'
15:20:15.999: User added source 'Game Capture' (game_capture) to scene 'Scene'
15:20:24.664: [game-capture: 'Game Capture'] attempting to hook process: RainbowSix_Vulkan.exe
15:21:47.174: [game-capture: 'Game Capture'] vk_shtex_init_d3d11_tex: OBS requesting VK_FORMAT_B8G8R8A8_UNORM texture format.  capture dimensions: 2560x1080
15:21:47.178: [game-capture: 'Game Capture'] vulkan shared texture capture successful
15:21:47.186: [game-capture: 'Game Capture'] shared texture capture successful
15:21:49.060: [game-capture: 'Game Capture'] ------------------ vulkan capture freed ------------------
15:21:49.156: [game-capture: 'Game Capture'] vk_shtex_init_d3d11_tex: OBS requesting VK_FORMAT_B8G8R8A8_UNORM texture format.  capture dimensions: 2560x1080
15:21:49.161: [game-capture: 'Game Capture'] vulkan shared texture capture successful
15:21:49.186: [game-capture: 'Game Capture'] shared texture capture successful
15:21:50.660: [game-capture: 'Game Capture'] ------------------ vulkan capture freed ------------------
15:21:50.710: [game-capture: 'Game Capture'] vk_shtex_init_d3d11_tex: OBS requesting VK_FORMAT_B8G8R8A8_UNORM texture format.  capture dimensions: 2560x1080
15:21:50.714: [game-capture: 'Game Capture'] vulkan shared texture capture successful
15:21:50.722: [game-capture: 'Game Capture'] shared texture capture successful
15:21:51.102: [game-capture: 'Game Capture'] ------------------ vulkan capture freed ------------------
15:21:51.169: [game-capture: 'Game Capture'] vk_shtex_init_d3d11_tex: OBS requesting VK_FORMAT_B8G8R8A8_UNORM texture format.  capture dimensions: 2560x1080
15:21:51.181: [game-capture: 'Game Capture'] vulkan shared texture capture successful
15:21:51.186: [game-capture: 'Game Capture'] shared texture capture successful
15:22:16.018: [game-capture: 'Game Capture'] ------------------ vulkan capture freed ------------------
15:22:16.076: [game-capture: 'Game Capture'] vk_shtex_init_d3d11_tex: OBS requesting VK_FORMAT_B8G8R8A8_UNORM texture format.  capture dimensions: 2560x1080
15:22:16.078: [game-capture: 'Game Capture'] vulkan shared texture capture successful
15:22:16.086: [game-capture: 'Game Capture'] shared texture capture successful
15:22:17.038: [game-capture: 'Game Capture'] ------------------ vulkan capture freed ------------------
15:22:17.118: [game-capture: 'Game Capture'] vk_shtex_init_d3d11_tex: OBS requesting VK_FORMAT_B8G8R8A8_UNORM texture format.  capture dimensions: 2560x1080
15:22:17.123: [game-capture: 'Game Capture'] vulkan shared texture capture successful
15:22:17.153: [game-capture: 'Game Capture'] shared texture capture successful

See: https://github.com/obsproject/obs-studio/blob/f8aa02897fc3c06eed62a1cecf8e2258be1f7cdd/plugins/win-capture/graphics-hook/vulkan-capture.c#L405

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.