在树莓派上使用OBS studio

发布于 2024-03-11  62 次阅读


引子

虽然在树莓派上运行obs没啥必要,但是因为现在树莓派的新版窗口系统改用Wayland了。因为在Wayland的世界里,每个窗口都在单独的容器里,使用x11composite等传统方法捕获屏幕将只能看到一片漆黑......

录屏变得十分麻烦,正好啊,obs支持使用Pipewire来捕获屏幕,还是得手动编译安装一个obs-studio。

安装依赖

sudo apt install cmake ninja-build pkg-config clang clang-format build-essential curl ccache git 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 libgles2-mesa-dev libwayland-dev librist-dev libsrt-openssl-dev libpci-dev libpipewire-0.3-dev libqrcodegencpp-dev 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 libdrm-dev nlohmann-json3-dev libwebsocketpp-dev libasio-dev qt6-base-dev qt6-base-private-dev libqt6svg6-dev qt6-wayland qt6-image-formats-plugins

拉取代码到本地

git clone --recursive https://github.com/obsproject/obs-studio.git
注意:此处必须要使用“--recursive”参数来引入obs-project所附带的子模块。

开始编译

# 创建编译文件夹
mkdir obs-build

# 设置编译参数
cmake -S obs-studio/ -B obs-build/ -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_QSV11=OFF -DENABLE_BROWSER=OFF -DENABLE_WEBRTC=OFF -DENABLE_AJA=OFF -DENABLE_JACK=ON -DENABLE_PIPEWIRE=ON -DQT_VERSION=6 

# 开始编译
cmake --build obs-build/

# 生成.deb安装包
cmake --build obs-build/ --target package

安装和使用

由于树莓派的OpenGL版本仅为OpenGL 3.1,直接运行OBS会提示如下内容。

Failed to initialize video. Your GPU may not be supported, or your graphics drivers may need to be updated.

安装生成的deb包后,以root身份运行以下命令,替换OBS的可执行文件为一个脚本来协助启动。

sudo mv /usr/local/bin/obs /usr/local/bin/obs.direct-run
echo -en 'export MESA_GL_VERSION_OVERRIDE=3.3\r\n$(readlink -f $(dirname $0))/obs.direct-run $@\r\n'|  sudo tee /usr/local/bin/obs
sudo chmod 755 /usr/local/bin/obs