Skip to content

Instantly share code, notes, and snippets.

@cr-chsn1
Last active January 30, 2024 22:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cr-chsn1/99492a6466528efe0f20cf217998eeec to your computer and use it in GitHub Desktop.
Save cr-chsn1/99492a6466528efe0f20cf217998eeec to your computer and use it in GitHub Desktop.
Raspberry Pi setup script for x264 Benchmark
#!/bin/bash
echo
echo "###################################"
echo "### ###"
echo "### x264 Benchmark ###"
echo "### Raspberry Pi setup script ###"
echo "### ###"
echo "###################################"
echo
echo "Original script by GrandAdmiralThrawn, edited by cr_chsn1"
###########################
# Setup build environment #
###########################
# Local build directories
build_ffmpeg_dir="${HOME}/ffmpeg"
build_x264_dir="${HOME}/x264"
# Source URLs
url_ffmpeg_git='https://git.ffmpeg.org/ffmpeg.git'
url_x264_git='https://code.videolan.org/videolan/x264.git'
url_benchmark_tool_100='https://www.raspiced.com/download/x264_benchmark/launchbenchmark_100.sh'
url_benchmark_source_100='https://www.raspiced.com/download/x264_benchmark/elephantsdream_source_100.264'
url_benchmark_tool='https://www.raspiced.com/download/x264_benchmark/launchbenchmark.sh'
url_benchmark_source='https://www.raspiced.com/download/x264_benchmark/elephantsdream_source.264'
# Bash coloring
color_reset='\033[0m'
color_green='\033[0;32m'
color_red='\033[0;31m'
color_yellow='\033[0;33m'
###################################################
# Handle uninstallation if the user wishes for it #
###################################################
# Handle deinstallation and source tree cleaning, if an "--uninstall" parameter is provided.
if [ "${1}" = "--uninstall" ]; then
cd "${build_ffmpeg_dir}/"
sudo make uninstall
make distclean
cd "${build_x264_dir}/"
sudo make uninstall
make distclean
cd "${HOME}"
sudo rm launchbenchmark*
sudo rm elephantsdream_source*
sudo rm -R ffmpeg/
sudo rm -R x264/
exit 0
fi
########################
# Flags & Architecture #
########################
echo "Choose your architecture"
echo "[1] ARMv6 (ARM1176JZF-S)"
echo "[2] ARMv7 (Cortex-A7)"
echo "[3] ARMv8 (Cortex-A53)"
echo "[4] ARMv8 (Cortex-A72)"
echo "[5] ARMv8 (Cortex-A53 AARCH64) [Not supported yet]"
echo "[6] ARMv8 (Cortex-A72 AARCH64) [Not supported yet]"
echo
echo "Please select an architecure (1..6), followed by [ENTER]:"
read input
# Raspberry Pi 1, Zero
if (("$input" == "1")); then
export CFLAGS='-mcpu=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp -mtune=arm1176jzf-s'
export CXXFLAGS="${CFLAGS}"
export ARCH='arm'
export CORES='1'
fi
# Raspberry Pi 2
if (("$input" == "2")); then
export CFLAGS='-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 -mtune=cortex-a7'
export CXXFLAGS="${CFLAGS}"
export ARCH='arm'
export CORES='4'
fi
# Raspberry Pi 2 (v1.2), 3 (32-bit)
if (("$input" == "3")); then
export CFLAGS='-march=armv8-a+crc -mfloat-abi=hard -mfpu=neon-fp-armv8 -mtune=cortex-a53'
export CXXFLAGS="${CFLAGS}"
export ARCH='arm'
export CORES='4'
fi
# Raspberry Pi 4 (32-bit)
if (("$input" == "4")); then
export CFLAGS='-march=armv8-a+crc -mfloat-abi=hard -mfpu=neon-fp-armv8 -mtune=cortex-a72'
export CXXFLAGS="${CFLAGS}"
export ARCH='arm'
export CORES='4'
fi
# Raspberry Pi 3 (64-bit)
if (("$input" == "5")); then
export CFLAGS='-march=armv8-a+crc -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -mtune=cortex-a53'
export CXXFLAGS="${CFLAGS}"
export ARCH='aarch64'
export CORES='4'
echo
printf "\n${color_green}Unfortunatelly AARCH64 is not supported yet.${color_reset}\n\n"
printf "\n${color_green}This script will end here.${color_reset}\n\n"
exit 0
fi
# Raspberry Pi 4 (64-bit)
if (("$input" == "6")); then
export CFLAGS='-march=armv8-a+crc -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -mtune=cortex-a72'
export CXXFLAGS="${CFLAGS}"
export ARCH='aarch64'
export CORES='4'
echo
printf "\n${color_green}Unfortunatelly AARCH64 is not supported yet.${color_reset}\n\n"
printf "\n${color_green}This script will end here.${color_reset}\n\n"
exit 0
fi
echo
echo "Your flags & architecture:"
echo
echo "FLAGS:" "$CFLAGS"
echo "ARCH:" "$ARCH"
echo
echo
#######################################################
# Main configuration, compilation & installation part #
#######################################################
# Install dependencies
printf "\n${color_green}Installing dependencies...${color_reset}\n\n"
sudo apt update
sudo apt -y install git libomxil-bellagio-dev
# Install benchmark tools
echo
echo "Do you want to download the benchmark tools?"
echo "[1] Yes"
echo "[2] No"
echo
echo "Please select your answer (1..2), followed by [ENTER]:"
read input
# Yes, download the tools
if (("$input" == "1")); then
printf "\n${color_green}Downloading Benchmark Tool (100 frames)...${color_reset}\n\n"
wget -q --show-progress --no-use-server-timestamps --no-check-certificate --directory-prefix="${HOME}" "${url_benchmark_tool_100}"
printf "\n${color_green}Downloading Bechmark Source (100 frames)...${color_reset}\n\n"
wget -q --show-progress --no-use-server-timestamps --no-check-certificate --directory-prefix="${HOME}" "${url_benchmark_source_100}"
printf "\n${color_green}Downloading Benchmark Tool...${color_reset}\n\n"
wget -q --show-progress --no-use-server-timestamps --no-check-certificate --directory-prefix="${HOME}" "${url_benchmark_tool}"
printf "\n${color_green}Downloading Benchmark Source...${color_reset}\n\n"
wget -q --show-progress --no-use-server-timestamps --no-check-certificate --directory-prefix="${HOME}" "${url_benchmark_source}"
sudo chmod +x "${HOME}"/launchbenchmark_100.sh
sudo chmod +x "${HOME}"/launchbenchmark.sh
fi
# Clone repositories
printf "\n${color_green}Cloning ffmpeg repository...${color_reset}\n\n"
git clone "${url_ffmpeg_git}"
printf "\n${color_green}Cloning x264 repository...${color_reset}\n\n"
git clone "${url_x264_git}"
# Configure, build & install ffmpeg
printf "\n${color_green}Configuring & compiling ffmpeg libraries...${color_reset}\n\n"
cd "${build_ffmpeg_dir}/"
./configure \
--prefix='/usr/local' \
--enable-gpl \
--enable-shared \
--enable-omx \
--enable-omx-rpi \
--enable-mmal \
--disable-opencl \
--arch="${ARCH}" \
--extra-cflags="${CFLAGS}" \
--extra-cxxflags="${CXXFLAGS}"
if (("${CORES}" == "1")); then
make -j2
else
make -j6
fi
sudo make install
sudo ldconfig
# Configure, build & install x264
printf "\n${color_green}Configuring & compiling x264 binary...${color_reset}\n\n"
cd "${build_x264_dir}/"
./configure \
--prefix='/usr/local' \
--extra-cflags="${CFLAGS}"
if (("${CORES}" == "1")); then
make -j2
else
make -j6
fi
sudo make install
# Demonstrating the basic operability
printf "\n${color_green}ffmpeg version report:${color_reset}\n\n"
ffmpeg -version
printf "\n${color_green}x264 version report:${color_reset}\n\n"
x264 --version
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment