Skip to content

Repository files navigation

OBS-WebRTC-Link

Build Status License

English | 日本語

A versatile WebRTC plugin for OBS Studio that provides Universal WebRTC Input & Output.

While perfect for OBS-to-OBS relay, it also enables you to receive streams from browsers, mobile devices, and other WHIP clients directly into OBS as a source.


🔗 Architecture

This plugin supports both SFU Relay (WHIP/WHEP) for stability and Direct P2P for low latency.

Mode A: SFU Relay (Recommended)

Best for: Internet streaming, receiving from multiple sources (Browsers, Mobiles), and complex networks.

(Compatible with any WHIP/WHEP compliant SFU like LiveKit, SRS, Janus)

graph LR
    Source[OBS / Browser / Mobile] -- WHIP --> SFU[SFU Server (e.g. LiveKit)]
    SFU -- WHEP --> Receiver[OBS (This Plugin)]
    SFU -- WHEP --> Browser[Browser Viewer]

Mode B: Direct P2P (Advanced)

Best for: Local Area Networks (LAN) or 1-on-1 direct connections.

graph LR
    Peer[OBS / Browser Peer] -- P2P / Direct --> Receiver[OBS (This Plugin)]

🚀 Features

Universal WebRTC Source:

  • Receive video/audio from other OBS instances.
  • Receive streams from web browsers (via WebRTC).
  • Receive from mobile apps or any WHIP-compatible publisher.

Hybrid Connection Modes:

  • SFU Relay Support: Stable connections through WHIP/WHEP compliant servers (LiveKit tested).
  • Direct P2P: Ultra-low latency direct connections.

Bidirectional:

  • Output: Send OBS Program output via WebRTC.
  • Source: Add a “WebRTC Link Source” to receive streams.

Additional:

  • Automatic reconnection
  • Hardware accelerated encoding/decoding (NVENC/AMF/QuickSync)

📦 Installation

Windows, Linux, macOS

Current Release (v0.1.0):

  • Linux: Download pre-built binary from Releases
  • Windows/macOS: Build from source (see BUILD.md)

Note: Pre-built Windows installer is planned for future releases. For now, please follow the build instructions in BUILD.md.


⚙️ Quick Start

Adding WebRTC Source to OBS

  1. Add Source
    • Click + in the Sources panel
    • Select WebRTC Link Source
    • Name your source (e.g., "Remote Feed")

Adding WebRTC Link Source Screenshot will be added in a future release

  1. Configure Connection Mode

    Choose between SFU (recommended) or P2P mode based on your use case.

Scenario 1: Receiving from LiveKit / SFU (Recommended)

Receiver (Your OBS):

  • Add WebRTC Link Source
  • Mode: SFU (WHEP)
  • URL: https://your-sfu-endpoint/whep
  • Token: subscriber token

WHEP Source Settings Screenshot will be added in a future release

Sender:

  • OBS: select WebRTC Output
  • Browser/Mobile: publish via WHIP or LiveKit SDK

Scenario 2: Direct P2P

Sender:

  • Choose "P2P Host"
  • Copy the Session ID

Receiver:

  • Add WebRTC Link Source
  • Select P2P Client
  • Paste Session ID

P2P Source Settings Screenshot will be added in a future release


📖 Detailed Usage Examples

For detailed, step-by-step guides covering common use cases:

  • Usage Examples Guide - Comprehensive examples including:
    • OBS-to-OBS relay via LiveKit
    • Browser to OBS (guest input)
    • Direct P2P connections
    • Mobile device as wireless camera
    • Audio-only mode for podcasts
    • Troubleshooting tips

For LiveKit server setup, see LiveKit Setup Guide.


🐳 Development Environment (Docker)

For easy local testing with LiveKit SFU, you can use the included Docker environment:

Quick Start

1. Navigate to the docker directory:

cd docker/livekit

2. Copy the example environment file:

cp .env.example .env

3. Generate API credentials:

# Generate API Key
openssl rand -base64 32

# Generate API Secret
openssl rand -base64 32

4. Edit .env and set your credentials:

LIVEKIT_API_KEY=your-generated-api-key
LIVEKIT_API_SECRET=your-generated-api-secret

5. Start LiveKit:

docker-compose up -d

LiveKit Endpoints

Once running, LiveKit will be available at:

  • WebRTC API: http://localhost:7880
  • WHIP Endpoint: http://localhost:7880/whip
  • WHEP Endpoint: http://localhost:7880/whep

Generating Access Tokens

To connect to LiveKit, you need to generate access tokens. You can use the LiveKit CLI or generate tokens programmatically.

Using LiveKit CLI:

# Install LiveKit CLI
go install github.com/livekit/livekit-cli/cmd/livekit-cli@latest

# Generate a publisher token (for WHIP)
livekit-cli create-token \
  --api-key <LIVEKIT_API_KEY> \
  --api-secret <LIVEKIT_API_SECRET> \
  --join --room my-room --identity publisher \
  --valid-for 24h

# Generate a subscriber token (for WHEP)
livekit-cli create-token \
  --api-key <LIVEKIT_API_KEY> \
  --api-secret <LIVEKIT_API_SECRET> \
  --join --room my-room --identity subscriber \
  --valid-for 24h

Stopping LiveKit

docker-compose down

To remove all data:

docker-compose down -v

🛠️ Build from Source

Prerequisites

Before building the plugin, ensure you have the following requirements:

Required Tools:

  • CMake: 3.20 or later (Download)
  • Git: For cloning the repository and managing submodules
  • C++17 Compatible Compiler:
    • Windows: Visual Studio 2019 or later (MSVC 14.2+)
    • Linux: GCC 9+ or Clang 10+
    • macOS: Xcode 12+ (Apple Clang 12+)

Required Libraries:

  • OBS Studio SDK: Version 30.x or later

Optional (Included as Submodules):

Getting OBS Studio

You have several options to obtain OBS Studio development files:

Option 1: Use Pre-built OBS Studio (Recommended for Windows)

Windows:

  1. Download the latest OBS Studio installer from obsproject.com
  2. Install OBS Studio to the default location (e.g., C:\Program Files\obs-studio)
  3. The include files are typically located at:
    • Headers: C:\Program Files\obs-studio\include
    • Libraries: C:\Program Files\obs-studio\bin\64bit

macOS:

  1. Download the OBS Studio DMG from obsproject.com
  2. Extract the app and locate the development headers inside the bundle
  3. Alternatively, install via Homebrew:
    brew install obs

Linux: Install OBS Studio development packages:

# Ubuntu/Debian
sudo apt install obs-studio libobs-dev

# Fedora
sudo dnf install obs-studio obs-studio-devel

# Arch Linux
sudo pacman -S obs-studio

Option 2: Build OBS Studio from Source

If you need a specific version or want to contribute to OBS itself:

  1. Clone the OBS Studio repository:

    git clone --recursive https://github.com/obsproject/obs-studio.git
    cd obs-studio
  2. Follow the build instructions for your platform:

  3. After building, note the paths to:

    • Include directory: <obs-build-dir>/include
    • Library directory: <obs-build-dir>/build/libobs or <obs-build-dir>/build/Release/bin/64bit

Platform-Specific Build Instructions

Windows (Visual Studio)

1. Clone the repository with submodules:

git clone --recursive https://github.com/m96-chan/OBS-WebRTC-Link.git
cd OBS-WebRTC-Link

If you already cloned without --recursive, initialize submodules:

git submodule update --init --recursive

2. Configure with CMake:

Open a command prompt or PowerShell and run:

mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A x64 ^
  -DOBS_INCLUDE_SEARCH_PATH="C:/Program Files/obs-studio/include" ^
  -DOBS_LIB_SEARCH_PATH="C:/Program Files/obs-studio/bin/64bit"

Replace "Visual Studio 17 2022" with your installed version:

  • Visual Studio 2022: "Visual Studio 17 2022"
  • Visual Studio 2019: "Visual Studio 16 2019"

3. Build:

cmake --build . --config Release

Or open obs-webrtc-link.sln in Visual Studio and build from the IDE.

4. Install:

cmake --install . --config Release

This will install the plugin to:

  • Plugin: C:\Program Files\obs-studio\obs-plugins\64bit\
  • Data: C:\Program Files\obs-studio\data\obs-plugins\obs-webrtc-link\

Note: You may need administrator privileges to install to Program Files.

macOS (Xcode or Command Line)

1. Clone the repository with submodules:

git clone --recursive https://github.com/m96-chan/OBS-WebRTC-Link.git
cd OBS-WebRTC-Link
git submodule update --init --recursive

2. Install dependencies:

# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install OBS Studio and dependencies
brew install obs cmake

3. Configure with CMake:

For command-line build:

mkdir build && cd build
cmake .. \
  -DCMAKE_BUILD_TYPE=Release \
  -DOBS_INCLUDE_SEARCH_PATH="/opt/homebrew/include" \
  -DOBS_LIB_SEARCH_PATH="/opt/homebrew/lib"

For Xcode:

mkdir build && cd build
cmake .. -G Xcode \
  -DOBS_INCLUDE_SEARCH_PATH="/opt/homebrew/include" \
  -DOBS_LIB_SEARCH_PATH="/opt/homebrew/lib"

4. Build:

Command-line:

cmake --build . --config Release

Or open the generated Xcode project and build from the IDE.

5. Install:

sudo cmake --install . --config Release

This will install the plugin to:

  • Plugin: /Library/Application Support/obs-studio/plugins/obs-webrtc-link.so
  • Data: /Library/Application Support/obs-studio/plugins/obs-webrtc-link/data/

Linux (GCC/Clang)

1. Install dependencies:

Ubuntu/Debian:

sudo apt update
sudo apt install build-essential cmake git \
  libobs-dev obs-studio \
  libssl-dev pkg-config

Fedora:

sudo dnf install gcc-c++ cmake git \
  obs-studio-devel \
  openssl-devel

Arch Linux:

sudo pacman -S base-devel cmake git obs-studio openssl

2. Clone the repository with submodules:

git clone --recursive https://github.com/m96-chan/OBS-WebRTC-Link.git
cd OBS-WebRTC-Link
git submodule update --init --recursive

3. Configure with CMake:

mkdir build && cd build
cmake .. \
  -DCMAKE_BUILD_TYPE=Release \
  -DOBS_INCLUDE_SEARCH_PATH="/usr/include" \
  -DOBS_LIB_SEARCH_PATH="/usr/lib"

4. Build:

cmake --build . -j$(nproc)

The -j$(nproc) flag uses all available CPU cores for faster compilation.

5. Install:

sudo cmake --install .

This will install the plugin to:

  • Plugin: /usr/lib/obs-plugins/obs-webrtc-link.so
  • Data: /usr/share/obs/obs-plugins/obs-webrtc-link/

CMake Configuration Options

The following CMake options are available to customize the build:

Option Default Description
OBS_INCLUDE_SEARCH_PATH - Path to OBS Studio include directory (required)
OBS_LIB_SEARCH_PATH - Path to OBS Studio library directory (required)
BUILD_LIBDATACHANNEL ON Build libdatachannel from source (submodule)
LIBDATACHANNEL_DIR - Custom path to libdatachannel installation
BUILD_TESTING ON Build unit tests (requires Google Test)
BUILD_BENCHMARKS ON Build performance benchmarks (requires Google Benchmark)
BUILD_TESTS_ONLY OFF Build only tests without OBS plugin (useful for CI)

Example: Build without tests and benchmarks:

cmake .. \
  -DOBS_INCLUDE_SEARCH_PATH="/path/to/obs/include" \
  -DOBS_LIB_SEARCH_PATH="/path/to/obs/lib" \
  -DBUILD_TESTING=OFF \
  -DBUILD_BENCHMARKS=OFF

Example: Use system-installed libdatachannel:

cmake .. \
  -DOBS_INCLUDE_SEARCH_PATH="/path/to/obs/include" \
  -DOBS_LIB_SEARCH_PATH="/path/to/obs/lib" \
  -DBUILD_LIBDATACHANNEL=OFF

Building Tests Only (Without OBS SDK)

If you want to build and run tests without installing OBS Studio:

mkdir build && cd build
cmake .. -DBUILD_TESTS_ONLY=ON
cmake --build . --config Release
ctest --output-on-failure

