Comments (2)
I figured out how to do it using some projects I found
https://github.com/P1n3appl3/obs-livesplit/blob/main/src/lib.rs
https://github.com/P1n3appl3/obs-gamepad/blob/main/src/lib.rs
https://github.com/agrif/ds1054z-source/blob/master/src/source.rs
https://github.com/chengyuhui/obs-subtitle/blob/master/src/lib.rs
But, It appears NvFBC was deprecated for Windows 10, though it still works it is outdated, and the nvfbc rust bindgen library only targets Linux which is still supported. Feel free to use this on Linux.
use nvfbc::{system::CaptureMethod, BufferFormat, SystemCapturer};
use obs_wrapper::{
graphics::{GraphicsColorFormat, GraphicsTexture},
obs_register_module,
obs_string,
prelude::*,
source::{
GetNameSource,
SourceContext,
SourceType,
Sourceable,
VideoRenderSource,
VideoTickSource,
},
};
struct NvidiaFrameBufferCaptureSource {
source: SourceContext,
texture: GraphicsTexture,
capturer: SystemCapturer,
}
struct NvidiaFrameBufferCaptureModule {
context: ModuleContext,
}
impl Sourceable for NvidiaFrameBufferCaptureSource {
fn get_id() -> ObsString {
obs_string!("nvfbc")
}
fn get_type() -> SourceType {
SourceType::INPUT
}
fn create(_create: &mut CreatableSourceContext<Self>, source: SourceContext) -> Self {
let mut capturer = SystemCapturer::new().expect("Failed to create SystemCapturer");
capturer
.start(BufferFormat::Rgb, 30)
.expect("Failed to start SystemCapturer");
let frame_info = capturer
.next_frame(CaptureMethod::Blocking)
.expect("Failed to get SystemFrameInfo");
let texture = GraphicsTexture::new(
frame_info.width,
frame_info.height,
GraphicsColorFormat::RGBA,
);
Self {
source,
texture,
capturer,
}
}
}
impl GetNameSource for NvidiaFrameBufferCaptureSource {
fn get_name() -> ObsString {
obs_string!("NvFBC")
}
}
impl VideoRenderSource for NvidiaFrameBufferCaptureSource {
fn video_render(&mut self, _context: &mut GlobalContext, _render: &mut VideoRenderContext) {
let frame_info = self
.capturer
.next_frame(CaptureMethod::Blocking)
.expect("Failed to get SystemFrameInfo");
self.texture
.set_image(frame_info.buffer, frame_info.width * 4, false);
self.texture.draw(0, 0, 2560, 1440, false);
}
}
impl Module for NvidiaFrameBufferCaptureModule {
fn new(context: ModuleContext) -> Self {
Self { context }
}
fn get_ctx(&self) -> &ModuleContext {
&self.context
}
fn load(&mut self, load_context: &mut LoadContext) -> bool {
let source = load_context
.create_source_builder::<NvidiaFrameBufferCaptureSource>()
.enable_get_name()
.enable_video_render()
.build();
load_context.register_source(source);
true
}
fn description() -> ObsString {
obs_string!(env!("CARGO_PKG_DESCRIPTION"))
}
fn name() -> ObsString {
obs_string!(env!("CARGO_PKG_NAME"))
}
fn author() -> ObsString {
obs_string!(env!("CARGO_PKG_AUTHORS"))
}
}
obs_register_module!(NvidiaFrameBufferCaptureModule);
from rust-obs-plugins.
Thanks @ShayBox!
from rust-obs-plugins.
Related Issues (15)
- Plugin doesn't appear in list HOT 4
- [Discussion] Design of hotkey API? HOT 2
- Catch unwinds in native callbacks
- Does not compile on 64-bit Windows HOT 5
- Can't seem to use multiple log levels in the same plugin HOT 1
- Is there plan to add Output/Encoder/Service? HOT 1
- How can I access current module from the source? HOT 1
- Fails to build Rust OBS Wrapper
- The docs build seems to have failed since 0.1.6 HOT 1
- Question on the newly added set_default API HOT 3
- Compile issues with example plugins on Win64 HOT 6
- Adding a source to a scene
- Doesn't compile on Debian HOT 1
- STATUS_DLL_NOT_FOUND HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-obs-plugins.