Skip to content

构建最新版本obs (2022-06-24)

当前基于obs最新代码

commit 889ca0fc041dbd35de15e99088407b5da488393a (HEAD -> master, origin/master, origin/HEAD)
Author: Sebastian Beckmann <beckmann.sebastian@outlook.de>
Date:   Thu May 19 04:09:42 2022 +0200

    UI: Regroup and Reorder source right-click menus

    Visually, the Scale Filtering, Blending Mode & Method, and Deinterlacing
    menus are now grouped together, with "Hide in Mixer" being its own group
    until a better place for it has been found.
    Projector and Screenshot menus have been moved down.

参考构建文档

https://obsproject.com/wiki/build-instructions-for-windows

该构建文档有2种构建模式,当前遵循planB来进行。

大致步骤:

  • git clone https://gitee.com/mirrors/obs-studio.git // 使用了镜像库
  • 下载基础依赖
    • visual studio 2019
      • windows 10 sdk
    • qt 5.15.2
    • CEF wrapper x64 本次暂不打算支持win32模式
    • windows cmake
    • windows Git + tortoiseGit

实际上,在构建指导文档中,有提到 CI/build-windows.ps1CI/build-windows.ps1 -SkipDependencyChecks -CombinedArchs -BuildConfiguration Release -Verbose 等参数。 这个脚本会自动下载和安装其它没有特别提到的相关依赖。

  • vlc库
  • windows-deps-2022-05-23-x64.zip 是根据 windows-deps-${Version}-${ArchSuffix}.zip" 自动替换得到
  • windows-deps-qt-2022-05-23-x64.zip
  • cef_binary_4638_windows_x64.zip 这个也会自动下载,虽然前面也已经提到

自行下载依赖文件

因众所周知的网络问题,直接使用 build-windows.ps1脚本下载经常失败。

需要下载的文件:

https://github.com/obsproject/obs-deps/releases/download/win-${Version}/windows-deps-${Version}-${ArchSuffix}.zip

https://cdn-fastly.obsproject.com/downloads/windows-deps-qt-${Version}-${ArchSuffix}.zip

https://cdn-fastly.obsproject.com/downloads/vlc.zip

https://cdn-fastly.obsproject.com/downloads/cef_binary_${Version}_windows_${ArchSuffix}.zip

实际下载的链接地址:

https://github.com/obsproject/obs-deps/releases/download/win-2022-05-23/windows-deps-2022-05-23-x64.zip
https://cdn-fastly.obsproject.com/downloads/windows-deps-qt-2022-05-23-x64.zip
https://cdn-fastly.obsproject.com/downloads/vlc.zip
https://cdn-fastly.obsproject.com/downloads/cef_binary_2022-05-23_windows_x64.zip

下载后自行解压缩

根据构建脚本,需要将这些依赖解压缩到如下目录结构

./folder/obs-build-dependencies
./folder/obs-build-dependencies/windows-deps-2022-05-23-x64
./folder/obs-build-dependencies/vlc-3.0.0-git
./folder/obs-build-dependencies/cef_binary_2022-05-23_windows_x64
./folder/obs-studio  # obs源码位置

特殊注意点 windows-deps-qt-2022-05-23-x64.zip 这个压缩包,也需要解压缩到 windows-deps-2022-05-23-x64 目录中 vlc需要解压缩到 vlc-3.0.0-git

开始编译

.\CI\build-windows.ps1

输出类似:

Found existing pre-built dependencies...

Found existing pre-built Qt...

Found existing VLC...

Found existing CEF framework and loader library...

select windows 10 sdk to target 10.0.18363.xxxx

报错处理

发现提示 无法找到包含文件 atlbase.h 应该是visual studio没有安装mfc依赖,安装后再次尝试。

开发调试环境

上述步骤设置之后,并不方便后续开发和调试,需要参照后续步骤继续设置Cmake-GUI来生成一个方便的开发和debug环境。

关键的环境变量:

  • CMAKE_PREFIX_PATH 仅需要添加空值即可
  • DepsPath 参照上文解压缩路径,当前为 E:/folder/obs-build-dependencies/windows-deps-2022-05-23-x64
  • QTDIR 当前设置为 D:\Qt\5.15.2\msvc2019_64
  • CEF_ROOT_DIR 当前设置 E:/folder/obs-build-dependencies/cef_binary_2022-05-23_windows_x64
  • VIRTUALCAM_GUID 随机字符串,长度建议30~40
  • ENABLE_BROWSER 这个环境变量在CMake完成Configure之后,自动出现,仅需要勾选
  • 后面几个环境变量如果不设置,也可以编译,但是会丢失相关youtube的集成能力,本身当前版本就是基于youtube的集成模型来做改版,必须启用
  • YOUTUBE_CLIENTID=aabbccdd
  • YOUTUBE_SECRET=xxxxyyyy
  • YOUTUBE_CLIENTID_HASH=1000
  • YOUTUBE_SECRET_HASH=2000
  • OBS_InstallerTempDir= 这个变量如果配置了,在vs构建过程中,会自动把相关的输出文件 exe/dll/qss/lang等文件copy到指定的目录

构建installer安装包

根据当前理解,obs采用NSIS来构建安装包。

实际使用脚本 UI/installer/mp-installer.nsi

但是,这个脚本需要给NSIS预先安装一个插件。 相关代码在 https://github.com/notr1ch/OBSInstallerUtils

下载 https://github.com/notr1ch/OBSInstallerUtils

关键点 CMakeGenerate时一定选Win32,不要选x64,否则NSIS无法识别插件。

直接使用cmake-gui生成项目后,构建得到OBSInstallerUtils.dll插件,放入文件夹:C:\Program Files (32)\NSIS\plugins\x86-unicode

Option A: Automatic Windows builds

Automatic Windows builds allow building OBS with minimal input and setup. Necessary dependencies are installed automatically, build flags use a sane default, and the generated OBS build uses the application's full feature set.

Prerequisites

  • Windows PowerShell (v5+ and more recent)
  • Visual Studio 2019 (at least Community Edition)
    • Windows 10 SDK (minimum 10.0.20348.0)
  • Git for Windows

Note that the automatic build scripts can use Chocolatey to automatically install additional build dependencies (CMake and 7-Zip), by passing the -Choco switch.

Build procedure

  • Clone the repository including submodules:

    git clone --recursive https://github.com/obsproject/obs-studio.git

  • To do a fully automated build, open a PowerShell window, switch to the checkout directory then run one of the following commands:

<a id='download-and-set-up-dependencies-then-build-obs-for-local-host-' class='anchor' aria-hidden='true'></a>
# Download and set up dependencies, then build OBS for local host 
# architecture with common feature set
CI/build-windows.ps1

<a id='check-for-dependencies-installable-via-chocolatey' class='anchor' aria-hidden='true'></a>
# Check for dependencies installable via Chocolatey
CI/build-windows.ps1 -Choco

<a id='skip-download-and-setup-of-dependencies' class='anchor' aria-hidden='true'></a>
# Skip download and setup of dependencies
CI/build-windows.ps1 -SkipDependencyChecks

<a id='build-32-bit-only' class='anchor' aria-hidden='true'></a>
# Build 32-bit only
CI/build-windows.ps1 -BuildArch '32-bit'

<a id='build-both-architectures' class='anchor' aria-hidden='true'></a>
# Build both architectures
CI/build-windows.ps1 -CombinedArchs

<a id='create-a-zip-archive-with-obs-and-all-required-libraries' class='anchor' aria-hidden='true'></a>
# Create a zip archive with OBS and all required libraries
CI/build-windows.ps1 -Package

<a id='create-a-debug-build' class='anchor' aria-hidden='true'></a>
# Create a debug build
CI/build-windows.ps1 -BuildConfiguration Debug

<a id='use-mybuilddir-prefix-as-build-directory' class='anchor' aria-hidden='true'></a>
# Use `my_build_dir` prefix as build directory
CI/build-windows.ps1 -BuildDirectory my_build_dir

<a id='build-and-package-a-combined-64-bit-and-32-bit-of-obs-with-release-configuration-' class='anchor' aria-hidden='true'></a>
# Build and package a combined 64-bit and 32-bit of OBS with Release configuration, 
# using more verbose output and skipping dependency checks
CI/build-windows.ps1 -SkipDependencyChecks -CombinedArchs -BuildConfiguration Release -Verbose

<a id='show-all-available-options' class='anchor' aria-hidden='true'></a>
# Show all available options
CI/build-windows.ps1 -Help

Option B: Custom Windows builds

Custom Windows builds allow full customization of the desired build configuration but also require manual setup and preparation. Available CMake configuration variables can be found in the CMake build system documentation.

Prerequisites

  • Visual Studio 2019 (recommended)
    • Windows 10 SDK (minimum 10.0.20348.0). Latest SDK
  • Development packages of FFmpeg, x264, cURL, and mbedTLS
  • Qt5 (Grab the MSVC package for your version of Visual Studio)
    • OBS officially supports building with Qt 5.15.2
  • CEF Wrapper (x64, x86)
  • Windows version of CMake (3.20 or higher, latest preferred)
  • Windows version of Git (Git binaries must exist in path)

Build procedure

1. Get the source code

  • Clone the repository including submodules: git clone --recursive https://github.com/obsproject/obs-studio.git

(If you do not know what submodules are, or you are not using Git from the command line, PLEASE make sure to fetch the submodules too).

2. Get the dependencies

  • Download and set up most preconditions mentioned above, you can also run the script CI/windows/01_install_dependencies.ps1 (run it with the -Help switch to see all available options).

NOTE: You cannot change the directory where the script will download and setup the dependencies in.

3. Set up the build project

  1. Run cmake-gui, and set the following fields:

    • In "where is the source code", enter in the repository directory (example: D:/obs).
    • In "where to build the binaries", enter the repository directory path with the 'build' subdirectory (example: D:/obs/build). If this directory does not exist, it will be created by CMake.
    • Set required CMake variables either as Windows environment variables (allows usage across multiple projects) or directly as cache variables. Check the CMake build system documentation for a full list and description of these variables:

    • CMAKE_PREFIX_PATH - REQUIRED

    • DepsPath (DepsPath32 and DepsPath64 as architecture-specific variants) - LEGACY
    • QTDIR (QTDIR32 and QTDIR64 as architecture-specific variants) - LEGACY
    • CEF_ROOT_DIR (when building with browser support)
    • VIRTUALCAM_GUID (when building with Virtual Camera support)
    • In cmake-gui, press Configure, and select the generator that corresponds with the desired installed Visual Studio version:

    • Visual Studio 16 2019, or their 64bit equivalents if you want to build the 64bit version of OBS

    • NOTE: If you need to change your dependencies from a build already configured, you will need to uncheck COPIED_DEPENDENCIES and run Configure again.
    • If you did not set up environment variables earlier you can now configure the variables named above in cmake-gui
  2. In cmake-gui, press Generate to generate Visual Studio project files in the build subdirectory.

4. Open the Visual Studio project

  1. Open obs-studio.sln from the subdirectory you specified under "where to build the binaries" (e.g. D:/obs/build) in Visual Studio (or click the Open Project button from within cmake-gui).

  2. The project should now be ready to build and run. All required dependencies should be copied on compile and it should be a fully functional build environment. The build artifacts are installed into a subdirectory called rundir/ within your chose build directory (with `beingDebug,RelWithDebInfo` or any other build configuration that was successfully built).

5. Install the virtual camera

If you want to use the Virtual Camera created by this build, you will have to run its install script and also remove the Virtual Camera from a standard OBS installation first:

  • To uninstall the OBS Virtual Camera

    1. Close any applications that were using the OBS Virtual Camera.
    2. In the OBS Studio installation directory, run data\obs-plugins\win-dshow\virtualcam-uninstall.bat as administrator.
    3. To install an OBS Virtual Camera:

    4. In the OBS Studio artifact directory (for Visual Studio builds, this is /rundir/), run data\obs-plugins\win-dshow\virtualcam-install.bat as administrator.

Don't forget to uninstall your build's virtual camera before cleaning/deleting your build files.

6. Integrating clang-format into Visual Studio

Use of clang-format is required for pull requests, and OBS uses a more recent version than is shipped with Visual Studio 2019:

  1. Download and install LLVM 12.0.0
  2. Run Visual Studio, select Tools -> Options from the menu
    • Go to Text Editor -> C/C++ -> Code Style -> Formatting -> General
    • Enable "Use custom clang-format.exe" and enter the file name, e.g. C:\Program Files\LLVM\bin\clang-format.exe
    • The default keyboard shortcut for formatting a document (Edit.FormatDocument) is Ctrl+K, Ctrl+D.