This is useful for continuous integration (CI) environments.

Dependency Management

Included as Git Submodules (Automatically Built):

  • libdatachannel: WebRTC implementation
  • nlohmann-json: JSON library for C++
  • Google Test: Unit testing framework
  • Google Benchmark: Performance benchmarking

The project automatically builds these dependencies from submodules. To update them:

git submodule update --remote

Using System Libraries (Advanced):

If you have libraries installed system-wide and want to use them instead:

cmake .. \
  -DBUILD_LIBDATACHANNEL=OFF \
  -DOBS_INCLUDE_SEARCH_PATH="/path/to/obs/include" \
  -DOBS_LIB_SEARCH_PATH="/path/to/obs/lib"

The project includes custom CMake Find modules that automatically locate system libraries. See cmake/README.md for details.

IDE Development Setup

Visual Studio (Windows)

  1. Open Visual Studio
  2. Select File → Open → CMake and choose the root CMakeLists.txt
  3. Visual Studio will automatically configure the project
  4. Edit CMake settings in CMakeSettings.json to specify OBS paths:
    {
      "configurations": [
        {
          "name": "x64-Release",
          "generator": "Ninja",
          "configurationType": "Release",
          "buildRoot": "${projectDir}\\build",
          "cmakeCommandArgs": "-DOBS_INCLUDE_SEARCH_PATH=\"C:/Program Files/obs-studio/include\" -DOBS_LIB_SEARCH_PATH=\"C:/Program Files/obs-studio/bin/64bit\""
        }
      ]
    }
  5. Build the project using Build → Build All

Xcode (macOS)

  1. Generate Xcode project:
    mkdir build && cd build
    cmake .. -G Xcode \
      -DOBS_INCLUDE_SEARCH_PATH="/opt/homebrew/include" \
      -DOBS_LIB_SEARCH_PATH="/opt/homebrew/lib"
  2. Open obs-webrtc-link.xcodeproj in Xcode
  3. Select the target and build configuration (Debug/Release)
  4. Build using Product → Build (⌘B)

CLion (Cross-Platform)

  1. Open CLion and select Open → Choose the project root directory
  2. CLion will automatically detect CMakeLists.txt
  3. Configure CMake options in Settings → Build, Execution, Deployment → CMake:
    • Add CMake options:
      -DOBS_INCLUDE_SEARCH_PATH=/path/to/obs/include
      -DOBS_LIB_SEARCH_PATH=/path/to/obs/lib
      
  4. Build the project using Build → Build Project

Visual Studio Code (Cross-Platform)

  1. Install the CMake Tools extension
  2. Open the project folder in VS Code
  3. Create or edit .vscode/settings.json:
    {
      "cmake.configureArgs": [
        "-DOBS_INCLUDE_SEARCH_PATH=/path/to/obs/include",
        "-DOBS_LIB_SEARCH_PATH=/path/to/obs/lib"
      ]
    }
  4. Press Ctrl+Shift+P (or Cmd+Shift+P on macOS) and run CMake: Configure
  5. Build using CMake: Build or press F7

Troubleshooting

Common Build Errors

Error: "Could not find OBS Studio"

  • Solution: Ensure OBS_INCLUDE_SEARCH_PATH and OBS_LIB_SEARCH_PATH are correctly set
  • Verify that OBS Studio is installed and the paths contain obs-module.h and obs.lib/libobs.so

Error: "Submodule not found"

  • Solution: Initialize submodules:
    git submodule update --init --recursive

Error: "Qt not found" (Windows)

  • Solution: Qt is optional for UI components. The plugin will build without Qt, but without UI features.
  • To enable Qt, install Qt 5.15+ or Qt 6.x and ensure it's in your PATH, or disable UI:
    cmake .. -DQT_FOUND=OFF

Error: "CMake version too old"

  • Solution: Update CMake to version 3.20 or later
  • Download from cmake.org

Error: "Compiler not found" (Windows)

  • Solution: Install Visual Studio 2019 or later with C++ development tools
  • Ensure you open "Developer Command Prompt for VS" or run vcvarsall.bat

Error: "libobs.so not found" (Linux)

  • Solution: Install OBS Studio development package:
    sudo apt install libobs-dev  # Ubuntu/Debian
    sudo dnf install obs-studio-devel  # Fedora

