### Output, Encoder, and Service Integration Example Source: https://docs.obsproject.com/frontends Demonstrates how to set up video and audio encoders, associate them with an output, and optionally link a service for streaming, before starting the output. ```c 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); ``` -------------------------------- ### Scene Handling Example Source: https://docs.obsproject.com/reference-frontend-api Example of getting a scene from a source. ```c obs_scene_t *scene = obs_scene_from_source(source); [...] } obs_frontend_source_list_free(&scenes); ``` -------------------------------- ### Example Properties Callback Source: https://docs.obsproject.com/plugins This example demonstrates how to define properties for an OBS source, including a boolean setting. ```c static obs_properties_t *my_source_properties(void *data) { obs_properties_t *ppts = obs_properties_create(); obs_properties_add_bool(ppts, "my_bool", obs_module_text("MyBool")); UNUSED_PARAMETER(data); return ppts; } struct obs_source_info my_source { .get_properties = my_source_properties, [...] }; ``` -------------------------------- ### Service Implementation Example Source: https://docs.obsproject.com/plugins Example of defining an obs_service_info structure for a custom streaming service. ```c /* my-service.c */ [...] struct obs_service_info my_service_service = { .id = "my_service", .get_name = my_service_name, .create = my_service_create, .destroy = my_service_destroy, .encode = my_service_encode, .update = my_service_update, .get_url = my_service_url, .get_key = my_service_key }; ``` -------------------------------- ### Starting an Output Source: https://docs.obsproject.com/reference-outputs Starts the output. Returns _true_ if output successfully started, _false_ otherwise. If the output failed to start, `obs_output_get_last_error()` may contain a specific error string related to the reason. ```c bool obs_output_start(obs_output_t *output); ``` -------------------------------- ### Native Plugin Initialization Example (my-plugin.c) Source: https://docs.obsproject.com/plugins An example C file demonstrating the initialization of a native plugin module, including registering sources, outputs, encoders, and services. ```c /* 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; } ``` -------------------------------- ### Effect Parameters Example Source: https://docs.obsproject.com/graphics This example demonstrates the syntax for defining effect parameters, including matrices, textures, and custom color/float parameters. ```hlsl uniform float4x4 ViewProj; uniform texture2d image; uniform float4 my_color_param; uniform float my_float_param; ``` -------------------------------- ### Color Key Filter Rendering Example Source: https://docs.obsproject.com/graphics An example of how a filter like the color key filter renders its effect. ```c static void color_key_render(void *data, gs_effect_t *effect) { struct color_key_filter_data *filter = data; if (!obs_source_process_filter_begin(filter->context, GS_RGBA, OBS_ALLOW_DIRECT_RENDERING)) return; gs_effect_set_vec4(filter->color_param, &filter->color); gs_effect_set_float(filter->contrast_param, filter->contrast); gs_effect_set_float(filter->brightness_param, filter->brightness); gs_effect_set_float(filter->gamma_param, filter->gamma); gs_effect_set_vec4(filter->key_color_param, &filter->key_color); gs_effect_set_float(filter->similarity_param, filter->similarity); gs_effect_set_float(filter->smoothness_param, filter->smoothness); obs_source_process_filter_end(filter->context, filter->effect, 0, 0); UNUSED_PARAMETER(effect); } ``` -------------------------------- ### Example of Conditional Property Visibility Source: https://docs.obsproject.com/plugins This example shows how to make a text property ('setting_b') hidden or visible based on the state of a boolean property ('setting_a') using a modified callback. ```c static bool setting_a_modified(obs_properties_t *ppts, obs_property_t *p, obs_data_t *settings) { bool enabled = obs_data_get_bool(settings, "setting_a"); p = obs_properties_get(ppts, "setting_b"); obs_property_set_enabled(p, enabled); /* return true to update property widgets, false otherwise */ return true; } static obs_properties_t *my_source_properties(void *data) { obs_properties_t *ppts = obs_properties_create(); obs_property_t *p; p = obs_properties_add_bool(ppts, "setting_a", obs_module_text("SettingA")); obs_property_set_modified_callback(p, setting_a_modified); obs_properties_add_text(ppts, "setting_b", obs_module_text("SettingB"), OBS_TEXT_DEFAULT); return ppts; } ``` -------------------------------- ### Audio Mixer Channels Source: https://docs.obsproject.com/reference-sources Sets or gets the audio mixer channels (audio tracks) that a source outputs to. Bits set in the 'mixers' value determine the output channels. For example, to output to mixer 1 and 3, use (1<<0) | (1<<2), which is 0x5. ```c void obs_source_set_audio_mixers(obs_source_t *source, uint32_t mixers); uint32_t obs_source_get_audio_mixers(const obs_source_t *source); ``` -------------------------------- ### obs_startup Source: https://docs.obsproject.com/reference-core Initializes the OBS core context. It takes the locale, a path to module configuration, and a profiler name store as parameters. It returns false if already initialized or if initialization fails. ```c bool obs_startup(const char *locale, const char *module_config_path, profiler_name_store_t *store) ``` -------------------------------- ### Example CMakeLists.txt for a Native Plugin Module Source: https://docs.obsproject.com/plugins A common CMakeLists.txt file for building a native plugin module. ```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) ``` -------------------------------- ### Encoder Implementation Example Source: https://docs.obsproject.com/plugins Example of defining an obs_encoder_info structure for a custom video encoder. ```c /* my-encoder.c */ [...] struct obs_encoder_info my_encoder_encoder = { .id = "my_encoder", .type = OBS_ENCODER_VIDEO, .codec = "h264", .get_name = my_encoder_name, .create = my_encoder_create, .destroy = my_encoder_destroy, .encode = my_encoder_encode, .update = my_encoder_update, .get_extra_data = my_encoder_extra_data, .get_sei_data = my_encoder_sei, .get_video_info = my_encoder_video_info }; ``` -------------------------------- ### Getting Default Source Settings Source: https://docs.obsproject.com/reference-sources Calls `obs_source_info.get_defaults` to get the defaults settings of the source type. ```c obs_data_t *obs_get_source_defaults(const char *id); ``` -------------------------------- ### Example Technique Definition Source: https://docs.obsproject.com/graphics This code demonstrates how to define a technique with a single pass, including vertex and pixel shaders. ```hlsl uniform float4x4 ViewProj; uniform texture2d image; struct VertInOut { float4 pos : POSITION; float2 uv : TEXCOORD0; }; VertInOut MyVertexShaderFunc(VertInOut vert_in) { VertInOut vert_out; vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj); vert_out.uv = vert_in.uv; return vert_out; } float4 MyPixelShaderFunc(VertInOut vert_in) : TARGET { return image.Sample(def_sampler, vert_in.uv); } technique Draw { pass { vertex_shader = MyVertexShaderFunc(vert_in); pixel_shader = MyPixelShaderFunc(vert_in); } }; ``` -------------------------------- ### Getting the Current Script's Path Source: https://docs.obsproject.com/scripting A function automatically implemented in each script to get its path. ```Python script_path() ``` ```Lua script_path() ``` -------------------------------- ### Implementing a Source Object Source: https://docs.obsproject.com/plugins Example of defining an `obs_source_info` structure and filling it with source-related information and callbacks. ```c /* my-source.c */ [...] struct obs_source_info my_source { .id = "my_source", .type = OBS_SOURCE_TYPE_INPUT, .output_flags = OBS_SOURCE_VIDEO, .get_name = my_source_name, .create = my_source_create, .destroy = my_source_destroy, .update = my_source_update, .video_render = my_source_render, .get_width = my_source_width, .get_height = my_source_height }; ``` -------------------------------- ### Creating a Source Source: https://docs.obsproject.com/reference-sources Creates a source of the specified type with the specified settings. The “source” context is used for anything related to presenting or modifying video/audio. Use `obs_source_release()` to release it. ```c obs_source_t *obs_source_create(const char *id, const char *name, obs_data_t *settings, obs_data_t *hotkey_data); ``` -------------------------------- ### Getting Set Output Delay Source: https://docs.obsproject.com/reference-outputs Gets the currently set delay value, in seconds. ```c uint32_t obs_output_get_delay(const obs_output_t *output); ``` -------------------------------- ### obs_frontend_streaming_start Source: https://docs.obsproject.com/reference-frontend-api Starts streaming. ```c void obs_frontend_streaming_start(void) ``` -------------------------------- ### Getting Source Display Name Source: https://docs.obsproject.com/reference-sources Calls the `obs_source_info.get_name` callback to get the translated display name of a source type. ```c const char *obs_source_get_display_name(const char *id); ``` -------------------------------- ### Getting Service Display Name Source: https://docs.obsproject.com/reference-services Calls the `obs_service_info.get_name` callback to get the translated display name of a service type. ```c const char *obs_service_get_display_name(const char *id); ``` -------------------------------- ### Get the HDC of a GDI-interop texture Source: https://docs.obsproject.com/reference-libobs-graphics-graphics Gets the HDC of a GDI-interop texture on Windows. Call `gs_texture_release_dc()` to release the HDC. ```c void *gs_texture_get_dc(gs_texture_t *gdi_tex) ``` -------------------------------- ### Implementing an Output Object Source: https://docs.obsproject.com/plugins Example of defining an `obs_output_info` structure and filling it with output-related information and callbacks. ```c /* my-output.c */ [...] struct obs_output_info my_output { .id = "my_output", .flags = OBS_OUTPUT_AV | OBS_OUTPUT_ENCODED, .get_name = my_output_name, .create = my_output_create, .destroy = my_output_destroy, .start = my_output_start, .stop = my_output_stop, .encoded_packet = my_output_data, .get_total_bytes = my_output_total_bytes, .encoded_video_codecs = "h264", .encoded_audio_codecs = "aac" }; ``` -------------------------------- ### Registering a Source in Lua Source: https://docs.obsproject.com/scripting Example demonstrating how to register a custom source using Lua by defining an `obs_source_info` structure. ```lua local info = {} info.id = "my_source_id" info.type = obslua.OBS_SOURCE_TYPE_INPUT info.output_flags = obslua.OBS_SOURCE_VIDEO info.get_name = function() return "My Source" end info.create = function(settings, source) -- typically source data would be stored as a table local my_source_data = {} [...] return my_source_data end info.video_render = function(my_source_data, effect) [...] end info.get_width = function(my_source_data) [...] -- assuming the source data contains a 'width' key return my_source_data.width end info.get_height = function(my_source_data) [...] -- assuming the source data contains a 'height' key return my_source_data.height end -- register the source obs_register_source(info) ``` -------------------------------- ### obs_frontend_create_profile Source: https://docs.obsproject.com/reference-frontend-api Creates a new profile. ```c bool obs_frontend_create_profile(const char *name) ```