### Install OBS Studio via Snap Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install OBS Studio using the snap package manager. Ensure snapd is installed first. ```bash sudo snap install obs-studio ``` -------------------------------- ### Example CMakeLists.txt for a Plugin Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/plugins.md A typical CMakeLists.txt file for building a native OBS Studio plugin module, linking against libobs and installing with data. ```cmake # my-plugin/CMakeLists.txt project(my-plugin) set(my-plugin_SOURCES my-plugin.c my-source.c my-output.c my-encoder.c my-service.c) add_library(my-plugin MODULE ${my-plugin_SOURCES}) target_link_libraries(my-plugin libobs) install_obs_plugin_with_data(my-plugin data) ``` -------------------------------- ### Install OBS Studio on Void Linux Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install OBS Studio on Void Linux. Dependencies will be installed automatically. If installation fails, try updating the system first with 'sudo xbps-install -Su'. ```bash sudo xbps-install obs ``` -------------------------------- ### Install OBS Studio on Solus Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install OBS Studio on Solus using the eopkg package manager. ```bash eopkg install obs-studio ``` -------------------------------- ### Install OBS Studio on openSUSE Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install the obs-studio package on openSUSE after configuring the Packman repository. ```bash sudo zypper in obs-studio ``` -------------------------------- ### Install OBS Studio using CMake Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Mac Install the OBS Studio application bundle to the specified installation prefix. This command is used after building the project from the command line. ```bash cmake --install build ``` -------------------------------- ### Install OBS Studio on NixOS Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Use this command to install OBS Studio on NixOS. ```bash nix-env -i obs-studio ``` -------------------------------- ### Build and Install OBS Studio Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Linux After configuring the build, use this command to compile and install OBS Studio. Replace `` with the actual build folder name, e.g., `build_ubuntu`. ```bash cmake --build && cmake --install ``` -------------------------------- ### Install OBS Studio on FreeBSD Source: https://github.com/obsproject/obs-studio/wiki/Install-Instructions Installs OBS Studio on FreeBSD using the pkg package manager. ```sh pkg install obs-studio ``` -------------------------------- ### Install OBS Studio on Debian Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install the OBS Studio package from the Debian repositories. ```bash sudo apt install obs-studio ``` -------------------------------- ### Start Profile Node Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-libobs-util-profiler.md Starts a new profile node. This node will be a child of the most recently started node. ```c void profile_start(const char *name); ``` -------------------------------- ### Install OBS Studio on OpenMandriva Lx3 Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install OBS Studio on OpenMandriva Lx3 using the urpmi package manager. ```bash urpmi obs-studio ``` -------------------------------- ### Install OBS Studio on OpenMandriva Lx4 Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install OBS Studio on OpenMandriva Lx4 using the dnfdragora package manager. ```bash dnf install obs-studio ``` -------------------------------- ### Install OBS Studio on Fedora Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install the main OBS Studio package using the DNF package manager on Fedora. ```bash sudo dnf install obs-studio ``` -------------------------------- ### Install OBS Studio to Custom Location Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-FreeBSD Installs the OBS Studio project to a custom installation path using CMake. This allows for flexible deployment outside the default prefix. ```bash cmake --install --prefix ``` -------------------------------- ### Start Profiler Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-libobs-util-profiler.md Starts the profiler. Ensure this is called before any profiling operations. ```c void profiler_start(void); ``` -------------------------------- ### Install v4l2loopback on Fedora Silverblue/Kinoite Source: https://github.com/obsproject/obs-studio/wiki/Install-Instructions Installs the kmod-v4l2loopback package for virtual camera support on Fedora Silverblue/Kinoite systems. ```bash rpm-ostree install kmod-v4l2loopback ``` -------------------------------- ### Install OBS Studio Plugins on Fedora Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install additional OBS Studio plugins for Browser, VLC, vkcapture, and WebKitGTK support on Fedora. ```bash sudo dnf install obs-studio-plugin-vlc-video obs-studio-plugin-vkcapture obs-studio-plugin-webkitgtk ``` -------------------------------- ### Install OBS Studio Dependencies on openSUSE Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Linux Installs necessary development libraries and tools for building OBS Studio on openSUSE using the zypper package manager. ```bash sudo zypper in cmake \ fontconfig-devel \ freetype2-devel \ gcc \ gcc-c++ \ libcurl-devel \ ffmpeg2-devel \ libjansson-devel \ libpulse-devel \ libspeexdsp-devel \ libudev-devel \ libv4l-devel \ libXcomposite-devel \ libXinerama-devel \ libXrandr-devel \ luajit-devel \ mbedtls \ qt6-qtbase-dev \ qt6-qtbase-private-dev \ swig \ python3-devel \ libxss-dev ``` -------------------------------- ### Install OBS Studio on Gentoo via Portage Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install the OBS Studio package on Gentoo Linux using the Portage package manager. ```bash sudo emerge media-video/obs-studio ``` -------------------------------- ### Install v4l2loopback on Debian/Ubuntu Source: https://github.com/obsproject/obs-studio/wiki/Install-Instructions Installs the v4l2loopback-dkms package for virtual camera support on Debian/Ubuntu-based systems. ```bash sudo apt install v4l2loopback-dkms ``` -------------------------------- ### Install FFmpeg on Debian Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Install the FFmpeg package, which is a prerequisite for OBS Studio, on Debian systems. ```bash sudo apt install ffmpeg ``` -------------------------------- ### Install Fedora OBS Dependencies Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Linux Installs core OBS Studio build dependencies on Fedora systems using dnf. ```bash sudo dnf install \ alsa-lib-devel \ asio-devel \ cmake extra-cmake-modules \ extra-cmake-modules \ ffmpeg-free-devel \ fontconfig-devel \ freetype-devel \ gcc \ gcc-c++ \ gcc-objc \ git \ glib2-devel \ jansson-devel \ json-devel \ libavcodec-free-devel \ libavdevice-free-devel \ librist-devel \ libcurl-devel \ libdatachannel-devel \ libdrm-devel \ libglvnd-devel \ libqrcodegencpp-devel \ libuuid-devel \ libva-devel \ libv4l-devel \ libvpl-devel \ libX11-devel \ libXcomposite-devel \ libXdamage \ libXinerama-devel \ libxkbcommon-devel \ luajit-devel \ make \ mbedtls-devel \ ninja \ nv-codec-headers \ pciutils-devel \ pipewire-devel \ pulseaudio-libs-devel \ python3-devel \ qt6-qtbase-devel \ qt6-qtbase-private-devel \ qt6-qtsvg-devel \ qt6-qtwayland-devel \ rnnoise-devel \ simde-devel \ speexdsp-devel \ srt-devel \ swig \ systemd-devel \ uthash-devel \ vlc-devel \ wayland-devel \ websocketpp-devel \ x264-devel ``` -------------------------------- ### Install OBS Studio on Ubuntu Source: https://github.com/obsproject/obs-studio/wiki/Install-Instructions Installs OBS Studio on Ubuntu 18.04 or later by adding the official OBS PPA and updating package lists. ```bash sudo add-apt-repository ppa:obsproject/obs-studio sudo apt update sudo apt install obs-studio ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/obsproject/obs-studio/wiki/MacOS-Virtual-Camera-Compatibility-Guide-(Legacy) Run this command in the Terminal to install necessary command-line tools for code signing operations. ```bash xcode-select --install ``` -------------------------------- ### Install qt6-wayland prerequisite on Arch Linux/Manjaro Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds If using OBS Studio on Wayland with Arch-based distributions, install this prerequisite to avoid crashes and ensure functionality. ```bash sudo pacman -S qt6-wayland ``` -------------------------------- ### Install Debian Build System Dependencies Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Linux Installs essential build tools and libraries for OBS Studio on Debian-based systems. ```bash sudo apt install cmake extra-cmake-modules ninja-build pkg-config clang clang-format build-essential curl ccache git zsh ``` -------------------------------- ### obs_frontend_start_virtualcam Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-frontend-api.md Starts the virtual camera. ```APIDOC ## obs_frontend_start_virtualcam ### Description Starts the virtual camera. ### Method void ### Endpoint obs_frontend_start_virtualcam() ``` -------------------------------- ### Install OBS Studio Project Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-FreeBSD Installs the OBS Studio project to the prefix specified during CMake configuration. This command copies the built files to their designated locations. ```bash cmake --install ``` -------------------------------- ### Install OBS Studio on Arch Linux/Manjaro via Pacman Source: https://github.com/obsproject/obs-studio/wiki/Unofficial-Linux-Builds Use this command to install the OBS Studio package from the official Arch Linux/Manjaro repositories. ```bash sudo pacman -S obs-studio ``` -------------------------------- ### Configure and Start OBS Output Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/frontends.md Use this code to set video and audio encoders for an output, attach a service if streaming, and then start the output. Ensure encoders and services are properly initialized before use. ```cpp obs_encoder_set_video(my_h264_encoder, obs_get_video()); obs_encoder_set_audio(my_aac_encoder, obs_get_audio()); obs_output_set_video_encoder(my_output, my_h264_encoder); obs_output_set_audio_encoder(my_output, my_aac_encoder); obs_output_set_service(my_output, my_service); /* if a stream */ obs_output_start(my_output); ``` -------------------------------- ### Install Red Hat OBS Dependencies Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Linux Installs core OBS Studio build dependencies on Red Hat-based systems using yum. ```bash sudo yum install \ alsa-lib-devel \ asio-devel \ cmake extra-cmake-modules \ ffmpeg-free-devel \ fontconfig-devel \ freetype-devel \ gcc \ gcc-c++ \ gcc-objc \ git \ glib2-devel \ json-devel \ libavcodec-free-devel \ libavdevice-free-devel \ libcurl-devel \ libdrm-devel \ libglvnd-devel \ jansson-devel \ libuuid-devel \ libva-devel \ libv4l-devel \ libX11-devel \ libXcomposite-devel \ libXinerama-devel \ luajit-devel \ make \ mbedtls-devel \ pciutils-devel \ pipewire-devel \ pulseaudio-libs-devel \ python3-devel \ qt6-qtbase-devel \ qt6-qtbase-private-devel \ qt6-qtsvg-devel \ qt6-qtwayland-devel \ speexdsp-devel \ swig \ systemd-devel \ vlc-devel \ wayland-devel \ websocketpp-devel \ x264-devel ``` -------------------------------- ### Install Build System Dependencies on FreeBSD Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-FreeBSD Installs essential build system tools and libraries required for compiling OBS Studio on FreeBSD using the pkg package manager. ```bash sudo pkg install cmake ninja binutils pkgconf curl ccache kf6-extra-cmake-modules ``` -------------------------------- ### Install OBS UI Dependencies on FreeBSD Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-FreeBSD Installs the Qt framework and related modules necessary for the OBS Studio graphical user interface on FreeBSD using the pkg package manager. ```bash sudo pkg install qt6-base qt6-imageformats qt6-svg ``` -------------------------------- ### Install OBS Virtual Camera Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Windows Run this batch script as administrator from the OBS Studio artifact directory to install the OBS Virtual Camera. This is typically located in `/rundir/`. ```batch data\obs-plugins\win-dshow\virtualcam-install.bat ``` -------------------------------- ### Install v4l2loopback on Red Hat/Fedora Source: https://github.com/obsproject/obs-studio/wiki/Install-Instructions Installs the kmod-v4l2loopback package for virtual camera support on Red Hat/Fedora-based systems. Requires RPM Fusion to be enabled. ```bash sudo dnf install kmod-v4l2loopback ``` -------------------------------- ### Start CPU Usage Monitoring Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-libobs-util-platform.md Initializes and starts monitoring CPU usage. Returns a handle to a CPU usage information object that should be used with query and destroy functions. ```cpp os_cpu_usage_info_t *os_cpu_usage_info_start(void) ``` -------------------------------- ### Install OBS Core Dependencies on FreeBSD Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-FreeBSD Installs the core runtime dependencies for OBS Studio on FreeBSD, including multimedia and system libraries, using the pkg package manager. ```bash sudo pkg install ffmpeg libx264 mbedtls mesa-libs jansson lua52 luajit python37 libX11 xorgproto libxcb libXcomposite libXext libXfixes libXinerama libXrandr swig dbus jansson libICE libSM libsysinfo ``` -------------------------------- ### Get Direct Data Pointer Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-libobs-util-deque.md Gets a direct pointer to the data at a specific positional index within the deque, relative to the starting point. Use with caution to avoid corrupting deque integrity. ```c void *deque_data(struct deque *dq, size_t idx) ``` -------------------------------- ### Create and Manage OBS Studio Sources Source: https://context7.com/obsproject/obs-studio/llms.txt Demonstrates creating a video capture source, configuring its settings, adjusting volume, muting, updating properties, finding sources by name, and adding a color correction filter. Remember to release sources using obs_source_release when they are no longer needed. ```c #include void create_sources_example(void) { // Create settings for a video capture source obs_data_t *settings = obs_data_create(); obs_data_set_string(settings, "device", "video0"); obs_data_set_int(settings, "resolution", 1920); // Create a video capture source obs_source_t *camera = obs_source_create("v4l2_input", "Webcam", settings, NULL); obs_data_release(settings); if (!camera) { printf("Failed to create camera source\n"); return; } // Get source dimensions uint32_t width = obs_source_get_width(camera); uint32_t height = obs_source_get_height(camera); printf("Source dimensions: %ux%u\n", width, height); // Set source volume (0.0 to 1.0) obs_source_set_volume(camera, 0.8f); // Mute/unmute audio obs_source_set_muted(camera, false); // Update source settings dynamically obs_data_t *new_settings = obs_data_create(); obs_data_set_int(new_settings, "resolution", 1280); obs_source_update(camera, new_settings); obs_data_release(new_settings); // Get source by name (increments reference) obs_source_t *found_source = obs_get_source_by_name("Webcam"); if (found_source) { printf("Found source: %s\n", obs_source_get_name(found_source)); obs_source_release(found_source); } // Add a filter to the source obs_data_t *filter_settings = obs_data_create(); obs_data_set_double(filter_settings, "gamma", 1.2); obs_source_t *color_filter = obs_source_create("color_filter", "Color Correction", filter_settings, NULL); obs_data_release(filter_settings); if (color_filter) { obs_source_filter_add(camera, color_filter); obs_source_release(color_filter); } // Release the source when done obs_source_release(camera); } ``` -------------------------------- ### Configure FFmpeg Recording Output Source: https://context7.com/obsproject/obs-studio/llms.txt This example demonstrates setting up an FFmpeg output for recording video and audio to a file. It includes basic configuration for the output path and muxer settings. ```c void recording_output_example(obs_encoder_t *video_enc, obs_encoder_t *audio_enc) { // Create recording output settings obs_data_t *output_settings = obs_data_create(); obs_data_set_string(output_settings, "path", "/home/user/Videos/recording.mp4"); obs_data_set_string(output_settings, "muxer_settings", "movflags=faststart"); // Create FFmpeg output for recording obs_output_t *recording = obs_output_create( "ffmpeg_muxer", "Recording", output_settings, NULL); obs_data_release(output_settings); if (recording) { obs_output_set_video_encoder(recording, video_enc); obs_output_set_audio_encoder(recording, audio_enc, 0); if (obs_output_start(recording)) { printf("Recording started\n"); // Pause/resume recording if (obs_output_can_pause(recording)) { obs_output_pause(recording, true); // Pause obs_output_pause(recording, false); // Resume } } obs_output_stop(recording); obs_output_release(recording); } } ``` -------------------------------- ### Native Plugin Initialization Example Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/plugins.md Demonstrates the basic structure for a native OBS Studio plugin's initialization file (my-plugin.c), including module declaration, locale usage, and object registration. ```cpp /* my-plugin.c */ #include /* Defines common functions (required) */ OBS_DECLARE_MODULE() /* Implements common ini-based locale (optional) */ OBS_MODULE_USE_DEFAULT_LOCALE("my-plugin", "en-US") extern struct obs_source_info my_source; /* Defined in my-source.c */ extern struct obs_output_info my_output; /* Defined in my-output.c */ extern struct obs_encoder_info my_encoder; /* Defined in my-encoder.c */ extern struct obs_service_info my_service; /* Defined in my-service.c */ bool obs_module_load(void) { obs_register_source(&my_source); obs_register_output(&my_output); obs_register_encoder(&my_encoder); obs_register_service(&my_service); return true; } ``` -------------------------------- ### Create OBS Studio Installer Package Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-FreeBSD Generates an installer package for OBS Studio using CMake. This command handles the creation of compressed archives and shell scripts containing the binaries. ```bash cmake --package ``` -------------------------------- ### Install OBS Plugin Dependencies on FreeBSD Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-FreeBSD Installs optional plugin-specific dependencies for OBS Studio on FreeBSD, such as audio and video libraries, using the pkg package manager. ```bash sudo pkg install v4l_compat fdk-aac fontconfig freetype2 speexdsp libudev-devd libv4l vlc audio/jack pulseaudio sndio ``` -------------------------------- ### Open Module Example Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-modules.md Opens a plugin module from a specific path. This loads the module image but does not initialize it. Call obs_init_module() to initialize. ```c obs_module_t *module = NULL; int ret = obs_open_module(&module, "/path/to/plugin.dll", "/path/to/data"); if (ret == MODULE_SUCCESS) { // Module opened successfully } ``` -------------------------------- ### Install v4l2loopback on Arch Linux/Manjaro Source: https://github.com/obsproject/obs-studio/wiki/Install-Instructions Installs the v4l2loopback-dkms package for virtual camera support on Arch Linux-based and Manjaro systems. Ensure kernel headers are installed first. ```bash sudo pacman -S v4l2loopback-dkms ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/obsproject/obs-studio/wiki/MacOS-Virtual-Camera-Compatibility-Guide-(Legacy) This command installs the necessary Xcode command line tools, which are required for subsequent code signing operations. You will be prompted to enter your administrator password. ```bash Xcode-select --install ``` -------------------------------- ### OBS Frontend API Example Source: https://context7.com/obsproject/obs-studio/llms.txt Demonstrates various frontend API functions including scene management, streaming/recording controls, replay buffer, virtual camera, studio mode, and profile/scene collection access. Requires including 'obs-frontend-api.h'. ```c #include void frontend_api_example(void) { // Get current scene obs_source_t *current_scene = obs_frontend_get_current_scene(); if (current_scene) { printf("Current scene: %s\n", obs_source_get_name(current_scene)); obs_source_release(current_scene); } // Get all scenes struct obs_frontend_source_list scenes = {0}; obs_frontend_get_scenes(&scenes); for (size_t i = 0; i < scenes.sources.num; i++) { printf("Scene: %s\n", obs_source_get_name(scenes.sources.array[i])); } obs_frontend_source_list_free(&scenes); // Set current scene by name obs_source_t *target_scene = obs_get_source_by_name("Game Scene"); if (target_scene) { obs_frontend_set_current_scene(target_scene); obs_source_release(target_scene); } // Streaming controls if (!obs_frontend_streaming_active()) { obs_frontend_streaming_start(); } // Recording controls if (!obs_frontend_recording_active()) { obs_frontend_recording_start(); } // Pause/resume recording if (obs_frontend_recording_active()) { obs_frontend_recording_pause(true); // Pause obs_frontend_recording_pause(false); // Resume } // Stop streaming and recording obs_frontend_streaming_stop(); obs_frontend_recording_stop(); // Replay buffer obs_frontend_replay_buffer_start(); obs_frontend_replay_buffer_save(); obs_frontend_replay_buffer_stop(); // Virtual camera obs_frontend_start_virtualcam(); if (obs_frontend_virtualcam_active()) { obs_frontend_stop_virtualcam(); } // Studio mode obs_frontend_set_preview_program_mode(true); obs_source_t *preview = obs_frontend_get_current_preview_scene(); if (preview) { printf("Preview scene: %s\n", obs_source_get_name(preview)); obs_source_release(preview); } obs_frontend_preview_program_trigger_transition(); // Take screenshot obs_frontend_take_screenshot(); // Get profile and scene collection info char *profile = obs_frontend_get_current_profile(); char *collection = obs_frontend_get_current_scene_collection(); printf("Profile: %s, Collection: %s\n", profile, collection); bfree(profile); bfree(collection); // Save current configuration obs_frontend_save(); } ``` -------------------------------- ### Example Plugin Directory Structure Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/plugins.md Illustrates a common file and directory layout for a native OBS Studio plugin module. ```default my-plugin/data/locale/en-US.ini my-plugin/CMakeLists.txt my-plugin/my-plugin.c my-plugin/my-source.c my-plugin/my-output.c my-plugin/my-encoder.c my-plugin/my-service.c ``` -------------------------------- ### Custom Source Plugin Example in C Source: https://context7.com/obsproject/obs-studio/llms.txt Implement a custom video source plugin for OBS Studio. This example demonstrates the structure for registering a source, defining its properties, handling settings, and custom rendering. Ensure all required OBS module functions are implemented. ```c // my_plugin.c #include OBS_DECLARE_MODULE() OBS_MODULE_USE_DEFAULT_LOCALE("my_plugin", "en-US") // Source plugin definition static const char *my_source_get_name(void *type_data) { return "My Custom Source"; } static void *my_source_create(obs_data_t *settings, obs_source_t *source) { struct my_source_data *data = bzalloc(sizeof(struct my_source_data)); data->source = source; // Initialize with settings const char *text = obs_data_get_string(settings, "text"); data->text = bstrdup(text); return data; } static void my_source_destroy(void *data) { struct my_source_data *source_data = data; bfree(source_data->text); bfree(source_data); } static void my_source_update(void *data, obs_data_t *settings) { struct my_source_data *source_data = data; bfree(source_data->text); source_data->text = bstrdup(obs_data_get_string(settings, "text")); } static uint32_t my_source_get_width(void *data) { return 640; } static uint32_t my_source_get_height(void *data) { return 480; } static void my_source_render(void *data, gs_effect_t *effect) { struct my_source_data *source_data = data; // Custom rendering using graphics API gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID); gs_technique_t *tech = gs_effect_get_technique(solid, "Solid"); gs_technique_begin(tech); gs_technique_begin_pass(tech, 0); gs_draw_sprite(NULL, 0, 640, 480); gs_technique_end_pass(tech); gs_technique_end(tech); } static void my_source_defaults(obs_data_t *settings) { obs_data_set_default_string(settings, "text", "Hello OBS!"); obs_data_set_default_int(settings, "color", 0xFFFFFFFF); } static obs_properties_t *my_source_properties(void *data) { obs_properties_t *props = obs_properties_create(); obs_properties_add_text(props, "text", "Display Text", OBS_TEXT_DEFAULT); obs_properties_add_color(props, "color", "Text Color"); obs_properties_add_int_slider(props, "opacity", "Opacity", 0, 100, 1); return props; } static struct obs_source_info my_source_info = { .id = "my_custom_source", .type = OBS_SOURCE_TYPE_INPUT, .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW, .get_name = my_source_get_name, .create = my_source_create, .destroy = my_source_destroy, .update = my_source_update, .get_width = my_source_get_width, .get_height = my_source_get_height, .video_render = my_source_render, .get_defaults = my_source_defaults, .get_properties = my_source_properties, .icon_type = OBS_ICON_TYPE_CUSTOM, }; // Module entry point bool obs_module_load(void) { obs_register_source(&my_source_info); return true; } void obs_module_unload(void) { // Cleanup resources } const char *obs_module_name(void) { return "My Custom Plugin"; } const char *obs_module_description(void) { return "A custom OBS plugin example"; } ``` -------------------------------- ### Mutex Usage Example Source: https://github.com/obsproject/obs-studio/blob/master/deps/w32-pthreads/manual/pthread_mutex_init.html An example demonstrating how to protect a shared variable using a mutex. ```APIDOC ## Example Protecting a shared global variable `x` with a mutex: ```c int x; pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; // Access and modifications to x should be bracketed by lock and unlock calls: pthread_mutex_lock(&mut); /* operate on x */ pthread_mutex_unlock(&mut); ``` ``` -------------------------------- ### Initialize Module Example Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-modules.md Initializes a previously opened module by calling its obs_module_load export. Returns true if the module was loaded successfully. ```c obs_module_t *module; if (obs_open_module(&module, "/path/to/plugin.dll", NULL) == MODULE_SUCCESS) { if (obs_init_module(module)) { // Module initialized successfully } } ``` -------------------------------- ### Create and Manage Scenes with OBS Studio API Source: https://context7.com/obsproject/obs-studio/llms.txt Demonstrates creating a scene, adding image sources, transforming items (position, scale, rotation, crop, bounds), setting visibility and lock status, organizing items into groups, enumerating scene items, and setting a scene as the output source. Ensure to release resources like scenes and sources when no longer needed. ```c #include void scene_management_example(void) { // Create a new scene obs_scene_t *scene = obs_scene_create("Main Scene"); if (!scene) { printf("Failed to create scene\n"); return; } // Get the scene's source (for setting as output) obs_source_t *scene_source = obs_scene_get_source(scene); // Create a source to add to the scene obs_data_t *settings = obs_data_create(); obs_data_set_string(settings, "file", "/path/to/image.png"); obs_source_t *image_source = obs_source_create("image_source", "Background", settings, NULL); obs_data_release(settings); // Add source to scene obs_sceneitem_t *item = obs_scene_add(scene, image_source); obs_source_release(image_source); // Scene holds the reference if (item) { // Set position struct vec2 pos = {100.0f, 50.0f}; obs_sceneitem_set_pos(item, &pos); // Set scale struct vec2 scale = {0.5f, 0.5f}; obs_sceneitem_set_scale(item, &scale); // Set rotation (degrees) obs_sceneitem_set_rot(item, 15.0f); // Set crop struct obs_sceneitem_crop crop = {10, 10, 10, 10}; obs_sceneitem_set_crop(item, &crop); // Set bounds for automatic scaling obs_sceneitem_set_bounds_type(item, OBS_BOUNDS_SCALE_INNER); struct vec2 bounds = {1920.0f, 1080.0f}; obs_sceneitem_set_bounds(item, &bounds); // Set visibility obs_sceneitem_set_visible(item, true); // Lock item to prevent accidental changes obs_sceneitem_set_locked(item, true); // Set item order obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP); } // Create a group within the scene obs_sceneitem_t *group = obs_scene_add_group(scene, "Overlay Group"); // Enumerate all items in scene obs_scene_enum_items(scene, [](obs_scene_t *scene, obs_sceneitem_t *item, void *param) -> bool { obs_source_t *source = obs_sceneitem_get_source(item); printf("Scene item: %s\n", obs_source_get_name(source)); return true; // Continue enumeration }, NULL); // Set scene as main output on channel 0 obs_set_output_source(0, scene_source); // Release scene when done obs_scene_release(scene); } ``` -------------------------------- ### Example Usage of pthread_key_create Source: https://github.com/obsproject/obs-studio/blob/master/deps/w32-pthreads/manual/pthread_key_create.html This example demonstrates how to use pthread_key_create to allocate and manage a thread-specific buffer. ```APIDOC ## Example The following code fragment allocates a thread-specific array of 100 characters, with automatic reclamation at thread exit: ```c /* Key for the thread-specific buffer */ static pthread_key_t buffer_key; /* Once-only initialisation of the key */ static pthread_once_t buffer_key_once = PTHREAD_ONCE_INIT; /* Allocate the thread-specific buffer */ void buffer_alloc(void) { pthread_once(&buffer_key_once, buffer_key_alloc); pthread_setspecific(buffer_key, malloc(100)); } /* Return the thread-specific buffer */ char * get_buffer(void) { return (char *) pthread_getspecific(buffer_key); } /* Allocate the key */ static void buffer_key_alloc(void) { pthread_key_create(&buffer_key, buffer_destroy); } /* Free the thread-specific buffer */ static void buffer_destroy(void * buf) { free(buf); } ``` ``` -------------------------------- ### Begin Technique Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-libobs-graphics-effects.md Starts a rendering technique. This function must be called before beginning any passes within the technique. It returns the number of passes available in the technique. ```cpp size_t num_passes = gs_technique_begin(technique); ``` -------------------------------- ### Initialize and Shutdown OBS Studio Core Source: https://context7.com/obsproject/obs-studio/llms.txt Initializes the OBS Studio core library, configures video and audio subsystems, loads modules, and performs cleanup. Ensure obs_startup is called before other OBS functions and obs_shutdown is called upon application exit. ```c #include int main(int argc, char *argv[]) { // Initialize OBS context if (!obs_startup("en-US", NULL, NULL)) { printf("Failed to initialize OBS\n"); return 1; } // Configure video settings struct obs_video_info ovi = { .graphics_module = "libobs-opengl", // or "libobs-d3d11" on Windows .fps_num = 30, .fps_den = 1, .base_width = 1920, .base_height = 1080, .output_width = 1920, .output_height = 1080, .output_format = VIDEO_FORMAT_NV12, .adapter = 0, .gpu_conversion = true, .colorspace = VIDEO_CS_709, .range = VIDEO_RANGE_PARTIAL, .scale_type = OBS_SCALE_BICUBIC, }; int result = obs_reset_video(&ovi); if (result != OBS_VIDEO_SUCCESS) { printf("Failed to initialize video: %d\n", result); obs_shutdown(); return 1; } // Configure audio settings struct obs_audio_info oai = { .samples_per_sec = 48000, .speakers = SPEAKERS_STEREO, }; if (!obs_reset_audio(&oai)) { printf("Failed to initialize audio\n"); obs_shutdown(); return 1; } // Load all modules (plugins) from default paths obs_load_all_modules(); obs_post_load_modules(); // ... application logic ... // Cleanup obs_shutdown(); return 0; } ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/obsproject/obs-studio/wiki/Private-Stream-Hosting Installs essential packages required for compiling Nginx and its modules on Debian-based systems. ```bash apt-get install build-essential libpcre3 libpcre3-dev libssl-dev ``` -------------------------------- ### OBS Studio Base Theme Example (.obt) Source: https://github.com/obsproject/obs-studio/wiki/OBS-Studio-Theme-System Defines the base theme metadata, variables, and default styles for QWidgets. Use this for the main theme definition. ```css @OBSThemeMeta { name: "Simple"; id: "simple_theme"; } @OBSThemeVars { –-main_color: "red"; } QWidget { color: var(--main_color); } ``` -------------------------------- ### Get Weak Source Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-core-objects.md Gets a weak reference to a source. Weak references do not prevent the source from being destroyed. ```APIDOC ## obs_source_get_weak_source() ### Description Gets a weak reference to a source. ### Function Signature `obs_weak_source_t *obs_source_get_weak_source(obs_source_t *source)` ### Parameters * **source** (`obs_source_t *`) - Required - The source object. ### Returns * `obs_weak_source_t *` - A weak reference to the source. ``` -------------------------------- ### Basic Serializer Get Position Function Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-libobs-util-serializers.md Gets the current position within the serializer's data. ```cpp int64_t serializer_get_pos(struct serializer *s) ``` -------------------------------- ### obs_frontend_recording_start Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-frontend-api.md Begins the recording process. Use this function to start capturing video and audio. ```APIDOC ## obs_frontend_recording_start ### Description Starts recording. ``` -------------------------------- ### Configure and Build Qt for Windows ARM64 Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-for-Windows-ARM64 Use this batch script to configure, compile, and install Qt 5.15.2 for Windows ARM64. Ensure you are using a normal x64 VS Developer Command Prompt and jom for faster compilation. ```batch "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 cd qt\ configure.bat -opensource -platform win32-msvc -xplatform win32-arm64-msvc2017 -prefix "C:\qt" -confirm-license -schannel -nomake examples -nomake tests -no-compile-examples -no-dbus -no-freetype -no-harfbuzz -no-icu -no-feature-concurrent -no-feature-itemmodeltester -no-feature-printdialog -no-feature-printer -no-feature-printpreviewdialog -no-feature-printpreviewwidget -no-feature-sql -no-feature-sqlmodel -no-feature-testlib -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci -no-sql-odbc -no-sql-psql -no-sql-sqlite2 -no-sql-sqlite -no-sql-tds -DQT_NO_PDF -DQT_NO_PRINTER -mp jom -j12 jom install -j12 ``` -------------------------------- ### Creating and Managing Sources Source: https://context7.com/obsproject/obs-studio/llms.txt Demonstrates how to create, configure, and manage OBS sources, including video capture sources and filters. ```APIDOC ## Creating and Managing Sources Sources are the fundamental building blocks in OBS that provide video/audio content. Create sources using `obs_source_create` and manage their lifecycle with reference counting. ```c #include void create_sources_example(void) { // Create settings for a video capture source obs_data_t *settings = obs_data_create(); obs_data_set_string(settings, "device", "video0"); obs_data_set_int(settings, "resolution", 1920); // Create a video capture source obs_source_t *camera = obs_source_create("v4l2_input", "Webcam", settings, NULL); obs_data_release(settings); if (!camera) { printf("Failed to create camera source\n"); return; } // Get source dimensions uint32_t width = obs_source_get_width(camera); uint32_t height = obs_source_get_height(camera); printf("Source dimensions: %ux%u\n", width, height); // Set source volume (0.0 to 1.0) obs_source_set_volume(camera, 0.8f); // Mute/unmute audio obs_source_set_muted(camera, false); // Update source settings dynamically obs_data_t *new_settings = obs_data_create(); obs_data_set_int(new_settings, "resolution", 1280); obs_source_update(camera, new_settings); obs_data_release(new_settings); // Get source by name (increments reference) obs_source_t *found_source = obs_get_source_by_name("Webcam"); if (found_source) { printf("Found source: %s\n", obs_source_get_name(found_source)); obs_source_release(found_source); } // Add a filter to the source obs_data_t *filter_settings = obs_data_create(); obs_data_set_double(filter_settings, "gamma", 1.2); obs_source_t *color_filter = obs_source_create("color_filter", "Color Correction", filter_settings, NULL); obs_data_release(filter_settings); if (color_filter) { obs_source_filter_add(camera, color_filter); obs_source_release(color_filter); } // Release the source when done obs_source_release(camera); } ``` ``` -------------------------------- ### Install Debian OBS Plugin Dependencies Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Linux Installs development libraries for various OBS Studio plugins on Debian-based systems. ```bash sudo apt install \ libasound2-dev \ libfdk-aac-dev \ libfontconfig-dev \ libfreetype6-dev \ libjack-jackd2-dev \ libpulse-dev libsndio-dev \ libspeexdsp-dev \ libudev-dev \ libv4l-dev \ libva-dev \ libvlc-dev \ libvpl-dev \ libdrm-dev \ nlohmann-json3-dev \ libwebsocketpp-dev \ libasio-dev ``` -------------------------------- ### Install Debian OBS Core Dependencies Source: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Linux Installs core OBS Studio runtime and development libraries on Debian-based systems. ```bash sudo apt install libavcodec-dev libavdevice-dev libavfilter-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libcurl4-openssl-dev libmbedtls-dev libgl1-mesa-dev libjansson-dev libluajit-5.1-dev python3-dev libx11-dev libxcb-randr0-dev libxcb-shm0-dev libxcb-xinerama0-dev libxcb-composite0-dev libxcomposite-dev libxinerama-dev libxcb1-dev libx11-xcb-dev libxcb-xfixes0-dev swig libcmocka-dev libxss-dev libglvnd-dev libgles2-mesa-dev libwayland-dev librist-dev libsrt-openssl-dev libpci-dev libpipewire-0.3-dev libqrcodegencpp-dev uthash-dev libsimde-dev ``` -------------------------------- ### Full Service Configuration Example Source: https://github.com/obsproject/obs-studio/wiki/Service-Submission-Guidelines This JSON object demonstrates a complete service configuration, including all available properties for defining a new streaming service. It specifies common settings, server details, supported codecs, and recommended streaming parameters. ```json { "name": "Example Service Name", "common": false, "more_info_link": "https://example.com/documentation/more-info", "stream_key_link": "https://example.com/page/with/stream/key", "alt_names": [ "Previous Example Service Name" ], "servers": [ { "name": "RTMPS Example", "url": "rtmps://ingest.example.com:443/live" }, { "name": "RTMP Example", "url": "rtmp://ingest.example.com/live" } ], "protocol": "RTMPS", "supported video codecs": [ "h264", "hevc" ], "supported audio codecs": [ "aac", "opus" ], "recommended": { "keyint": 2, "profile": "high", "supported resolutions": [ "1920x1080", "1280x720", "852x480", "640x360" ], "bitrate matrix": [ { "res": "1920x1080", "fps": 30, "max bitrate": 6000 }, { "res": "1920x1080", "fps": 60, "max bitrate": 9000 } ], "max fps": 60, "max video bitrate": 9000, "max audio bitrate": 320, "bframes": 2, "x264opts": "scenecut=0", "output": "rtmp_output" } } ``` -------------------------------- ### Example: Enabling and Disabling Cancellation Source: https://github.com/obsproject/obs-studio/blob/master/deps/w32-pthreads/manual/pthread_setcancelstate.html This example demonstrates how to set the cancel state to PTHREAD_CANCEL_ENABLE and then to PTHREAD_CANCEL_DISABLE, saving the old states. ```c #include #include int main(void) { int old_state, old_type; /* Disable asynchronous cancels, enable deferred cancels */ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_state); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old_type); /* ... do work ... */ /* Restore previous cancel state and type */ pthread_setcancelstate(old_state, NULL); pthread_setcanceltype(old_type, NULL); return 0; } ``` -------------------------------- ### pthread_cleanup_push Source: https://github.com/obsproject/obs-studio/blob/master/deps/w32-pthreads/manual/pthread_cleanup_push.html Installs a cleanup handler routine that will be called when the thread terminates. The handler is executed in LIFO order if multiple handlers are installed. ```APIDOC ## pthread_cleanup_push ### Description Installs the specified routine function with its argument as a cleanup handler. This handler will be invoked when the thread exits via `pthread_exit` or is cancelled. ### Signature ```c #include void pthread_cleanup_push(void (*routine)(void *), void *arg); ``` ### Parameters * **routine** (void (*)(void *)) - The function to be called as a cleanup handler. * **arg** (void *) - The argument to be passed to the cleanup handler function. ``` -------------------------------- ### OBS Data API Example Source: https://context7.com/obsproject/obs-studio/llms.txt Demonstrates creating, populating, reading, and serializing data objects using the obs_data API. Includes setting various data types, default values, nested objects, and arrays. Also shows how to save to and load from JSON files, and iterate through data items. ```c #include void data_api_example(void) { // Create new data object obs_data_t *data = obs_data_create(); // Set various data types obs_data_set_string(data, "name", "My Source"); obs_data_set_int(data, "width", 1920); obs_data_set_double(data, "volume", 0.85); obs_data_set_bool(data, "enabled", true); // Set default values obs_data_set_default_string(data, "fallback", "default_value"); obs_data_set_default_int(data, "port", 8080); // Create nested object obs_data_t *nested = obs_data_create(); obs_data_set_string(nested, "url", "rtmp://server.com/live"); obs_data_set_obj(data, "server_config", nested); obs_data_release(nested); // Create and populate array obs_data_array_t *array = obs_data_array_create(); for (int i = 0; i < 3; i++) { obs_data_t *item = obs_data_create(); obs_data_set_int(item, "index", i); obs_data_set_string(item, "label", "Item"); obs_data_array_push_back(array, item); obs_data_release(item); } obs_data_set_array(data, "items", array); obs_data_array_release(array); // Read data back const char *name = obs_data_get_string(data, "name"); long long width = obs_data_get_int(data, "width"); double volume = obs_data_get_double(data, "volume"); bool enabled = obs_data_get_bool(data, "enabled"); printf("Name: %s, Width: %lld, Volume: %.2f, Enabled: %d\n", name, width, volume, enabled); // Check if value exists if (obs_data_has_user_value(data, "width")) { printf("Width was explicitly set\n"); } // Serialize to JSON const char *json = obs_data_get_json(data); printf("JSON: %s\n", json); // Save to file obs_data_save_json(data, "/tmp/settings.json"); // Load from JSON file obs_data_t *loaded = obs_data_create_from_json_file("/tmp/settings.json"); if (loaded) { // Apply loaded settings to existing data obs_data_apply(data, loaded); obs_data_release(loaded); } // Iterate through all items obs_data_item_t *item = obs_data_first(data); while (item) { const char *item_name = obs_data_item_get_name(item); enum obs_data_type type = obs_data_item_gettype(item); printf("Item: %s, Type: %d\n", item_name, type); obs_data_item_next(&item); } obs_data_release(data); } ``` -------------------------------- ### Swift Enumerated Loop Example Source: https://github.com/obsproject/obs-studio/blob/master/CODESTYLE.md Use enumerated loops when both the index and the element are required. This example iterates over a collection and prints the index. ```Swift for (i, theThing) in theCollection.enumerated() { doTheThing(with: theThing); print("I am on iteration \(i) here...") } ``` -------------------------------- ### Get Output Video Conversion Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-outputs.md Optionally gets the video conversion information for raw outputs. This function was added in version 29.1. ```c const struct video_scale_info *obs_output_get_video_conversion([obs_output_t](#c.obs_output_t) *output) ``` -------------------------------- ### Basic Hello World Script Source: https://github.com/obsproject/obs-studio/wiki/Scripting-Tutorial-Source-Shake A minimal script to verify that scripting is enabled. Use `blog` for better logging. ```Python print("Hello World!") #one obligatory newline ``` -------------------------------- ### obs_output_can_begin_data_capture Source: https://github.com/obsproject/obs-studio/blob/master/docs/sphinx/reference-outputs.md Determines whether video/audio capture (encoded or raw) is able to start. Call this before initializing any output state to ensure that the output can start. ```APIDOC ## bool obs_output_can_begin_data_capture(const [obs_output_t](#c.obs_output_t) *output, int flags) ### Description Determines whether video/audio capture (encoded or raw) is able to start. Call this before initializing any output state to ensure that the output can start. ### Parameters #### Path Parameters * **output** (const [obs_output_t](#c.obs_output_t) *) - The output * **flags** (int) - Reserved. Set this to 0. ### Returns *true* if data capture can begin ```