Skip to main content

Crate libobs_wrapper

Crate libobs_wrapper 

Source
Expand description

Safe, runtime-affine Rust access to the libobs object model.

§Start here

crate::context::ObsContext is the root managed handle. Most applications create it through crate::utils::StartupInfo, then use only the modules needed for their workflow.

What you needModule
Discover installed sources/encoders/outputs/servicescrate::capabilities
Configure arbitrary plugins from runtime metadatacrate::settings
Sources and filterscrate::sources
Scenes, groups, native order and transform snapshotscrate::scenes
Audio/video encoderscrate::encoders
Streaming servicescrate::services
Validated output graphs and lifecyclecrate::data::output
Preview/display surfacescrate::display
OBS event subscriptionscrate::signals and per-object signals() methods
Raw FFI escape hatch[crate::sys]

If you only need a conventional recorder, RTMP stream, replay buffer, or common capture source, the libobs-simple crate is normally a better starting point. It uses this wrapper internally and can be mixed with wrapper calls on the same crate::context::ObsContext.

§Plugin-generic workflow

Do not assume every machine has the same OBS plugins. The preferred generic path is:

  1. call crate::context::ObsContext::capabilities;
  2. choose by codec/protocol/capability, or use crate::capabilities::ObsCapabilities::best_output_plan;
  3. use descriptor settings_schema_for / settings_snapshot_for methods to configure plugin settings without hard-coded property models;
  4. create managed objects from the descriptors;
  5. use crate::data::output::ObsOutputPipelineBuilder for complete output graphs.

§Scene composition

crate::scenes::ObsSceneRef owns managed scene items and exposes libobs’s actual native order. crate::scenes::SceneItemTrait covers transform/state behavior, including crop, bounds, scale filters, blending, and restorable snapshots. crate::scenes::ObsSceneGroupRef represents native OBS groups rather than simulating groups in Rust.

One important libobs behavior is exposed explicitly: ungrouping creates replacement parent-scene items. crate::scenes::ObsSceneGroupRef::ungroup therefore returns replacement managed handles and marks the replaced child handles removed.

§Ownership and unsafe access

Managed objects retain native references through one OBS runtime. Clones share a lifetime lease, and operations validate runtime affinity before combining objects. Prefer opaque object IDs for identity. [crate::sys] is available when raw libobs functionality is genuinely needed, but raw pointers carry the usual libobs thread-affinity and reference-count responsibilities.

The repository’s docs/api_orientation.md contains a longer task-to-module guide and examples.

Re-exports§

pub use libobs as sys;

Modules§

capabilities
Runtime capability discovery and compatibility planning for the loaded OBS installation.
context
OBS Context Management
crash_handler
Contains a default crash handler that is attached by default to the ObsContext. By default this will handle crashes just by printing them out to console, if the dialog-crash-handler feature is disabled. If you want to implement your own crash handler, make sure that you do the least amount of work possible and access as few global variables as you can, as it is quite unstable if libobs has crashed.
data
This module contains every struct related to storing data in OBS. There are two important structs:
display
This module is used to create a OBS display which you can use to preview the output of your recording.
encoders
This module contains video- and audio-encoders. In simple terms, you need a video and audio encoder, so a proper mp4 file can get written to disk (with video and audio). If you are unsure which encoder to use, you might as well take a look at the libobs-simple crate for a output that has all needed encoders attached already.
enums
Contains all important enums for this crate
graphics
Holds a Vec2 vector, mainly used for positioning the ObsDisplay or ObsSceneItems.
logger
This module is used to provide a logger trait, which can be used to implement custom logging for the libobs console output.
runtime
Runtime management for serialized OBS access.
scenes
Scenes, managed scene items, native OBS groups, ordering, and transform state.
services
Typed OBS streaming-service handles.
settings
Generic, plugin-agnostic settings schemas built from OBS property metadata.
signals
Per-object OBS signal subscriptions.
sources
This module holds everything related to sources. A source renders specific content to the scene, which is then processed by the ObsOutputRef and for example written to a file using encoders.
utils

Macros§

impl_obs_drop
Implement a non-panicking native cleanup guard.
impl_signal_manager
Generate a signal manager whose subscription state is owned by that manager.
run_with_obs
Execute work on the OBS actor while preserving the runtime’s structured error.
run_with_obs_impl