├── .gitignore ├── LICENSE ├── README.md ├── build.sh └── launch_OBS.sh /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xbelanch/OBS4Pi/c61abcf1156cd76ccb7c3097427981b6c184ac18/.gitignore -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Xavier Belanche Alonso 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OBS4Pi. Building and installing FFmpeg and OBS Studio for the Raspberry Pi 4 ![Build passed](https://img.shields.io/badge/build-passed-green) ![GitHub last commit](https://img.shields.io/github/last-commit/xbelanch/OBS4Pi) 2 | 3 | ## Description 4 | 5 | This script [builds and install](https://stackoverflow.com/questions/19753078/what-is-building-and-installing) [FFmpeg (n4.3.2)](https://github.com/FFmpeg/FFmpeg) and [OBS Studio (26.1.2)](https://github.com/obsproject/obs-studio) on a [Raspberry Pi 4](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/). Derives and copypasta from different scripts that I have found but unfortunately they did not run successfully. This script may not work tomorrow or next week, so feel free to open a ticket issue to let me know. 6 | 7 | ## Installation 8 | 9 | Before running the script you must upgrade the currently Raspberry Pi OS *Buster* version to the not yet released *Bullseye*. This [tutorial](https://raspberrytips.com/update-raspberry-pi-latest-version/) explains the basic steps 10 | of how to do it. If you found issues during the upgrade phase check it out the troubleshooting section of that step by step tutorial: [Manually upgrade Debian from Buster to Bullseye](https://doc.akito.ooo/books/essentials/page/manually-upgrade-debian-from-buster-to-bullseye). 11 | 12 | ## Frequently Asked Questions 13 | 14 | No questions at this moment. 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | export LD_LIBRARY_PATH=/usr/local/lib/ 4 | TMPDIR="$(mktemp -d)" 5 | RED=$(tput setaf 1) 6 | GREEN=$(tput setaf 2) 7 | YELLOW=$(tput setaf 3) 8 | BLUE=$(tput setaf 4) 9 | PURPLE=$(tput setaf 5) 10 | CYAN=$(tput setaf 6) 11 | DEFAULT=$(tput sgr0) 12 | FFMPEG_TAG=n5.0 13 | OBS_TAG=28.0.0 14 | 15 | cleanup() { 16 | rm -rf "${TMPDIR}" 17 | } 18 | 19 | trap cleanup EXIT 20 | 21 | # Save current working directory 22 | cwd=$(pwd) 23 | 24 | version="0.0.3" 25 | dependencies=( 26 | "autoconf" 27 | "automake" 28 | "bison" 29 | "build-essential" 30 | "v4l2loopback-dkms" 31 | "cmake" 32 | "doxygen" 33 | "flex" 34 | "git" 35 | "graphviz" 36 | "imagemagick" 37 | "libasound2-dev" 38 | "libass-dev" 39 | "libatlas-base-dev" 40 | "libavcodec-dev" 41 | "libavdevice-dev" 42 | "libavfilter-dev" 43 | "libavformat-dev" 44 | "libavutil-dev" 45 | "libcurl4-openssl-dev" 46 | "libdc1394-22-dev" 47 | "libdrm-dev" 48 | "libfontconfig1-dev" 49 | "libfreetype6-dev" 50 | "libgl1-mesa-dev" 51 | "libgmp-dev" 52 | "libgstreamer-plugins-base1.0-dev" 53 | "libgstreamer1.0-dev" 54 | "libgtk-3-dev" 55 | "libjack-jackd2-dev" 56 | "libjansson-dev" 57 | "libjpeg-dev" 58 | "liblapacke-dev" 59 | "libluajit-5.1-dev" 60 | "libmbedtls-dev" 61 | "libmp3lame-dev" 62 | "libopencore-amrnb-dev" 63 | "libopencore-amrwb-dev" 64 | "libopenexr-dev" 65 | "libopus-dev" 66 | "libpng-dev" 67 | "libpulse-dev" 68 | "libqt5svg5-dev" 69 | "libqt5x11extras5-dev" 70 | "librtmp-dev" 71 | "libsdl2-dev" 72 | "libsdl2-image-dev" 73 | "libsdl2-mixer-dev" 74 | "libsdl2-net-dev" 75 | "libsdl2-ttf-dev" 76 | "libsnappy-dev" 77 | "libsoxr-dev" 78 | "libspeexdsp-dev" 79 | "libssh-dev" 80 | "libssl-dev" 81 | "libswresample-dev" 82 | "libswscale-dev" 83 | "libtiff-dev" 84 | "libtool" 85 | "libudev-dev" 86 | "libv4l-dev" 87 | "libva-dev" 88 | "libvdpau-dev" 89 | "libvlc-dev" 90 | "libvo-amrwbenc-dev" 91 | "libvorbis-dev" 92 | "libwebp-dev" 93 | "libx11-dev" 94 | "libx11-xcb-dev" 95 | "libx11-xcb1" 96 | "libx264-dev" 97 | "libx265-dev" 98 | "libxcb-randr0" 99 | "libxcb-randr0-dev" 100 | "libxcb-shape0-dev" 101 | "libxcb-shm0-dev" 102 | "libxcb-xfixes0" 103 | "libxcb-xfixes0-dev" 104 | "libxcb-xinerama0-dev" 105 | "libxcb-xinput-dev" 106 | "libxcb-xinput0" 107 | "libxcb1-dev" 108 | "libxcomposite-dev" 109 | "libxinerama-dev" 110 | "libxml2-dev" 111 | "libxvidcore-dev" 112 | "lzma-dev" 113 | "meson" 114 | "nasm" 115 | "pkg-config" 116 | "python3-dev" 117 | "python3-pip" 118 | "python3-pyqt5" 119 | "qtbase5-dev" 120 | "qtbase5-private-dev" 121 | "swig" 122 | "texinfo" 123 | "wget" 124 | "yasm" 125 | "zlib1g-dev" 126 | "libboost-all-dev" 127 | "qt5-image-formats-plugins" 128 | "qtcreator" 129 | "qtbase5-dev" 130 | "qtdeclarative5-dev" 131 | "libxcb-composite0-dev" 132 | "libpci-dev" 133 | ) 134 | 135 | my_date() { 136 | date "+%H:%M:%S %d-%m-%y " 137 | } 138 | 139 | print_info() { 140 | echo "${GREEN}" 141 | echo "________ __________ _________ _______________.__ _____ " 142 | echo "\_____ \\______ \/ _____/ / | \______ \__| / | | " 143 | echo " / | \| | _/\_____ \ / | || ___/ |/ | |_" 144 | echo "${PURPLE}/ | \ | \/ \/ ^ / | | / ^ /" 145 | echo "\_______ /______ /_______ /\____ ||____| |__\____ | " 146 | echo " \/ \/ \/ |__| |__| " 147 | echo "${DEFAULT}" 148 | 149 | echo "================================================================" 150 | echo " FFmpeg and OBS Studio Building Script v$version for Pi4" 151 | echo "================================================================" 152 | echo "" 153 | echo "${RED}OS${DEFAULT}: $(lsb_release -d | grep -oP "(?<=\s)(.*)")" 154 | echo "${RED}Kernel${DEFAULT}: $(uname -s) $(uname -r) $(uname -m)" 155 | echo "${RED}Timestamp${DEFAULT}: $(my_date)" 156 | echo "${RED}FFmpeg tag source version${DEFAULT}: ${FFMPEG_TAG}" 157 | echo "${RED}OBS tag source version${DEFAULT}: ${OBS_TAG}" 158 | echo "" 159 | } 160 | 161 | install_dependencies() { 162 | # If you're interested on improving this 163 | # take a look at https://stackoverflow.com/questions/1298066/how-to-check-if-package-installed-and-install-it-if-not 164 | echo "${YELLOW}" 165 | echo "Update and upgrade list of installed packages" 166 | echo "" 167 | sudo apt-get update -qq && sudo apt-get -y upgrade 168 | echo "" 169 | echo "Install missing dependencies" 170 | echo "${DEFAULT}" 171 | for pkg in ${dependencies[@]}; do 172 | if [ $(dpkg-query -W -f='${Status}' "${pkg}" 2>/dev/null | grep -c "ok installed") -eq 0 ]; 173 | then 174 | printf "${RED}Package: %-35s NOT INSTALLED${DEFAULT}\n" $pkg; 175 | sudo apt-get install -y "${pkg}"; 176 | else 177 | printf "Package: ${PURPLE}%-35s ${GREEN}OK${DEFAULT}\n" $pkg; 178 | fi 179 | done 180 | } 181 | 182 | check_os_version() { 183 | os_version=$(($(lsb_release -sr) + 0)) 184 | [[ $os_version -eq 11 ]] || { echo >&2 "${RED}!!!!!You must update Debian version to ${CYAN}bullseye${RED} before you execute again the script!!!!!${DEFAULT}" ; exit 1; } 185 | } 186 | 187 | get_and_build_pipewire() { 188 | echo "${YELLOW}" 189 | echo "-----------------------------------" 190 | echo "Get and build Pipewire" 191 | echo "-----------------------------------" 192 | echo "${DEFAULT}" 193 | git clone https://gitlab.freedesktop.org/pipewire/pipewire.git "${TMPDIR}/pipewire" \ 194 | && cd "${TMPDIR}/pipewire" \ 195 | && git checkout 0.3.43 \ 196 | && ./autogen.sh \ 197 | && make -j$(nproc) \ 198 | && sudo make install 199 | } 200 | 201 | get_and_build_libfdk_aac() { 202 | echo "${YELLOW}" 203 | echo "-----------------------------------" 204 | echo "Get and build libfdk-aac" 205 | echo "-----------------------------------" 206 | echo "${DEFAULT}" 207 | # AAC 208 | # To disable remove --enable-libfdk-aac 209 | git clone --depth 1 https://github.com/mstorsjo/fdk-aac "${TMPDIR}/fdk-aac" && cd "${TMPDIR}/fdk-aac" \ 210 | && autoreconf -fiv \ 211 | && ./configure --enable-shared \ 212 | && make -j$(nproc) \ 213 | && sudo make install 214 | } 215 | 216 | get_and_build_libdav1d() { 217 | echo "${YELLOW}" 218 | echo "-----------------------------------" 219 | echo "Get and build libdav1d" 220 | echo "-----------------------------------" 221 | echo "${DEFAULT}" 222 | # AV1 223 | # To disable remove --enable-libdav1d 224 | git clone --depth 1 https://code.videolan.org/videolan/dav1d.git "${TMPDIR}/dav1d" && mkdir "${TMPDIR}/dav1d/build" && cd "${TMPDIR}/dav1d/build" \ 225 | && meson .. \ 226 | && ninja \ 227 | && sudo ninja install 228 | } 229 | 230 | get_and_build_libkvazaar() { 231 | echo "${YELLOW}" 232 | echo "-----------------------------------" 233 | echo "Get and build libkvazaar" 234 | echo "-----------------------------------" 235 | echo "${DEFAULT}" 236 | # HEVC 237 | # To disable remove --enable-libkvazaar 238 | git clone --depth 1 https://github.com/ultravideo/kvazaar.git "${TMPDIR}/kvazaar" && cd "${TMPDIR}/kvazaar" \ 239 | && ./autogen.sh \ 240 | && ./configure --enable-shared \ 241 | && make -j$(nproc) \ 242 | && sudo make install 243 | } 244 | 245 | get_and_build_libvpx() { 246 | echo "${YELLOW}" 247 | echo "-----------------------------------" 248 | echo "Get and build libvpx" 249 | echo "-----------------------------------" 250 | echo "${DEFAULT}" 251 | # VP8 and VP9 252 | # To disable remove --enable-libvpx 253 | git clone --depth 1 https://chromium.googlesource.com/webm/libvpx "${TMPDIR}/libvpx" && cd "${TMPDIR}/libvpx" \ 254 | && ./configure --disable-examples --disable-tools --disable-unit_tests --disable-docs --enable-shared \ 255 | && make -j$(nproc) \ 256 | && sudo make install 257 | } 258 | 259 | get_and_build_libaom() { 260 | echo "${YELLOW}" 261 | echo "-----------------------------------" 262 | echo "Get and build libaom" 263 | echo "-----------------------------------" 264 | echo "${DEFAULT}" 265 | # AP1 266 | # To disable remove --enable-libaom 267 | git clone --depth 1 --branch v3.0.0 https://aomedia.googlesource.com/aom "${TMPDIR}/aom" \ 268 | && mkdir "${TMPDIR}/aom/aom_build" \ 269 | && cd "${TMPDIR}/aom/aom_build" \ 270 | && cmake -G "Unix Makefiles" AOM_SRC -DENABLE_NASM=on -DPYTHON_EXECUTABLE="$(which python3)" -DCMAKE_C_FLAGS="-mfpu=vfp -mfloat-abi=hard" .. \ 271 | && sed -i 's/ENABLE_NEON:BOOL=ON/ENABLE_NEON:BOOL=OFF/' CMakeCache.txt \ 272 | && make -j$(nproc) \ 273 | && sudo make install 274 | } 275 | 276 | get_and_build_zimg() { 277 | echo "${YELLOW}" 278 | echo "-----------------------------------" 279 | echo "Get and build zimg" 280 | echo "-----------------------------------" 281 | echo "${DEFAULT}" 282 | # ZIMG 283 | git clone --recurse-submodules https://github.com/sekrit-twc/zimg.git "${TMPDIR}/zimg" && cd "${TMPDIR}/zimg" \ 284 | && ./autogen.sh \ 285 | && ./configure --enable-shared \ 286 | && make -j$(nproc) \ 287 | && sudo make install 288 | } 289 | 290 | get_and_build_x264() { 291 | echo "${YELLOW}" 292 | echo "-----------------------------------" 293 | echo "Get and build x264" 294 | echo "-----------------------------------" 295 | echo "${DEFAULT}" 296 | git clone https://code.videolan.org/videolan/x264.git "${TMPDIR}/x264" && cd "${TMPDIR}/x264" \ 297 | && git checkout stable \ 298 | && ./configure --enable-shared --enable-pic --disable-cli \ 299 | && make -j$(nproc) \ 300 | && sudo make install 301 | } 302 | 303 | # Stolen from: https://github.com/PietroAvolio/Building-Gstreamer-Raspberry-Pi-With-SRT-Support/blob/master/gstreamer-build.sh 304 | # git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer 305 | get_and_build_gstreamer() { 306 | echo "${YELLOW}" 307 | echo "-----------------------------------" 308 | echo "Get and build gstreamer" 309 | echo "-----------------------------------" 310 | echo "${DEFAULT}" 311 | git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git "${TMPDIR}/gstreamer" && cd "${TMPDIR}/gstreamer" \ 312 | && git checkout tags/1.19.2 \ 313 | && meson build \ 314 | && ninja -C build \ 315 | && sudo ninja -C build install 316 | } 317 | 318 | get_and_build_obs_gstreamer() { 319 | echo "${YELLOW}" 320 | echo "------------------------------------------" 321 | echo "Get and build obs-gstreamer v0.2.0 plugin" 322 | echo "------------------------------------------" 323 | echo "${DEFAULT}" 324 | git clone https://github.com/fzwoch/obs-gstreamer.git "${TMPDIR}/obs-gstreamer" && cd "${TMPDIR}/obs-gstreamer" \ 325 | && git checkout tags/v0.2.0 \ 326 | && meson --buildtype=release build \ 327 | && ninja -C build \ 328 | && sudo ninja -C build install \ 329 | && sudo ln -sf /usr/local/lib/arm-linux-gnueabihf/obs-plugins/obs-gstreamer.so /usr/lib/obs-plugins/obs-gstreamer.so 330 | } 331 | 332 | get_and_build_ffmpeg() { 333 | echo "${YELLOW}" 334 | echo "-----------------------------------" 335 | echo "Get and build FFMPEG ${FFMPEG_TAG}" 336 | echo "-----------------------------------" 337 | echo "${DEFAULT}" 338 | git clone --depth 1 --branch ${FFMPEG_TAG} https://github.com/FFmpeg/FFmpeg.git "${TMPDIR}/FFmpeg" && cd "${TMPDIR}/FFmpeg" \ 339 | && ./configure \ 340 | --extra-cflags='-I/usr/local/include -march=armv8-a+crc+simd -mfloat-abi=hard -mfpu=neon-fp-armv8 -mtune=cortex-a72' \ 341 | --extra-libs='-lpthread -lm -latomic' \ 342 | --arch=armv7l \ 343 | --enable-shared \ 344 | --enable-libv4l2 \ 345 | --enable-libaom \ 346 | --enable-version3 \ 347 | --enable-gpl \ 348 | --enable-libass \ 349 | --enable-libdrm \ 350 | --enable-libfdk-aac \ 351 | --enable-libfreetype \ 352 | --enable-libkvazaar \ 353 | --enable-libmp3lame \ 354 | --enable-libopencore-amrnb \ 355 | --enable-libopencore-amrwb \ 356 | --enable-libopus \ 357 | --enable-librtmp \ 358 | --enable-libsnappy \ 359 | --enable-libsoxr \ 360 | --enable-libssh \ 361 | --enable-libvorbis \ 362 | --enable-libvpx \ 363 | --enable-libwebp \ 364 | --enable-libzimg \ 365 | --enable-libx264 \ 366 | --enable-libx265 \ 367 | --enable-libxml2 \ 368 | --enable-mmal \ 369 | --enable-nonfree \ 370 | --enable-omx \ 371 | --enable-omx-rpi \ 372 | --enable-version3 \ 373 | --target-os=linux \ 374 | --enable-pthreads \ 375 | --enable-openssl \ 376 | --enable-hardcoded-tables \ 377 | && make -j$(nproc) \ 378 | && sudo make install 379 | } 380 | 381 | get_and_build_obs() { 382 | echo "${YELLOW}" 383 | echo "-----------------------------------" 384 | echo "Get and build OBS Studio ${OBS_TAG}" 385 | echo "-----------------------------------" 386 | echo "${DEFAULT}" 387 | git clone --recursive https://github.com/obsproject/obs-studio.git "${TMPDIR}/OBS" && cd "${TMPDIR}/OBS" \ 388 | && mkdir build32 && cd build32 \ 389 | && cmake -DENABLE_NEW_MPEGTS_OUTPUT=OFF -DENABLE_BROWSER=OFF -DUNIX_STRUCTURE=1 -DCMAKE_INSTALL_PREFIX=/usr .. \ 390 | && make -j4 \ 391 | && sudo make install \ 392 | && sudo ldconfig 393 | } 394 | 395 | main() { 396 | clear 397 | print_info 398 | check_os_version 399 | install_dependencies 400 | get_and_build_pipewire 401 | get_and_build_libfdk_aac 402 | get_and_build_libdav1d 403 | get_and_build_libkvazaar 404 | get_and_build_libvpx 405 | get_and_build_libaom 406 | get_and_build_zimg 407 | get_and_build_x264 408 | get_and_build_gstreamer 409 | sudo ldconfig 410 | get_and_build_ffmpeg 411 | get_and_build_obs 412 | get_and_build_obs_gstreamer 413 | sudo ldconfig 414 | cleanup 415 | } 416 | 417 | time main 418 | 419 | cd $cwd 420 | 421 | echo "${YELLOW}" 422 | echo "All done!" 423 | echo "Cross your fingers and run ./launch_OBS.sh script to launch OBS" 424 | echo "${DEFAULT}" 425 | exit 0 426 | -------------------------------------------------------------------------------- /launch_OBS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libGL.so 4 | MESA_GL_VERSION_OVERRIDE=3.3 obs 5 | --------------------------------------------------------------------------------