LoginSignup
13
10

More than 1 year has passed since last update.

Jetson Nanoでライブ配信ソフトOBS Studioを動かしてみた (※ブラウザソースあり手順を追加)

Last updated at Posted at 2020-04-11

はじめに

Jetson Nano で ライブ配信ソフト OBS Studio を動かすまでをメモに残しておきます。

きっかけは質問を受けて調べたらいくつか動作実績は出てきましたが、いろいろと苦労している様子で、完璧な手順がありませんでした。

OBS(Open Broadcaster Software) とは

OBS(Open Broadcaster Software) は、オープンソースで開発されている、フリーのライブ配信ソフトです。
オフラインイベントやオンラインイベントの配信で、映像や音声を取り込んでテロップや画面の切り替えによく使用されます。Windows、macOS、Linux (x86/x64) はビルド済みのバイナリをダウンロードして使用することができますが、Jetson Nano や Raspberry Pi は CPU アーキテクチャが 異なり ARM (ARMv7/ARM64) のため、ソースからビルドする必要があります。

ビルド済バイナリパッケージ

ビルドが面倒な方はバイナリパッケージ(ブラウザソースなし)を作成しましたので、以下のリンクからダウンロードして使用してください。
https://github.com/kitazaki/jetson_nano_obs-studio

OBS Studio 25.0.5-26 (obs-studio_20200411-git-1_arm64.deb)
OBS Studio 26.1.2-289 (obs-studio_20210328-git-1_arm64.deb)

# インストール方法
$ wget https://github.com/kitazaki/jetson_nano_obs-studio/raw/master/obs-studio_20200411-git-1_arm64.deb
$ sudo apt install ./obs-studio_20200411-git-1_arm64.deb

# アンインストール方法
$ sudo dpkg -r obs-studio

※ 2020/4/11 23:40追記

  • バイナリパッケージを使用して OBS 起動時にエラーが出る場合
$ obs
obs: error while loading shared libraries: libobs-frontend-api.so.0: cannot open shared object file: No such file or directory

# 解決方法 (共有ライブラリの再読み込みをする)
$ sudo ldconfig
  • OBS 起動後に配信開始や録画開始でエラーが出る場合

解決方法
「Jetson Nano でのビルド」→「2. 必要なパッケージをダウンロード/インストールする」を実施する

※ 2021/3/28 10:30追記

ブラウザソースありのバイナリパッケージはサイズが大きい(約230MB)のでGoogle Driveに置きました。
OBS Studio 25.0.5-26 (obs-studio_20210328-git-1_arm64.deb)

Jetson Nano でのビルド

基本的に公式のビルド手順にしたがって実施します。
ビルドに掛かる時間は必要なパッケージのダウンロード/インストールから始めて 1 時間くらい掛かりました。
https://github.com/obsproject/obs-studio/wiki/Install-Instructions

環境

  • Jetson Nano (A01、新リビジョン B01 では試していません)
  • OS イメージ JetPack 4.3 (nv-jetson-nano-sd-card-image-r32.3.1.zip)
  • Ubuntu 18.04.4 LTS (Bionic Beaver)
  • ウェブカメラ (Logitech, Inc. Webcam C270)

※ 2021/3/28 10:30追記

  • Jetson Nano 2GB
  • OS イメージ JetPack 4.5.1 (jetson-nano-2gb-jp451-sd-card-image.zip)
    • Ubuntu 18.04.5 LTS

手順

1. パッケージを最新の状態に更新する

$ sudo apt update
$ sudo apt upgrade

2. 必要なパッケージをダウンロード/インストールする

sudo apt install \
            build-essential \
            checkinstall \
            cmake \
            git \
            libnss3-dev \
            libmbedtls-dev \
            libasound2-dev \
            libavcodec-dev \
            libavdevice-dev \
            libavfilter-dev \
            libavformat-dev \
            libavutil-dev \
            libcurl4-openssl-dev \
            libfdk-aac-dev \
            libfontconfig-dev \
            libfreetype6-dev \
            libgl1-mesa-dev \
            libjack-jackd2-dev \
            libjansson-dev \
            libluajit-5.1-dev \
            libpulse-dev \
            libqt5x11extras5-dev \
            libspeexdsp-dev \
            libswresample-dev \
            libswscale-dev \
            libudev-dev \
            libv4l-dev \
            libvlc-dev \
            libx11-dev \
            libx264-dev \
            libxcb-shm0-dev \
            libxcb-xinerama0-dev \
            libxcomposite-dev \
            libxinerama-dev \
            pkg-config \
            python3-dev \
            qt5-default \
            qtbase5-dev \
            qtbase5-private-dev \
            qttools5-dev-tools \
            libqt5svg5-dev \
            swig \
            libxcb-randr0-dev \
            libxcb-xfixes0-dev \
            libx11-xcb-dev \
            libxcb1-dev

3. OBS Studio のソースコードをダウンロードする

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

4. OBS Studio をビルドする

"ブラウザソースなし"のビルド手順

$ cd obs-studio
$ mkdir build && cd build
$ cmake -DUNIX_STRUCTURE=1 -DCMAKE_INSTALL_PREFIX=/usr ..
$ make -j4
$ sudo make install

"ブラウザソースあり"のビルド手順

"ブラウザソースあり"=ブラウザソースプラグインをビルドするためには、CEF (Chromium Embedded Framework)が必要になり、先にCEFをビルドします。

次にOBS Studioをビルドします。(cef-projectとobs-studioが同じディレクトリに存在する前提)
cmakeコマンドを2回実行している理由は、plugins/obs-browser/CMakeLists.txtで、FindCEF.cmakeが実行され、CEFライブラリ(libcef_dll_wrapper.aとlibcef.so)を探すディレクトリが異なるためです。

$ cd obs-studio
$ mkdir build && cd build
$ cmake -DUNIX_STRUCTURE=1 -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="../../cef-project" ..
$ cmake -DUNIX_STRUCTURE=1 -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="../../cef-project/third_party/cef/cef_binary_87.1.12+g03f9336+chromium-87.0.4280.88_linuxarm64" ..
$ make -j4
$ sudo make install
  • 参考

1回目のcmakeでエラーが発生します。(抜粋)

-- Looking for Chromium Embedded Framework in ../../cef-project
CMake Warning at plugins/obs-browser/FindCEF.cmake:50 (message):
  Could not find the CEF shared library
Call Stack (most recent call first):
  plugins/obs-browser/CMakeLists.txt:13 (find_package)

-- CEF Not found -- obs-browser plugin disabled.

2回目のcmakeで成功します。(抜粋)
(「-- CEF Not found -- obs-browser plugin disabled.」のメッセージが表示されなければ成功です。)

-- Looking for Chromium Embedded Framework in ../../cef-project/third_party/cef/cef_binary_87.1.12+g03f9336+chromium-87.0.4280.88_linuxarm64

Jetson Nano での実行

コマンドプロンプトから普通に OBS を実行すると OpenGL ライブラリの読み込みで Segmentation Fault が発生してプロセスが終了してしまいます。

$ obs
Attempted path: share/obs/obs-studio/locale/en-US.ini
Attempted path: /usr/share/obs/obs-studio/locale/en-US.ini
Attempted path: share/obs/obs-studio/locale.ini
Attempted path: /usr/share/obs/obs-studio/locale.ini
Attempted path: share/obs/obs-studio/themes/Dark.qss
Attempted path: /usr/share/obs/obs-studio/themes/Dark.qss
info: Physical Cores: 4, Logical Cores: 4
info: Physical Memory: 3956MB Total, 1993MB Free
info: Kernel Version: Linux 4.9.140-tegra
info: Distribution: "Ubuntu" "18.04"
info: Window System: X11.0, Vendor: The X.Org Foundation, Version: 1.19.6
info: Portable mode: false
Attempted path: share/obs/obs-studio/themes/Dark/no_sources.svg
Attempted path: /usr/share/obs/obs-studio/themes/Dark/no_sources.svg
QMetaObject::connectSlotsByName: No matching signal for on_advAudioProps_clicked()
QMetaObject::connectSlotsByName: No matching signal for on_advAudioProps_destroyed()
QMetaObject::connectSlotsByName: No matching signal for on_actionGridMode_triggered()
QMetaObject::connectSlotsByName: No matching signal for on_program_customContextMenuRequested(QPoint)
info: OBS 25.0.5-26-g2552cf91-modified (linux)
info: ---------------------------------
info: ---------------------------------
info: audio settings reset:
	samples per sec: 44100
	speakers:        2
info: ---------------------------------
info: Initializing OpenGL...
Segmentation fault (core dumped)

OpenGL ライブラリの読み込みで失敗しているので、他の失敗事例を調べたところ LD_PRELOAD 環境変数を設定したら起動できたという記事を見つけて試したところ、正常に OBS を起動できました。

正常に起動できたときのログです。

$ LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libGL.so obs
Attempted path: share/obs/obs-studio/locale/en-US.ini
Attempted path: /usr/share/obs/obs-studio/locale/en-US.ini
Attempted path: share/obs/obs-studio/locale.ini
Attempted path: /usr/share/obs/obs-studio/locale.ini
Attempted path: share/obs/obs-studio/themes/Dark.qss
Attempted path: /usr/share/obs/obs-studio/themes/Dark.qss
info: Physical Cores: 4, Logical Cores: 4
info: Physical Memory: 3956MB Total, 1365MB Free
info: Kernel Version: Linux 4.9.140-tegra
info: Distribution: "Ubuntu" "18.04"
info: Window System: X11.0, Vendor: The X.Org Foundation, Version: 1.19.6
info: Portable mode: false
Attempted path: share/obs/obs-studio/themes/Dark/no_sources.svg
Attempted path: /usr/share/obs/obs-studio/themes/Dark/no_sources.svg
QMetaObject::connectSlotsByName: No matching signal for on_advAudioProps_clicked()
QMetaObject::connectSlotsByName: No matching signal for on_advAudioProps_destroyed()
QMetaObject::connectSlotsByName: No matching signal for on_actionGridMode_triggered()
QMetaObject::connectSlotsByName: No matching signal for on_program_customContextMenuRequested(QPoint)
info: OBS 25.0.5-26-g2552cf91-modified (linux)
info: ---------------------------------
info: ---------------------------------
info: audio settings reset:
	samples per sec: 44100
	speakers:        2
info: ---------------------------------
info: Initializing OpenGL...
info: Loading up OpenGL on adapter NVIDIA Corporation NVIDIA Tegra X1 (nvgpu)/integrated
info: OpenGL loaded successfully, version 3.3.0 NVIDIA 32.3.1, shading language 3.30 NVIDIA via Cg compiler
info: ---------------------------------
info: video settings reset:
	base resolution:   1920x1080
	output resolution: 1280x720
	downscale filter:  Bicubic
	fps:               30/1
	format:            NV12
	YUV mode:          601/Partial
info: NV12 texture support not available
info: Audio monitoring device:
	name: Default
	id: default
info: ---------------------------------
warning: Failed to load 'en-US' text for module: 'decklink-ouput-ui.so'
libDeckLinkAPI.so: cannot open shared object file: No such file or directory
warning: A DeckLink iterator could not be created.  The DeckLink drivers may not be installed
info: No blackmagic support
info: FFMPEG VAAPI supported
info: VLC found, VLC video source enabled
info: ---------------------------------
info:   Loaded Modules:
info:     vlc-video.so
info:     text-freetype2.so
info:     rtmp-services.so
info:     obs-x264.so
info:     obs-transitions.so
info:     obs-outputs.so
info:     obs-libfdk.so
info:     obs-filters.so
info:     obs-ffmpeg.so
info:     linux-v4l2.so
info:     linux-pulseaudio.so
info:     linux-jack.so
info:     linux-decklink.so
info:     linux-capture.so
info:     linux-alsa.so
info:     image-source.so
info:     frontend-tools.so
info:     decklink-ouput-ui.so
info: ---------------------------------
info: ==== Startup complete ===============================================
  • ブラウザソースなし
  • ブラウザソースあり

環境変数を設定する

.bashrc ファイルに環境変数 LD_PRELOAD の定義を追加すれば、毎回 OBS を起動する際に環境変数の設定が不要になります。

.bashrc
# for OBS-Studio to avoid OpenGL Segmentation Fault
LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libGL.so
$ source .bashrc
$ obs

さいごに

配信ソフトは安定性が重要なので、しばらく (2 時間くらい) の間 YouTubeLive 配信を続けてみましたが、問題なさそうでした。
https://youtu.be/p-NPszC5vQo

映像はソフトウェアエンコーディング (ソフトウェア x264) なので、配信や録画を開始すると CPU 使用率は 60% くらいで推移します。

では、OBS Studio で良き配信ライフを!

追記

2021/3/24

Jetson Nano 2GB、JetPack 4.5.1でmakeを実行しているときに以下のエラーが発生。

/home/jetson/obs-studio/UI/obs-app.cpp:64:10: fatal error: qpa/qplatformnativeinterface.h: No such file or directory
 #include <qpa/qplatformnativeinterface.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
UI/CMakeFiles/obs.dir/build.make:298: recipe for target 'UI/CMakeFiles/obs.dir/obs-app.cpp.o' failed
make[2]: *** [UI/CMakeFiles/obs.dir/obs-app.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:1929: recipe for target 'UI/CMakeFiles/obs.dir/all' failed
make[1]: *** [UI/CMakeFiles/obs.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

qt5関連パッケージをインストールして解決。(上記2.の手順にも反映済)

sudo apt install qtbase5-private-dev qtbase5-dev qttools5-dev-tools

OBS Studio 26.1.2でデスクトップ音声が使用可能になりました。

2021/3/28

ブラウザソースありのビルド手順を追加

  • 2022/3/20 追記

Jetson Nano JetPack 4.6.1 / OBS-Studio 27.2.0 (ブラウザソースなし) / StreamFX 0.11.0 (オプション)

環境

  • Jetson Nano 4GB (A02)
  • JetPack 4.6.1 (L4T 32.7.1)
  • OBS: Application Version: 27.2.0-133-g923d42721-modified - Build Number: 1
  • StreamFX 0.11.0.10-gbf1787e5 (オプション)

0. OBS-Studio バージョン26で追加された仮想カメラ機能の有効化

$ sudo apt install v4l2loopback-dkms

1. Doxygenのインストール

エラー内容

-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
--- Cannot find doxygen(version 1.8.10 or newer), ENABLE_DOCS turned off.
-- Configuring incomplete, errors occurred!

対処方法

$ sudo apt install doxygen

2. AV1 Codec Libraryのインストール

エラー内容

CMake Error at test/test.cmake:606 (target_link_libraries):
  Target "aom_av1_encoder" of type OBJECT_LIBRARY may not be linked into
  another target.  One may link only to STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

対処方法

$ git clone https://aomedia.googlesource.com/aom
$ cd aom
$ mkdir cmake-build && cd cmake-build
$ cmake ..
$ make -j3
$ sudo make install

3. AJA NTV2 SDKのインストール

エラー内容

CMake Error at /usr/local/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find LibAJANTV2 (missing: AJA_LIBRARIES_INCLUDE_DIR AJA_NTV2_LIB)
Call Stack (most recent call first):
  /usr/local/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  cmake/Modules/FindLibAJANTV2.cmake:98 (find_package_handle_standard_args)
  plugins/aja/CMakeLists.txt:18 (find_package)

対処方法

$ git clone https://github.com/aja-video/ntv2
$ mkdir cmake-build && cd cmake-build
$ cmake -DCMAKE_BUILD_TYPE=Debug -DAJA_INSTALL_HEADERS=ON -DAJA_INSTALL_INCLUDEDIR=/usr/local/include ..
$ make -j3
$ sudo make install

4. cmakeコマンドのパラメータを変更する

エラー内容

CMake Error at plugins/linux-capture/CMakeLists.txt:55 (message):
  OBS: - PipeWire library not found! Please install PipeWire or set
  ENABLE_PIPEWIRE=OFF

対処方法

$ cmake -DUNIX_STRUCTURE=1 -DCMAKE_CXX_FLAGS="-fPIC" -DENABLE_PIPEWIRE=OFF -DBUILD_BROWSER=OFF -DCMAKE_INSTALL_PREFIX=/usr ..

5. ビルド中のエラーに対処する

エラー内容

In file included from /home/jetson/20220320/obs-studio/plugins/aja/aja-common.hpp:11:0,
                 from /home/jetson/20220320/obs-studio/plugins/aja/aja-card-manager.cpp:2:
/usr/local/include/ajalibraries/ajantv2/includes/ntv2card.h:18:11: fatal error: ntv2linuxdriverinterface.h: No such file or directory
  #include "ntv2linuxdriverinterface.h"
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
plugins/aja/CMakeFiles/aja.dir/build.make:89: recipe for target 'plugins/aja/CMakeFiles/aja.dir/aja-card-manager.cpp.o' failed

対処方法

$ cd /usr/local/include/ajalibraries/ajantv2/includes
$ sudo ln -s ../src/lin/ntv2linuxdriverinterface.h ./

6. StreamFXのインストール (オプション)

補足

下記のエラー内容は無視して問題ない

CMake Error at UI/frontend-plugins/streamfx/cmake/clang/Clang.cmake:235 (file):
  Error evaluating generator expression:

    $<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>

  $<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets to
  specify include directories, compile definitions, and compile options.  It
  may not be used with the add_custom_command, add_custom_target, or
  file(GENERATE) commands.
Call Stack (most recent call first):
  UI/frontend-plugins/streamfx/CMakeLists.txt:1937 (generate_compile_commands_json)

Screenshot from 2022-03-20 10-34-40.png

  • 2022/3/21 追記

Jetson Nano JetPack 4.6.1 / OBS-Studio 27.2.0 (ブラウザソースあり) / cef_binary_96.0.16 / StreamFX 0.11.0

環境

  • Jetson Nano 4GB (A02)
  • JetPack 4.6.1 (L4T 32.7.1)
  • OBS: Application Version: 27.2.0-133-g923d42721-modified - Build Number: 1
  • cef_binary_96.0.16+g89c902b+chromium-96.0.4664.55_linuxarm64
  • StreamFX 0.11.0.10-gbf1787e5

1. CEF (Chromium Embedded Framework)をビルドする

2. OBS-Studioをビルドする

cmakeコマンドを2回実行する必要がなくなりました。

$ cd obs-studio
$ mkdir build && cd build
$ cmake -DUNIX_STRUCTURE=1 -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_BROWSER=ON -DCEF_LIBRARY="../../cef-project/third_party/cef/cef_binary_96.0.16+g89c902b+chromium-96.0.4664.55_linuxarm64/Release/libcef.so" -DCEFWRAPPER_LIBRARY="../../cef-project/build/libcef_dll_wrapper/libcef_dll_wrapper.a" -DCEF_INCLUDE_DIR="../../cef-project/third_party/cef/cef_binary_96.0.16+g89c902b+chromium-96.0.4664.55_linuxarm64" -DCEF_ROOT_DIR="../../cef-project/third_party/cef/cef_binary_96.0.16+g89c902b+chromium-96.0.4664.55_linuxarm64" ..
$ sudo make -j3
$ sudo make install

Screenshot from 2022-03-21 11-56-40.png

Screenshot from 2022-03-21 11-55-43.png

13
10
11

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
10