Error: "Permission denied" during install

  • Solution: Use sudo on Linux/macOS:
    sudo cmake --install . --config Release
  • On Windows, run Command Prompt as Administrator

Debug vs. Release Builds

Debug Build (for development):

cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug

Debug builds include:

  • Debug symbols for debugging
  • No optimizations
  • Slower performance but easier to debug

Release Build (for production):

cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release

Release builds include:

  • Full compiler optimizations
  • Smaller binary size
  • Better performance

Important: Match your build configuration with OBS Studio's configuration. If OBS was built in Release mode, build the plugin in Release mode as well to avoid potential issues.

Running Tests

After building with BUILD_TESTING=ON:

cd build
ctest --output-on-failure --verbose

Or run specific tests:

./tests/unit/sample_test
./tests/unit/peer_connection_test

Running Benchmarks

After building with BUILD_BENCHMARKS=ON:

cd build
./tests/benchmarks/whip_connection_benchmark

Verifying Installation

After installation, verify the plugin is loaded:

  1. Launch OBS Studio
  2. Go to Tools → Scripts or check the log file
  3. Look for "obs-webrtc-link" in the loaded plugins list
  4. Add a WebRTC Link Source to verify the plugin is working

Getting Help

If you encounter issues:


📝 License

Licensed under GPLv2.
See LICENSE for full details.


🇯🇵 日本語概要

OBSでWebRTC映像を送受信するための汎用プラグインです。
OBS同士のリレーはもちろん、ブラウザ・スマホ・他の配信アプリからの映像をOBSソースとして受信できます。


主な機能

WebRTC入力ソース:

  • ブラウザやスマホからの映像をOBSへ取り込み可能
  • LiveKitなどのSFUと接続し、安定した遠隔映像受信が可能

2つの接続モード:

  • SFUリレー(推奨):サーバー経由で安定接続
  • Direct P2P:LAN向け直接接続

想定ユースケース

  • OBSリレー:自宅↔スタジオ間の伝送
  • ゲスト参加:ブラウザ経由で映像を送信
  • スマホカメラ:WebRTCを使ったワイヤレスカメラ化

🐳 開発環境(Docker)

ローカルでのテストを簡単に行うため、LiveKit SFUのDocker環境を用意しています。

クイックスタート

1. dockerディレクトリに移動:

cd docker/livekit

2. 環境変数ファイルをコピー:

cp .env.example .env

3. API認証情報を生成:

# API Keyを生成
openssl rand -base64 32

# API Secretを生成
openssl rand -base64 32

4. .env ファイルを編集して認証情報を設定:

LIVEKIT_API_KEY=生成したAPIキー
LIVEKIT_API_SECRET=生成したAPIシークレット

5. LiveKitを起動:

docker-compose up -d

LiveKitエンドポイント

起動後、以下のエンドポイントが利用可能になります:

  • WebRTC API: http://localhost:7880
  • WHIP エンドポイント: http://localhost:7880/whip
  • WHEP エンドポイント: http://localhost:7880/whep

アクセストークンの生成

LiveKitに接続するには、アクセストークンが必要です。LiveKit CLIを使用するか、プログラムで生成できます。

LiveKit CLIを使用:

# LiveKit CLIをインストール
go install github.com/livekit/livekit-cli/cmd/livekit-cli@latest

# パブリッシャートークンを生成(WHIP用)
livekit-cli create-token \
  --api-key <LIVEKIT_API_KEY> \
  --api-secret <LIVEKIT_API_SECRET> \
  --join --room my-room --identity publisher \
  --valid-for 24h

# サブスクライバートークンを生成(WHEP用)
livekit-cli create-token \
  --api-key <LIVEKIT_API_KEY> \
  --api-secret <LIVEKIT_API_SECRET> \
  --join --room my-room --identity subscriber \
  --valid-for 24h

LiveKitを停止

docker-compose down

すべてのデータを削除する場合:

docker-compose down -v

About

A versatile WebRTC plugin for OBS Studio that provides Universal WebRTC Input & Output.

Topics

Resources

Contributing

Stars

11 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages