diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98aa39b..c707115 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,20 +2,24 @@ name: Test builds on various OS and configurations on: pull_request: - branches: [ main ] + branches: [main] env: BRANCH_NAME: ${{ github.event.pull_request.head.ref }} - + jobs: test_build: strategy: matrix: - os: [ubuntu-latest, macos-latest, ARM] - max-jobs: [3] - libfdk-aac: [y, n] + os: [ubuntu-latest, macos-latest] + max-jobs: [4, 4] + mode: [8, 8] + libx265: [y, y] + libopus: [y, y] + libvpx: [y, y] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Build - run: bash build-bootstrap.sh --interactive n --mode 4 --max-jobs ${{ matrix.max-jobs }} --libfdk-aac ${{ matrix.libfdk-aac }} --h264-omx n + run: bash build-bootstrap.sh --none-interactive --mode ${{ matrix.mode }} --max-jobs ${{ matrix.max-jobs }} --libx265 ${{ matrix.libx265 }} --libopus ${{ matrix.libopus }} --libvpx ${{ matrix.libvpx }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bea433 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/Menu1.png b/Menu1.png index a9b9a50..1dc4a6e 100644 Binary files a/Menu1.png and b/Menu1.png differ diff --git a/README.md b/README.md index 37bd41e..635f1d8 100644 --- a/README.md +++ b/README.md @@ -9,39 +9,31 @@ Highlights - 32 and 64 bit support - libfdk-aac (Installed via the platform's package manager, or will build from source as a fallback if not available) - libx264 (Installed via the platform's package manager, or will build from source as a fallback if not available) -- h264_omx (32Bit only, Raspberry Pi only, deprecated) +- libx265 (Installed via the platform's package manager, or will build from source as a fallback if not available) +- libvpx (Installed via the platform's package manager, or will build from source as a fallback if not available) +- libopus (Installed via the platform's package manager, or will build from source as a fallback if not available) - h264_v4l2m2m (replaces h264_omx) - Ability to add extra compile flags - Automate with command line arguments. -Tested systems +Tested Environments - **Alpine** - - Apple M1 (Virtual) (64 Bit) - - Raspberry Pi 3B (32 Bit) -- **Bullseye** - - Raspberry Pi Zero W1 (32 Bit) - - Raspberry Pi Zero W2 (64 Bit) - - Raspberry Pi 4 (64 Bit) - - Raspberry Pi 3A+ (64 Bit) + - 64Bit ARM (VMware Fusion, Apple M1) -- **Buster** - - Raspberry Pi 4 (32 Bit) - - Raspberry Pi 3B+ (32 Bit) - - Raspberry Pi 3B (32 Bit) - -- **macOS Monterey** - - Apple M1 (64 Bit) - -- **Ubuntu** - - Intel (64 Bit) - - Apple M1 (Virtual) (64 Bit) +- **RPI Bullseye** + - 64Bit ARM (RPI Zero W2) +- **macOS Ventura** + - 64Bit ARM (Apple Mac Mini M1) +- **Ubuntu** + - 64Bit ARM (VMware Fusion, Apple M1) + - 64Bit AMD/INTEL ![image](./Menu1.png) @@ -49,16 +41,14 @@ Tested systems Copy the below and paste it in your terminal. -Note: If your OS is Alpine, install curl and bash first. +Note: If your OS is Alpine, install `curl` and `bash` first. + ``` apk add curl bash ``` + Then ``` bash <(curl -sL https://raw.githubusercontent.com/NRCHKB/nrchkb-ffmpeg-build/main/build-bootstrap.sh) ``` - - - - diff --git a/build-alpine.sh b/build-alpine.sh index 0eed22f..503ef40 100755 --- a/build-alpine.sh +++ b/build-alpine.sh @@ -1,6 +1,6 @@ #!/bin/bash -# nrchkb-ffmpeg-build Version 1.1 +# nrchkb-ffmpeg-build Version 2.0 # MIT License @@ -32,16 +32,30 @@ End=$'\e[0m' # Defaults JOBS=3 # Jobs Value -JOBSPARAM=false # Arg provided -OMX="n" # OMX Choice Value -OMXPARAM=false # Arg provided +JOBS_PARAM=false # Arg provided + FDK="y" # FDK Choice Value -FDKPARAM=false # Arg provided +FDK_PARAM=false # Arg provided + +L264="y" # 264 Choice Value +L264_PARAM=false # Arg provided + +L265="n" # 265 Choice Value +L265_PARAM=false # Arg provided + +LVPX="n" # VPX Choice Value +LVPX_PARAM=false # Arg provided + +LOPUS="n" # Opus Choice Value +LOPUS_PARAM=false # Arg provided + FLAGSYN="n" # Flags Choice Value FLAGS="" # Flasg Value -FLAGSPARAM=false # Arg provided +FLAGS_PARAM=false # Arg provided + MODE=0 # Mode Value -MODEPARAM=false # Arg provided +MODE_PARAM=false # Arg provided + INTERACTIVE="y" # Interactive # Prefix @@ -49,6 +63,9 @@ PREFIX="/usr/local" export LDFLAGS="-L$PREFIX/lib" export CFLAGS="-I$PREFIX/include" +# Ignore Repository sources +FORCE_BUILD=false + # Specific package manager implemention INSTALL() { apk add $@ @@ -60,19 +77,26 @@ CHECK() { apk info $1 } +# Package Names +DEP_X264="x264-dev" +DEP_X265="x265-dev" +DEP_VPX="libvpx-dev" +DEP_OPUS="opus-dev" +DEP_AAC="fdk-aac-dev" + # Print Header printHeader() { printf "\033c" echo echo " ---------------------------------------------------------" - echo " | 1.1 |" + echo " | 2.0 |" echo " | P&M FFmpeg Build Script (Alpine) |" echo " | An FFmpeg build & installation utility for NRCHKB |" echo " | |" echo " ---------------------------------------------------------" echo - echo " ${Red}Note: This script will install into $PREFIX/bin and $PREFIX/lib respectively.${End}" + echo " ${Yellow}Note: This script will install into $PREFIX/bin and $PREFIX/lib respectively.${End}" echo } @@ -82,17 +106,24 @@ menu() { echo " ${Yellow}What would you like to do:${End}" echo - echo " 1 - Install build tools (dependencies from apk)" - echo " 2 - Build/install libfdk-aac (AAC encoder, needed for HomeKit audio)" - echo " 3 - Build/install FFmpeg (video processor, builds from source)" - echo " 4 - All of the above" - echo " 5 - Cleanup build directories" + echo " 1 - Install build tools (Dependencies from apt)" + echo " 2 - Build/install libfdk-aac (AAC Audio Encoder)" + echo " 3 - Build/install libx264 (x264 Video Encoder)" + echo " 4 - Build/install libx265 (x265 Video Encoder)" + echo " 5 - Build/install libvpx (VP8/VP9 video Encoder/Decoder)" + echo " 6 - Build/install libopus (Opus Audio Encoder/Decoder)" + echo " 7 - Build FFmpeg (Builds from source only)" + echo " 8 - Guided Install" + echo " 9 - Purge build directories" echo " q - Quit" echo - echo " Note: this script will download and compile these software packages from source code." - echo " This will take a long time. Option 4 will take over 6 hours on a Pi Zero W." + echo " Note: This script will download and compile these software packages from source code," + echo " unless they happen to be available from your systems repository." + echo " Where necessary, libaries will be built as shared libs." + echo + echo " This excludes FFMPEG which will always be built for source." echo - echo " If you have previously run this script, running it again will update your software." + echo " If you have previously run this script, running it again will update your software." echo printf " Choice: " read -r @@ -102,7 +133,7 @@ menu() { MODE=$REPLY - if [[ $MODE -gt 5 || $MODE -lt 1 ]]; then + if [[ $MODE -gt 8 || $MODE -lt 1 ]]; then printHeader menu fi @@ -135,24 +166,13 @@ installDependencies() { echo " | |" echo " ---------------------------------------------------------" echo - INSTALL pkgconfig autoconf automake libtool git wget make g++ gcc nasm yasm - - CHECK x264-dev - - if [[ $? -gt 0 ]]; then - installLibx264 - else - INSTALL x264-dev - fi + INSTALL pkgconfig autoconf automake libtool git wget make g++ gcc nasm yasm build-base cmake diffutils } # Install Libx264 installLibx264() { - cd ~ || { - echo "cd failed, aborting at installLibx264:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -160,31 +180,65 @@ installLibx264() { echo " | |" echo " ---------------------------------------------------------" echo - REMOVE x264-dev + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_X264 + if [[ $? = 0 ]]; then + INSTALL $DEP_X264 + return + fi + fi + + + REMOVE $DEP_X264 git clone https://code.videolan.org/videolan/x264.git - cd x264 || { - echo "cd failed, aborting at installLibx264:02" - exit 1 - } - ./configure --prefix=$PREFIX --enable-static --enable-pic + cd x264 + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic checkForError make -j"$JOBS" checkForError make install checkForError ldconfig - cd ~ || { - echo "cd failed, aborting at installLibx264:03" - exit 1 - } + cd ~ +} + +# Install Libx265 +installLibx265() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libx265 |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_X265 + if [[ $? = 0 ]]; then + INSTALL $DEP_X265 + return + fi + fi + + + REMOVE $DEP_X265 + git clone https://bitbucket.org/multicoreware/x265_git.git + cd x265_git/build/linux + cmake -G "Unix Makefiles" -DLIB_INSTALL_DIR="$PREFIX/lib" -DENABLE_SHARED=on -DENABLE_PIC=on ../../source + checkForError + make -j"$JOBS" + checkForError + make install + checkForError + ldconfig + cd ~ } # Install Libfdk installLibfdk() { - cd ~ || { - echo "cd failed, aborting at installLibfdk:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -193,38 +247,97 @@ installLibfdk() { echo " ---------------------------------------------------------" echo - CHECK fdk-aac-dev - if [[ $? = 0 ]]; then - apk add fdk-aac-dev - return + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_AAC + if [[ $? = 0 ]]; then + INSTALL $DEP_AAC + return + fi fi - REMOVE fdk-aac-dev + REMOVE $DEP_AAC git clone https://github.com/mstorsjo/fdk-aac.git - cd fdk-aac || { - echo "cd failed, aborting at installLibfdk:02" - exit 1 - } + cd fdk-aac ./autogen.sh - ./configure --prefix=$PREFIX --enable-static --disable-shared + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic checkForError make -j"$JOBS" checkForError make install checkForError ldconfig - cd ~ || { - echo "cd failed, aborting at installLibfdk:03" - exit 1 - } + cd ~ +} + +# Install VPX +installLibvpx() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libvpx-dev |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_VPX + if [[ $? = 0 ]]; then + INSTALL $DEP_VPX + return + fi + fi + + REMOVE $DEP_VPX + git clone https://chromium.googlesource.com/webm/libvpx.git + cd libvpx + ./autogen.sh + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm + checkForError + make -j"$JOBS" + checkForError + make install + checkForError + ldconfig + cd ~ +} + +# Install VPX +installLibopus() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libopus-dev |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_OPUS + if [[ $? = 0 ]]; then + INSTALL $DEP_OPUS + return + fi + fi + + REMOVE $DEP_OPUS + git clone https://github.com/xiph/opus.git + cd opus + ./autogen.sh + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic + checkForError + make -j"$JOBS" + checkForError + make install + checkForError + ldconfig + cd ~ } # Install FFmpeg installFFmpeg() { - cd ~ || { - echo "cd failed, aborting at installFFmpeg:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -236,37 +349,43 @@ installFFmpeg() { wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 echo "Extracting source code..." tar xjf ffmpeg-snapshot.tar.bz2 - cd ffmpeg || { - echo "cd failed, aborting at installFFmpeg:02" - exit 1 - } + cd ffmpeg + - CMD="--prefix=$PREFIX --enable-nonfree --enable-gpl --enable-hardcoded-tables --disable-ffprobe --disable-ffplay --enable-libx264" + CMD="--prefix=$PREFIX --enable-nonfree --enable-gpl --disable-ffprobe --disable-ffplay --enable-pic --disable-static --enable-shared" if [[ "$FDK" = "y" ]]; then CMD="$CMD --enable-libfdk-aac" fi - if [[ "$OMX" = "y" ]]; then - CMD="$CMD --enable-mmal" - CMD="$CMD --enable-omx" - CMD="$CMD --enable-omx-rpi" + if [[ "$L264" = "y" ]]; then + CMD="$CMD --enable-libx264" + fi + + if [[ "$L265" = "y" ]]; then + CMD="$CMD --enable-libx265" + fi + + if [[ "$LVPX" = "y" ]]; then + CMD="$CMD --enable-libvpx" + fi + + if [[ "$LOPUS" = "y" ]]; then + CMD="$CMD --enable-libopus" fi if [[ "$FLAGSYN" = "y" ]]; then CMD="$CMD $FLAGS" fi - ./configure $CMD + ./configure $CMD --extra-libs="-lpthread -lm" checkForError make -j"$JOBS" checkForError make install checkForError - cd ~ || { - echo "cd failed, aborting at installFFmpeg:03" - exit 1 - } + ldconfig + cd ~ } # Clear Up @@ -274,75 +393,55 @@ cleanDirectory() { rm -rf ffmpeg rm -rf fdk-aac rm -rf x264 + rm -rf x265_git + rm -rf libvpx + rm -rf opus rm -f ffmpeg-snapshot.tar.bz2 } # Ask for Threads getJobsCount() { - if [[ $JOBSPARAM = true || "$INTERACTIVE" = "n" ]]; then + if [[ $JOBS_PARAM = true || "$INTERACTIVE" = "n" ]]; then return fi echo - echo " ${Yellow}How many simultaneous jobs would you like to use for build processes (if needed)${End}" - echo - echo " The more you specify - the higher chance of CPU throttling and memory constraints" - printf " we recommend no more than 3 for a Pi 4 (1-4): " + printf " ${Yellow}How many simultaneous jobs would you like to use for build processes (if needed) Default: $JOBS (#):${End}" read -r - if [[ $REPLY -lt 5 && $REPLY -gt 0 ]]; then + if [[ $REPLY -gt 0 ]]; then JOBS=$REPLY fi } -# Ask for omx -getOMX() { +# getLib L264_PARAM L264 "libx264" +getLib(){ - if [[ $OMXPARAM = true || "$INTERACTIVE" = "n" ]]; then + + if [[ ${!1} = true || "$INTERACTIVE" = "n" ]]; then return fi - echo - echo " ${Yellow}Would you like to enable 'h264_omx'?${End}" - echo - echo " Note: 'h264_omx' is deprecated and should not be used on new installs." - printf " If you already use it, choose yes here. Enter (y/n): " + printf " ${Yellow}Would you like to enable '$3'? Default: ${!2} (y/n):${End}" read -r if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then - OMX="$REPLY" + eval $2="$REPLY" fi -} -# Ask for FDK -getFDK() { - - if [[ $FDKPARAM = true || "$INTERACTIVE" = "n" ]]; then - return - fi - - echo - echo " ${Yellow}Would you like to enable 'libfdk-aac'?${End}" - echo - echo " Note: 'libfdk-aac' is needed for HomeKit audio. We recommend enabling libfdk-aac." - printf " If you are running Option 4, you can enable this lib. Enter (y/n): " - read -r - if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then - FDK="$REPLY" - fi } # Get Compile Flags getFlags() { - if [[ $FLAGSPARAM = true || "$INTERACTIVE" = "n" ]]; then + if [[ $FLAGS_PARAM = true || "$INTERACTIVE" = "n" ]]; then return fi echo - echo " ${Yellow}Would you like to add any extra FFmpeg compile flags?" + echo " ${Yellow}Would you like to add any extra FFmpeg compile flags? Default: $FLAGSYN (y/n)" echo - echo " ADVANCED: ${End}Compile flags could be added to enable libx265 or the countless others" - printf " You are responsible for ensuring any required parts are installed (y/n): " + echo " ADVANCED: ${End}Compile flags could be added to the build process, to ensure ffmpeg is compiled with more features." + printf " You are responsible for ensuring any requied dev/header files are installed: " read -r if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then FLAGSYN="$REPLY" @@ -350,7 +449,7 @@ getFlags() { echo echo " ${Yellow}Please enter your compile flags below, separated by a space${End}" echo - printf " Example '--enable-libx265 --enable-libopus' : " + printf " Example: --enable-vaapi --enable-libvorbis : " read -r if [[ ${#REPLY} -gt 0 ]]; then FLAGS="$REPLY" @@ -388,7 +487,6 @@ processOptions() { case $1 in 1) - getJobsCount stopWatch "start" installDependencies stopWatch "stop" @@ -415,9 +513,57 @@ processOptions() { 3) getJobsCount - getOMX - getFDK - getFlags + stopWatch "start" + installLibx264 + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + 4) + getJobsCount + stopWatch "start" + installLibx265 + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 5) + getJobsCount + stopWatch "start" + installLibvpx + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 6) + getJobsCount + stopWatch "start" + installLibopus + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 7) + getJobsCount stopWatch "start" installFFmpeg stopWatch "stop" @@ -429,17 +575,31 @@ processOptions() { fi ;; - 4) - cleanDirectory + 8) getJobsCount - getOMX - getFDK + getLib FDK_PARAM FDK "libfdk-aac" + getLib L264_PARAM L264 "libx264" + getLib L265_PARAM L265 "libx265" + getLib LVPX_PARAM LVPX "libvpx" + getLib LOPUS_PARAM LOPUS "libopus" getFlags stopWatch "start" installDependencies if [[ "$FDK" = "y" ]]; then installLibfdk fi + if [[ "$L264" = "y" ]]; then + installLibx264 + fi + if [[ "$L265" = "y" ]]; then + installLibx265 + fi + if [[ "$LVPX" = "y" ]]; then + installLibvpx + fi + if [[ "$LOPUS" = "y" ]]; then + installLibopus + fi installFFmpeg cleanDirectory stopWatch "stop" @@ -451,7 +611,7 @@ processOptions() { fi ;; - 5) + 9) stopWatch "start" cleanDirectory stopWatch "stop" @@ -466,52 +626,67 @@ processOptions() { } # Entry Point -cd ~ || { - echo "cd failed, aborting" - exit 1 -} +cd ~ while [ $# -gt 0 ]; do case "$1" in - --help | -h) + --help) + printf "\033c" echo "Options:" echo - echo " --interactive -i [y|n] Default: y Disables interactive mode" - echo " --mode -m [1|2|3|4|5] Sets the mode (requires --interactive 0, ignored otherwise)" - echo " --max-jobs -j [#] Default: 3 Set maximum number of builds jobs" - echo " --libfdk-aac -a [y|n] Default: y Compile/enable libfdk-aac" - echo " --h264-omx -x [y|n] Default: n Enable h264-omx" - echo " --extra-flags -f [\"--*-* --*-*\"] Default: empty Provides compile flags for ffmpeg" - echo - echo " Example: ./build-debian.sh --interactive n --max-jobs 2 --mode 4" + echo " --force-build : Forces the build of required libs, regaldess of their availability with the systems repository sources" + echo " --none-interactive : Disables interactive mode" + echo " --mode [1-9] : Sets the operation. Requies --none-interactive" + echo " --max-jobs [1-#] Default: 3 : Sets the number of build threads" + echo " --libfdk-aac [y:n] Default: y : Enable/Disable this lib" + echo " --libx264 [y:n] Default: y : Enable/Disable this lib" + echo " --libx265 [y:n] Default: n : Enable/Disable this lib" + echo " --libopus [y:n] Default: n : Enable/Disable this lib" + echo " --libvpx [y:n] Default: n : Enable/Disable this lib" + echo " --extra-flags [*] Default: None : Adds extra build args to the ffmpeg build" echo exit 0 ;; - --interactive | -i) - INTERACTIVE="$2" + --force-build) + FORCE_BUILD=true + ;; + --none-interactive) + INTERACTIVE="n" ;; - --mode | -m) + --mode) MODE=$2 - MODEPARAM=true + MODE_PARAM=true ;; - --max-jobs | -j) + --max-jobs) JOBS=$2 - JOBSPARAM=true + JOBS_PARAM=true ;; - --h264-omx | -x) - OMX="$2" - OMXPARAM=true - ;; - --libfdk-aac | -a) + --libfdk-aac) FDK="$2" - FDKPARAM=true + FDK_PARAM=true + ;; + --libx264) + L264="$2" + L264_PARAM=true + ;; + --libx265) + L265="$2" + L265_PARAM=true + ;; + --libopus) + LOPUS="$2" + LOPUS_PARAM=true + ;; + --libvpx) + LVPX="$2" + LVPX_PARAM=true ;; - --extra-flags | -f) + --extra-flags) FLAGSYN="y" FLAGS="$2" - FLAGSPARAM=true + FLAGS_PARAM=true ;; esac shift diff --git a/build-bootstrap.sh b/build-bootstrap.sh index a21d7c5..0167cea 100755 --- a/build-bootstrap.sh +++ b/build-bootstrap.sh @@ -14,9 +14,10 @@ if [[ "$OSTYPE" == "darwin"* ]]; then bash <(curl -sL https://raw.githubusercontent.com/NRCHKB/nrchkb-ffmpeg-build/$BRANCH_NAME/build-osx.sh) "$@" else echo - echo " ----------------------------------------------------------------------------------------------------" - echo " | OSX environments require 'brew' to be installed, and for it to be included in the PATH variable. |" - echo " ----------------------------------------------------------------------------------------------------" + echo " ----------------------------------------------------------------------------------------" + echo " | OSX environments require 'brew' to be installed, |" + echo " | and for it's path to be included in the PATH variable'. |" + echo " ----------------------------------------------------------------------------------------" echo exit 0 fi diff --git a/build-debian.sh b/build-debian.sh index ca3545d..f56e1c2 100755 --- a/build-debian.sh +++ b/build-debian.sh @@ -1,6 +1,6 @@ #!/bin/bash -# nrchkb-ffmpeg-build Version 1.1 +# nrchkb-ffmpeg-build Version 2.0 # MIT License @@ -32,16 +32,30 @@ End=$'\e[0m' # Defaults JOBS=3 # Jobs Value -JOBSPARAM=false # Arg provided -OMX="n" # OMX Choice Value -OMXPARAM=false # Arg provided +JOBS_PARAM=false # Arg provided + FDK="y" # FDK Choice Value -FDKPARAM=false # Arg provided +FDK_PARAM=false # Arg provided + +L264="y" # 264 Choice Value +L264_PARAM=false # Arg provided + +L265="n" # 265 Choice Value +L265_PARAM=false # Arg provided + +LVPX="n" # VPX Choice Value +LVPX_PARAM=false # Arg provided + +LOPUS="n" # Opus Choice Value +LOPUS_PARAM=false # Arg provided + FLAGSYN="n" # Flags Choice Value FLAGS="" # Flasg Value -FLAGSPARAM=false # Arg provided +FLAGS_PARAM=false # Arg provided + MODE=0 # Mode Value -MODEPARAM=false # Arg provided +MODE_PARAM=false # Arg provided + INTERACTIVE="y" # Interactive # Prefix @@ -49,6 +63,9 @@ PREFIX="/usr/local" export LDFLAGS="-L$PREFIX/lib" export CFLAGS="-I$PREFIX/include" +# Ignore Repository sources +FORCE_BUILD=false + # Specific package manager implemention INSTALL() { sudo apt install -y $@ @@ -61,19 +78,26 @@ CHECK() { apt info $1 } +# Package Names +DEP_X264="libx264-dev" +DEP_X265="libx265-dev" +DEP_VPX="libvpx-dev" +DEP_OPUS="libopus-dev" +DEP_AAC="libfdk-aac-dev" + # Print Header printHeader() { printf "\033c" echo echo " ---------------------------------------------------------" - echo " | 1.1 |" + echo " | 2.0 |" echo " | P&M FFmpeg Build Script (Debian) |" echo " | An FFmpeg build & installation utility for NRCHKB |" echo " | |" echo " ---------------------------------------------------------" echo - echo " ${Red}Note: This script will install into $PREFIX/bin and $PREFIX/lib respectively.${End}" + echo " ${Yellow}Note: This script will install into $PREFIX/bin and $PREFIX/lib respectively.${End}" echo } @@ -83,17 +107,24 @@ menu() { echo " ${Yellow}What would you like to do:${End}" echo - echo " 1 - Install build tools (dependencies from apt)" - echo " 2 - Build/install libfdk-aac (AAC encoder, needed for HomeKit audio)" - echo " 3 - Build/install FFmpeg (video processor, builds from source)" - echo " 4 - All of the above" - echo " 5 - Cleanup build directories" + echo " 1 - Install build tools (Dependencies from apt)" + echo " 2 - Build/install libfdk-aac (AAC Audio Encoder)" + echo " 3 - Build/install libx264 (x264 Video Encoder)" + echo " 4 - Build/install libx265 (x265 Video Encoder)" + echo " 5 - Build/install libvpx (VP8/VP9 video Encoder/Decoder)" + echo " 6 - Build/install libopus (Opus Audio Encoder/Decoder)" + echo " 7 - Build FFmpeg (Builds from source only)" + echo " 8 - Guided Install" + echo " 9 - Purge build directories" echo " q - Quit" echo - echo " Note: this script will download and compile these software packages from source code." - echo " This will take a long time. Option 4 will take over 6 hours on a Pi Zero W." + echo " Note: This script will download and compile these software packages from source code," + echo " unless they happen to be available from your systems repository." + echo " Where necessary, libaries will be built as shared libs." + echo + echo " This excludes FFMPEG which will always be built for source." echo - echo " If you have previously run this script, running it again will update your software." + echo " If you have previously run this script, running it again will update your software." echo printf " Choice: " read -r @@ -103,7 +134,7 @@ menu() { MODE=$REPLY - if [[ $MODE -gt 5 || $MODE -lt 1 ]]; then + if [[ $MODE -gt 8 || $MODE -lt 1 ]]; then printHeader menu fi @@ -136,24 +167,13 @@ installDependencies() { echo " | |" echo " ---------------------------------------------------------" echo - INSTALL pkg-config autoconf automake libtool git wget make g++ gcc nasm yasm - - CHECK libx264-dev - - if [[ $? -gt 0 ]]; then - installLibx264 - else - INSTALL libx264-dev - fi + INSTALL pkg-config autoconf automake libtool git wget make g++ gcc nasm yasm build-essential cmake-curses-gui cmake } # Install Libx264 installLibx264() { - cd ~ || { - echo "cd failed, aborting at installLibx264:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -161,31 +181,65 @@ installLibx264() { echo " | |" echo " ---------------------------------------------------------" echo - REMOVE libx264-dev + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_X264 + if [[ $? = 0 ]]; then + INSTALL $DEP_X264 + return + fi + fi + + + REMOVE $DEP_X264 git clone https://code.videolan.org/videolan/x264.git - cd x264 || { - echo "cd failed, aborting at installLibx264:02" - exit 1 - } - ./configure --prefix=$PREFIX --enable-static --enable-pic + cd x264 + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic checkForError make -j"$JOBS" checkForError sudo make install checkForError sudo ldconfig - cd ~ || { - echo "cd failed, aborting at installLibx264:03" - exit 1 - } + cd ~ +} + +# Install Libx265 +installLibx265() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libx265 |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_X265 + if [[ $? = 0 ]]; then + INSTALL $DEP_X265 + return + fi + fi + + + REMOVE $DEP_X265 + git clone https://bitbucket.org/multicoreware/x265_git.git + cd x265_git/build/linux + cmake -G "Unix Makefiles" -DLIB_INSTALL_DIR="$PREFIX/lib" -DENABLE_SHARED=on -DENABLE_PIC=on ../../source + checkForError + make -j"$JOBS" + checkForError + sudo make install + checkForError + sudo ldconfig + cd ~ } # Install Libfdk installLibfdk() { - cd ~ || { - echo "cd failed, aborting at installLibfdk:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -194,38 +248,97 @@ installLibfdk() { echo " ---------------------------------------------------------" echo - CHECK libfdk-aac-dev - if [[ $? = 0 ]]; then - INSTALL libfdk-aac-dev - return + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_AAC + if [[ $? = 0 ]]; then + INSTALL $DEP_AAC + return + fi fi - REMOVE libfdk-aac-dev + REMOVE $DEP_AAC git clone https://github.com/mstorsjo/fdk-aac.git - cd fdk-aac || { - echo "cd failed, aborting at installLibfdk:02" - exit 1 - } + cd fdk-aac ./autogen.sh - ./configure --prefix=$PREFIX --enable-static --disable-shared + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic checkForError make -j"$JOBS" checkForError sudo make install checkForError sudo ldconfig - cd ~ || { - echo "cd failed, aborting at installLibfdk:03" - exit 1 - } + cd ~ +} + +# Install VPX +installLibvpx() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libvpx-dev |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_VPX + if [[ $? = 0 ]]; then + INSTALL $DEP_VPX + return + fi + fi + + REMOVE $DEP_VPX + git clone https://chromium.googlesource.com/webm/libvpx.git + cd libvpx + ./autogen.sh + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm + checkForError + make -j"$JOBS" + checkForError + sudo make install + checkForError + sudo ldconfig + cd ~ +} + +# Install VPX +installLibopus() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libopus-dev |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_OPUS + if [[ $? = 0 ]]; then + INSTALL $DEP_OPUS + return + fi + fi + + REMOVE $DEP_OPUS + git clone https://github.com/xiph/opus.git + cd opus + ./autogen.sh + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic + checkForError + make -j"$JOBS" + checkForError + sudo make install + checkForError + sudo ldconfig + cd ~ } # Install FFmpeg installFFmpeg() { - cd ~ || { - echo "cd failed, aborting at installFFmpeg:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -237,37 +350,43 @@ installFFmpeg() { wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 echo "Extracting source code..." tar xjf ffmpeg-snapshot.tar.bz2 - cd ffmpeg || { - echo "cd failed, aborting at installFFmpeg:02" - exit 1 - } + cd ffmpeg + - CMD="--prefix=$PREFIX --enable-nonfree --enable-gpl --enable-hardcoded-tables --disable-ffprobe --disable-ffplay --enable-libx264" + CMD="--prefix=$PREFIX --enable-nonfree --enable-gpl --disable-ffprobe --disable-ffplay --enable-pic --disable-static --enable-shared" if [[ "$FDK" = "y" ]]; then CMD="$CMD --enable-libfdk-aac" fi - if [[ "$OMX" = "y" ]]; then - CMD="$CMD --enable-mmal" - CMD="$CMD --enable-omx" - CMD="$CMD --enable-omx-rpi" + if [[ "$L264" = "y" ]]; then + CMD="$CMD --enable-libx264" + fi + + if [[ "$L265" = "y" ]]; then + CMD="$CMD --enable-libx265" + fi + + if [[ "$LVPX" = "y" ]]; then + CMD="$CMD --enable-libvpx" + fi + + if [[ "$LOPUS" = "y" ]]; then + CMD="$CMD --enable-libopus" fi if [[ "$FLAGSYN" = "y" ]]; then CMD="$CMD $FLAGS" fi - ./configure $CMD + ./configure $CMD --extra-libs="-lpthread -lm" checkForError make -j"$JOBS" checkForError sudo make install checkForError - cd ~ || { - echo "cd failed, aborting at installFFmpeg:03" - exit 1 - } + sudo ldconfig + cd ~ } # Clear Up @@ -275,75 +394,55 @@ cleanDirectory() { rm -rf ffmpeg rm -rf fdk-aac rm -rf x264 + rm -rf x265_git + rm -rf libvpx + rm -rf opus rm -f ffmpeg-snapshot.tar.bz2 } # Ask for Threads getJobsCount() { - if [[ $JOBSPARAM = true || "$INTERACTIVE" = "n" ]]; then + if [[ $JOBS_PARAM = true || "$INTERACTIVE" = "n" ]]; then return fi echo - echo " ${Yellow}How many simultaneous jobs would you like to use for build processes (if needed)${End}" - echo - echo " The more you specify - the higher chance of CPU throttling and memory constraints" - printf " we recommend no more than 3 for a Pi 4 (1-4): " + printf " ${Yellow}How many simultaneous jobs would you like to use for build processes (if needed) Default: $JOBS (#):${End}" read -r - if [[ $REPLY -lt 5 && $REPLY -gt 0 ]]; then + if [[ $REPLY -gt 0 ]]; then JOBS=$REPLY fi } -# Ask for omx -getOMX() { +# getLib L264_PARAM L264 "libx264" +getLib(){ - if [[ $OMXPARAM = true || "$INTERACTIVE" = "n" ]]; then + + if [[ ${!1} = true || "$INTERACTIVE" = "n" ]]; then return fi - echo - echo " ${Yellow}Would you like to enable 'h264_omx'?${End}" - echo - echo " Note: 'h264_omx' is deprecated and should not be used on new installs." - printf " If you already use it, choose yes here. Enter (y/n): " + printf " ${Yellow}Would you like to enable '$3'? Default: ${!2} (y/n):${End}" read -r if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then - OMX="$REPLY" + eval $2="$REPLY" fi -} -# Ask for FDK -getFDK() { - - if [[ $FDKPARAM = true || "$INTERACTIVE" = "n" ]]; then - return - fi - - echo - echo " ${Yellow}Would you like to enable 'libfdk-aac'?${End}" - echo - echo " Note: 'libfdk-aac' is needed for HomeKit audio. We recommend enabling libfdk-aac." - printf " If you are running Option 4, you can enable this lib. Enter (y/n): " - read -r - if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then - FDK="$REPLY" - fi } # Get Compile Flags getFlags() { - if [[ $FLAGSPARAM = true || "$INTERACTIVE" = "n" ]]; then + if [[ $FLAGS_PARAM = true || "$INTERACTIVE" = "n" ]]; then return fi echo - echo " ${Yellow}Would you like to add any extra FFmpeg compile flags?" + echo " ${Yellow}Would you like to add any extra FFmpeg compile flags? Default: $FLAGSYN (y/n)" echo - echo " ADVANCED: ${End}Compile flags could be added to enable libx265 or the countless others" - printf " You are responsible for ensuring any required parts are installed (y/n): " + echo " ADVANCED: ${End}Compile flags could be added to the build process, to ensure ffmpeg is compiled with more features." + printf " You are responsible for ensuring any requied dev/header files are installed: " read -r if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then FLAGSYN="$REPLY" @@ -351,7 +450,7 @@ getFlags() { echo echo " ${Yellow}Please enter your compile flags below, separated by a space${End}" echo - printf " Example '--enable-libx265 --enable-libopus' : " + printf " Example: --enable-vaapi --enable-libvorbis : " read -r if [[ ${#REPLY} -gt 0 ]]; then FLAGS="$REPLY" @@ -389,7 +488,6 @@ processOptions() { case $1 in 1) - getJobsCount stopWatch "start" installDependencies stopWatch "stop" @@ -416,9 +514,57 @@ processOptions() { 3) getJobsCount - getOMX - getFDK - getFlags + stopWatch "start" + installLibx264 + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + 4) + getJobsCount + stopWatch "start" + installLibx265 + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 5) + getJobsCount + stopWatch "start" + installLibvpx + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 6) + getJobsCount + stopWatch "start" + installLibopus + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 7) + getJobsCount stopWatch "start" installFFmpeg stopWatch "stop" @@ -430,17 +576,31 @@ processOptions() { fi ;; - 4) - cleanDirectory + 8) getJobsCount - getOMX - getFDK + getLib FDK_PARAM FDK "libfdk-aac" + getLib L264_PARAM L264 "libx264" + getLib L265_PARAM L265 "libx265" + getLib LVPX_PARAM LVPX "libvpx" + getLib LOPUS_PARAM LOPUS "libopus" getFlags stopWatch "start" installDependencies if [[ "$FDK" = "y" ]]; then installLibfdk fi + if [[ "$L264" = "y" ]]; then + installLibx264 + fi + if [[ "$L265" = "y" ]]; then + installLibx265 + fi + if [[ "$LVPX" = "y" ]]; then + installLibvpx + fi + if [[ "$LOPUS" = "y" ]]; then + installLibopus + fi installFFmpeg cleanDirectory stopWatch "stop" @@ -452,7 +612,7 @@ processOptions() { fi ;; - 5) + 9) stopWatch "start" cleanDirectory stopWatch "stop" @@ -467,52 +627,67 @@ processOptions() { } # Entry Point -cd ~ || { - echo "cd failed, aborting" - exit 1 -} +cd ~ while [ $# -gt 0 ]; do case "$1" in - --help | -h) + --help) + printf "\033c" echo "Options:" echo - echo " --interactive -i [y|n] Default: y Disables interactive mode" - echo " --mode -m [1|2|3|4|5] Sets the mode (requires --interactive 0, ignored otherwise)" - echo " --max-jobs -j [#] Default: 3 Set maximum number of builds jobs" - echo " --libfdk-aac -a [y|n] Default: y Compile/enable libfdk-aac" - echo " --h264-omx -x [y|n] Default: n Enable h264-omx" - echo " --extra-flags -f [\"--*-* --*-*\"] Default: empty Provides compile flags for ffmpeg" - echo - echo " Example: ./build-debian.sh --interactive n --max-jobs 2 --mode 4" + echo " --force-build : Forces the build of required libs, regaldess of their availability with the systems repository sources" + echo " --none-interactive : Disables interactive mode" + echo " --mode [1-9] : Sets the operation. Requies --none-interactive" + echo " --max-jobs [1-#] Default: 3 : Sets the number of build threads" + echo " --libfdk-aac [y:n] Default: y : Enable/Disable this lib" + echo " --libx264 [y:n] Default: y : Enable/Disable this lib" + echo " --libx265 [y:n] Default: n : Enable/Disable this lib" + echo " --libopus [y:n] Default: n : Enable/Disable this lib" + echo " --libvpx [y:n] Default: n : Enable/Disable this lib" + echo " --extra-flags [*] Default: None : Adds extra build args to the ffmpeg build" echo exit 0 ;; - --interactive | -i) - INTERACTIVE="$2" + --force-build) + FORCE_BUILD=true + ;; + --none-interactive) + INTERACTIVE="n" ;; - --mode | -m) + --mode) MODE=$2 - MODEPARAM=true + MODE_PARAM=true ;; - --max-jobs | -j) + --max-jobs) JOBS=$2 - JOBSPARAM=true + JOBS_PARAM=true ;; - --h264-omx | -x) - OMX="$2" - OMXPARAM=true - ;; - --libfdk-aac | -a) + --libfdk-aac) FDK="$2" - FDKPARAM=true + FDK_PARAM=true + ;; + --libx264) + L264="$2" + L264_PARAM=true + ;; + --libx265) + L265="$2" + L265_PARAM=true + ;; + --libopus) + LOPUS="$2" + LOPUS_PARAM=true + ;; + --libvpx) + LVPX="$2" + LVPX_PARAM=true ;; - --extra-flags | -f) + --extra-flags) FLAGSYN="y" FLAGS="$2" - FLAGSPARAM=true + FLAGS_PARAM=true ;; esac shift diff --git a/build-osx.sh b/build-osx.sh index 66cddd0..35dd766 100755 --- a/build-osx.sh +++ b/build-osx.sh @@ -1,6 +1,6 @@ #!/bin/bash -# nrchkb-ffmpeg-build Version 1.1 +# nrchkb-ffmpeg-build Version 2.0 # MIT License @@ -32,16 +32,30 @@ End=$'\e[0m' # Defaults JOBS=3 # Jobs Value -JOBSPARAM=false # Arg provided -OMX="n" # OMX Choice Value -OMXPARAM=false # Arg provided +JOBS_PARAM=false # Arg provided + FDK="y" # FDK Choice Value -FDKPARAM=false # Arg provided +FDK_PARAM=false # Arg provided + +L264="y" # 264 Choice Value +L264_PARAM=false # Arg provided + +L265="n" # 265 Choice Value +L265_PARAM=false # Arg provided + +LVPX="n" # VPX Choice Value +LVPX_PARAM=false # Arg provided + +LOPUS="n" # Opus Choice Value +LOPUS_PARAM=false # Arg provided + FLAGSYN="n" # Flags Choice Value FLAGS="" # Flasg Value -FLAGSPARAM=false # Arg provided +FLAGS_PARAM=false # Arg provided + MODE=0 # Mode Value -MODEPARAM=false # Arg provided +MODE_PARAM=false # Arg provided + INTERACTIVE="y" # Interactive # Prefix @@ -49,6 +63,9 @@ PREFIX="/usr/local" export LDFLAGS="-L$PREFIX/lib" export CFLAGS="-I$PREFIX/include" +# Ignore Repository sources +FORCE_BUILD=false + # Specific package manager implemention INSTALL() { brew install $@ @@ -60,19 +77,26 @@ CHECK() { brew info $1 } +# Package Names +DEP_X264="x264" +DEP_X265="x265" +DEP_VPX="libvpx" +DEP_OPUS="opus" +DEP_AAC="fdk-aac" + # Print Header printHeader() { printf "\033c" echo echo " ---------------------------------------------------------" - echo " | 1.1 |" - echo " | P&M FFmpeg Build Script (OSX) |" + echo " | 2.0 |" + echo " | P&M FFmpeg Build Script (OSX) |" echo " | An FFmpeg build & installation utility for NRCHKB |" echo " | |" echo " ---------------------------------------------------------" echo - echo " ${Red}Note: This script will install into $PREFIX/bin and $PREFIX/lib respectively.${End}" + echo " ${Yellow}Note: This script will install into $PREFIX/bin and $PREFIX/lib respectively.${End}" echo } @@ -82,17 +106,24 @@ menu() { echo " ${Yellow}What would you like to do:${End}" echo - echo " 1 - Install build tools (dependencies from brew)" - echo " 2 - Build/install libfdk-aac (AAC encoder, needed for HomeKit audio)" - echo " 3 - Build/install FFmpeg (video processor, builds from source)" - echo " 4 - All of the above" - echo " 5 - Cleanup build directories" + echo " 1 - Install build tools (Dependencies from apt)" + echo " 2 - Build/install libfdk-aac (AAC Audio Encoder)" + echo " 3 - Build/install libx264 (x264 Video Encoder)" + echo " 4 - Build/install libx265 (x265 Video Encoder)" + echo " 5 - Build/install libvpx (VP8/VP9 video Encoder/Decoder)" + echo " 6 - Build/install libopus (Opus Audio Encoder/Decoder)" + echo " 7 - Build FFmpeg (Builds from source only)" + echo " 8 - Guided Install" + echo " 9 - Purge build directories" echo " q - Quit" echo - echo " Note: this script will download and compile these software packages from source code." - echo " This will take a long time. Option 4 will take over 6 hours on a Pi Zero W." + echo " Note: This script will download and compile these software packages from source code," + echo " unless they happen to be available from your systems repository." + echo " Where necessary, libaries will be built as shared libs." + echo + echo " This excludes FFMPEG which will always be built for source." echo - echo " If you have previously run this script, running it again will update your software." + echo " If you have previously run this script, running it again will update your software." echo printf " Choice: " read -r @@ -102,7 +133,7 @@ menu() { MODE=$REPLY - if [[ $MODE -gt 5 || $MODE -lt 1 ]]; then + if [[ $MODE -gt 8 || $MODE -lt 1 ]]; then printHeader menu fi @@ -135,24 +166,13 @@ installDependencies() { echo " | |" echo " ---------------------------------------------------------" echo - INSTALL pkg-config autoconf automake libtool git wget make nasm yasm - - CHECK x264 - - if [[ $? -gt 0 ]]; then - installLibx264 - else - INSTALL x264 - fi + INSTALL pkg-config autoconf automake libtool git wget make gcc nasm yasm cmake } # Install Libx264 installLibx264() { - cd ~ || { - echo "cd failed, aborting at installLibx264:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -160,30 +180,65 @@ installLibx264() { echo " | |" echo " ---------------------------------------------------------" echo - REMOVE x264 + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_X264 + if [[ $? = 0 ]]; then + INSTALL $DEP_X264 + return + fi + fi + + + REMOVE $DEP_X264 git clone https://code.videolan.org/videolan/x264.git - cd x264 || { - echo "cd failed, aborting at installLibx264:02" - exit 1 - } - ./configure --prefix=$PREFIX --enable-static --enable-pic + cd x264 + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic checkForError make -j"$JOBS" checkForError sudo make install checkForError - cd ~ || { - echo "cd failed, aborting at installLibx264:03" - exit 1 - } + sudo ldconfig + cd ~ +} + +# Install Libx265 +installLibx265() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libx265 |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_X265 + if [[ $? = 0 ]]; then + INSTALL $DEP_X265 + return + fi + fi + + + REMOVE $DEP_X265 + git clone https://bitbucket.org/multicoreware/x265_git.git + cd x265_git/build/xcode + cmake -G "Unix Makefiles" -DLIB_INSTALL_DIR="$PREFIX/lib" -DENABLE_SHARED=on -DENABLE_PIC=on ../../source + checkForError + make -j"$JOBS" + checkForError + sudo make install + checkForError + sudo ldconfig + cd ~ } # Install Libfdk installLibfdk() { - cd ~ || { - echo "cd failed, aborting at installLibfdk:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -192,37 +247,97 @@ installLibfdk() { echo " ---------------------------------------------------------" echo - CHECK fdk-aac - if [[ $? = 0 ]]; then - INSTALL fdk-aac - return + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_AAC + if [[ $? = 0 ]]; then + INSTALL $DEP_AAC + return + fi fi - REMOVE fdk-aac + REMOVE $DEP_AAC git clone https://github.com/mstorsjo/fdk-aac.git - cd fdk-aac || { - echo "cd failed, aborting at installLibfdk:02" - exit 1 - } + cd fdk-aac ./autogen.sh - ./configure --prefix=$PREFIX --enable-static --disable-shared + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic checkForError make -j"$JOBS" checkForError sudo make install checkForError - cd ~ || { - echo "cd failed, aborting at installLibfdk:03" - exit 1 - } + sudo ldconfig + cd ~ +} + +# Install VPX +installLibvpx() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libvpx-dev |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_VPX + if [[ $? = 0 ]]; then + INSTALL $DEP_VPX + return + fi + fi + + REMOVE $DEP_VPX + git clone https://chromium.googlesource.com/webm/libvpx.git + cd libvpx + ./autogen.sh + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm + checkForError + make -j"$JOBS" + checkForError + sudo make install + checkForError + sudo ldconfig + cd ~ +} + +# Install VPX +installLibopus() { + cd ~ + echo + echo " ---------------------------------------------------------" + echo " | |" + echo " | Building/Installing libopus-dev |" + echo " | |" + echo " ---------------------------------------------------------" + echo + + if [[ $FORCE_BUILD = false ]]; then + CHECK $DEP_OPUS + if [[ $? = 0 ]]; then + INSTALL $DEP_OPUS + return + fi + fi + + REMOVE $DEP_OPUS + git clone https://github.com/xiph/opus.git + cd opus + ./autogen.sh + ./configure --prefix=$PREFIX --disable-static --enable-shared --enable-pic + checkForError + make -j"$JOBS" + checkForError + sudo make install + checkForError + sudo ldconfig + cd ~ } # Install FFmpeg installFFmpeg() { - cd ~ || { - echo "cd failed, aborting at installFFmpeg:01" - exit 1 - } + cd ~ echo echo " ---------------------------------------------------------" echo " | |" @@ -234,37 +349,43 @@ installFFmpeg() { wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 echo "Extracting source code..." tar xjf ffmpeg-snapshot.tar.bz2 - cd ffmpeg || { - echo "cd failed, aborting at installFFmpeg:02" - exit 1 - } + cd ffmpeg + - CMD="--prefix=$PREFIX --enable-nonfree --enable-gpl --enable-hardcoded-tables --disable-ffprobe --disable-ffplay --enable-libx264" + CMD="--prefix=$PREFIX --enable-nonfree --enable-gpl --disable-ffprobe --disable-ffplay --enable-pic --disable-static --enable-shared" if [[ "$FDK" = "y" ]]; then CMD="$CMD --enable-libfdk-aac" fi - if [[ "$OMX" = "y" ]]; then - CMD="$CMD --enable-mmal" - CMD="$CMD --enable-omx" - CMD="$CMD --enable-omx-rpi" + if [[ "$L264" = "y" ]]; then + CMD="$CMD --enable-libx264" + fi + + if [[ "$L265" = "y" ]]; then + CMD="$CMD --enable-libx265" + fi + + if [[ "$LVPX" = "y" ]]; then + CMD="$CMD --enable-libvpx" + fi + + if [[ "$LOPUS" = "y" ]]; then + CMD="$CMD --enable-libopus" fi if [[ "$FLAGSYN" = "y" ]]; then CMD="$CMD $FLAGS" fi - ./configure $CMD + ./configure $CMD --extra-libs="-lpthread -lm" checkForError make -j"$JOBS" checkForError sudo make install checkForError - cd ~ || { - echo "cd failed, aborting at installFFmpeg:03" - exit 1 - } + sudo ldconfig + cd ~ } # Clear Up @@ -272,75 +393,55 @@ cleanDirectory() { rm -rf ffmpeg rm -rf fdk-aac rm -rf x264 + rm -rf x265_git + rm -rf libvpx + rm -rf opus rm -f ffmpeg-snapshot.tar.bz2 } # Ask for Threads getJobsCount() { - if [[ $JOBSPARAM = true || "$INTERACTIVE" = "n" ]]; then + if [[ $JOBS_PARAM = true || "$INTERACTIVE" = "n" ]]; then return fi echo - echo " ${Yellow}How many simultaneous jobs would you like to use for build processes (if needed)${End}" - echo - echo " The more you specify - the higher chance of CPU throttling and memory constraints" - printf " we recommend no more than 3 for a Pi 4 (1-4): " + printf " ${Yellow}How many simultaneous jobs would you like to use for build processes (if needed) Default: $JOBS (#):${End}" read -r - if [[ $REPLY -lt 5 && $REPLY -gt 0 ]]; then + if [[ $REPLY -gt 0 ]]; then JOBS=$REPLY fi } -# Ask for omx -getOMX() { +# getLib L264_PARAM L264 "libx264" +getLib(){ - if [[ $OMXPARAM = true || "$INTERACTIVE" = "n" ]]; then + + if [[ ${!1} = true || "$INTERACTIVE" = "n" ]]; then return fi - echo - echo " ${Yellow}Would you like to enable 'h264_omx'?${End}" - echo - echo " Note: 'h264_omx' is deprecated and should not be used on new installs." - printf " If you already use it, choose yes here. Enter (y/n): " + printf " ${Yellow}Would you like to enable '$3'? Default: ${!2} (y/n):${End}" read -r if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then - OMX="$REPLY" - fi -} - -# Ask for FDK -getFDK() { - - if [[ $FDKPARAM = true || "$INTERACTIVE" = "n" ]]; then - return + eval $2="$REPLY" fi - echo - echo " ${Yellow}Would you like to enable 'libfdk-aac'?${End}" - echo - echo " Note: 'libfdk-aac' is needed for HomeKit audio. We recommend enabling libfdk-aac." - printf " If you are running Option 4, you can enable this lib. Enter (y/n): " - read -r - if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then - FDK="$REPLY" - fi } # Get Compile Flags getFlags() { - if [[ $FLAGSPARAM = true || "$INTERACTIVE" = "n" ]]; then + if [[ $FLAGS_PARAM = true || "$INTERACTIVE" = "n" ]]; then return fi echo - echo " ${Yellow}Would you like to add any extra FFmpeg compile flags?" + echo " ${Yellow}Would you like to add any extra FFmpeg compile flags? Default: $FLAGSYN (y/n)" echo - echo " ADVANCED: ${End}Compile flags could be added to enable libx265 or the countless others" - printf " You are responsible for ensuring any required parts are installed (y/n): " + echo " ADVANCED: ${End}Compile flags could be added to the build process, to ensure ffmpeg is compiled with more features." + printf " You are responsible for ensuring any requied dev/header files are installed: " read -r if [[ "$REPLY" = "y" || "$REPLY" = "n" ]]; then FLAGSYN="$REPLY" @@ -348,7 +449,7 @@ getFlags() { echo echo " ${Yellow}Please enter your compile flags below, separated by a space${End}" echo - printf " Example '--enable-libx265 --enable-libopus' : " + printf " Example: --enable-vaapi --enable-libvorbis : " read -r if [[ ${#REPLY} -gt 0 ]]; then FLAGS="$REPLY" @@ -386,7 +487,6 @@ processOptions() { case $1 in 1) - getJobsCount stopWatch "start" installDependencies stopWatch "stop" @@ -413,9 +513,57 @@ processOptions() { 3) getJobsCount - getOMX - getFDK - getFlags + stopWatch "start" + installLibx264 + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + 4) + getJobsCount + stopWatch "start" + installLibx265 + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 5) + getJobsCount + stopWatch "start" + installLibvpx + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 6) + getJobsCount + stopWatch "start" + installLibopus + stopWatch "stop" + if [ "$INTERACTIVE" = "y" ]; then + echo " ${Yellow}All Done!${End} ...press enter" + read -r + printHeader + menu + fi + ;; + + 7) + getJobsCount stopWatch "start" installFFmpeg stopWatch "stop" @@ -427,17 +575,31 @@ processOptions() { fi ;; - 4) - cleanDirectory + 8) getJobsCount - getOMX - getFDK + getLib FDK_PARAM FDK "libfdk-aac" + getLib L264_PARAM L264 "libx264" + getLib L265_PARAM L265 "libx265" + getLib LVPX_PARAM LVPX "libvpx" + getLib LOPUS_PARAM LOPUS "libopus" getFlags stopWatch "start" installDependencies if [[ "$FDK" = "y" ]]; then installLibfdk fi + if [[ "$L264" = "y" ]]; then + installLibx264 + fi + if [[ "$L265" = "y" ]]; then + installLibx265 + fi + if [[ "$LVPX" = "y" ]]; then + installLibvpx + fi + if [[ "$LOPUS" = "y" ]]; then + installLibopus + fi installFFmpeg cleanDirectory stopWatch "stop" @@ -449,7 +611,7 @@ processOptions() { fi ;; - 5) + 9) stopWatch "start" cleanDirectory stopWatch "stop" @@ -464,52 +626,67 @@ processOptions() { } # Entry Point -cd ~ || { - echo "cd failed, aborting" - exit 1 -} +cd ~ while [ $# -gt 0 ]; do case "$1" in - --help | -h) + --help) + printf "\033c" echo "Options:" echo - echo " --interactive -i [y|n] Default: y Disables interactive mode" - echo " --mode -m [1|2|3|4|5] Sets the mode (requires --interactive 0, ignored otherwise)" - echo " --max-jobs -j [#] Default: 3 Set maximum number of builds jobs" - echo " --libfdk-aac -a [y|n] Default: y Compile/enable libfdk-aac" - echo " --h264-omx -x [y|n] Default: n Enable h264-omx" - echo " --extra-flags -f [\"--*-* --*-*\"] Default: empty Provides compile flags for ffmpeg" - echo - echo " Example: ./build-debian.sh --interactive n --max-jobs 2 --mode 4" + echo " --force-build : Forces the build of required libs, regaldess of their availability with the systems repository sources" + echo " --none-interactive : Disables interactive mode" + echo " --mode [1-9] : Sets the operation. Requies --none-interactive" + echo " --max-jobs [1-#] Default: 3 : Sets the number of build threads" + echo " --libfdk-aac [y:n] Default: y : Enable/Disable this lib" + echo " --libx264 [y:n] Default: y : Enable/Disable this lib" + echo " --libx265 [y:n] Default: n : Enable/Disable this lib" + echo " --libopus [y:n] Default: n : Enable/Disable this lib" + echo " --libvpx [y:n] Default: n : Enable/Disable this lib" + echo " --extra-flags [*] Default: None : Adds extra build args to the ffmpeg build" echo exit 0 ;; - --interactive | -i) - INTERACTIVE="$2" + --force-build) + FORCE_BUILD=true + ;; + --none-interactive) + INTERACTIVE="n" ;; - --mode | -m) + --mode) MODE=$2 - MODEPARAM=true + MODE_PARAM=true ;; - --max-jobs | -j) + --max-jobs) JOBS=$2 - JOBSPARAM=true + JOBS_PARAM=true ;; - --h264-omx | -x) - OMX="$2" - OMXPARAM=true - ;; - --libfdk-aac | -a) + --libfdk-aac) FDK="$2" - FDKPARAM=true + FDK_PARAM=true + ;; + --libx264) + L264="$2" + L264_PARAM=true + ;; + --libx265) + L265="$2" + L265_PARAM=true + ;; + --libopus) + LOPUS="$2" + LOPUS_PARAM=true + ;; + --libvpx) + LVPX="$2" + LVPX_PARAM=true ;; - --extra-flags | -f) + --extra-flags) FLAGSYN="y" FLAGS="$2" - FLAGSPARAM=true + FLAGS_PARAM=true ;; esac shift