Skip to content
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update \
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates libva-dev \
python3 python-is-python3 ninja-build meson \
python3 python-is-python3 ninja-build meson git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
&& update-ca-certificates

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Options:
--small Prioritize small size over speed and usability; don't build manpages.
--full-static Complete static build of ffmpeg (eg. glibc, pthreads etc...) **only Linux**
Note: Because of the NSS (Name Service Switch), glibc does not recommend static links.
--skip-ffmpeg-build Will only build the libs. Useful when building in a Dockerfile.
```

### Notes on static linking
Expand All @@ -162,6 +163,8 @@ Options:

- If you want the `Lv2` filter plugin, please ensure that `python3` is installed.

- If you want the `--enable-gpl-and-non-free` build, please ensure you have git installed.

1) Run the downoaded build script from the current directory, with your desired [options](#build-script-usage).
```bash
$ ./build-ffmpeg [your parameters here] --build
Expand Down
134 changes: 71 additions & 63 deletions build-ffmpeg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DISABLE_LV2=false
LATEST=false
MANPAGES=1
CURRENT_PACKAGE_VERSION=0
SKIP_FFMPEG_BUILD=false

# Check for Apple Silicon
if [[ ("$(uname -m)" == "arm64") && ("$OSTYPE" == "darwin"*) ]]; then
Expand Down Expand Up @@ -260,6 +261,9 @@ while (($# > 0)); do
CONFIGURE_OPTIONS+=("--enable-small" "--disable-doc")
MANPAGES=0
fi
if [[ "$1" == "--skip-ffmpeg-build" ]]; then
SKIP_FFMPEG_BUILD=true
fi
shift
;;
*)
Expand Down Expand Up @@ -1034,78 +1038,82 @@ if [ -d "$CWD/.git" ]; then
# if build fails below, .git will remain in the wrong place...
fi

build "ffmpeg" "$FFMPEG_VERSION"
download "https://github.com/FFmpeg/FFmpeg/archive/refs/heads/release/$FFMPEG_VERSION.tar.gz" "FFmpeg-release-$FFMPEG_VERSION.tar.gz"
# shellcheck disable=SC2086
./configure "${CONFIGURE_OPTIONS[@]}" \
--disable-debug \
--disable-shared \
--enable-pthreads \
--enable-static \
--enable-version3 \
--extra-cflags="${CFLAGS}" \
--extra-ldexeflags="${LDEXEFLAGS}" \
--extra-ldflags="${LDFLAGS}" \
--extra-libs="${EXTRALIBS}" \
--pkgconfigdir="$WORKSPACE/lib/pkgconfig" \
--pkg-config-flags="--static" \
--prefix="${WORKSPACE}" \
--extra-version="${EXTRA_VERSION}"

execute make -j $MJOBS
execute make install

if [ -d "$CWD/.git.bak" ]; then
mv "$CWD/.git.bak" "$CWD/.git"
fi
if ! $SKIP_FFMPEG_BUILD ; then
build "ffmpeg" "$FFMPEG_VERSION"
download "https://github.com/FFmpeg/FFmpeg/archive/refs/heads/release/$FFMPEG_VERSION.tar.gz" "FFmpeg-release-$FFMPEG_VERSION.tar.gz"
# shellcheck disable=SC2086
./configure "${CONFIGURE_OPTIONS[@]}" \
--disable-debug \
--disable-shared \
--enable-pthreads \
--enable-static \
--enable-version3 \
--extra-cflags="${CFLAGS}" \
--extra-ldexeflags="${LDEXEFLAGS}" \
--extra-ldflags="${LDFLAGS}" \
--extra-libs="${EXTRALIBS}" \
--pkgconfigdir="$WORKSPACE/lib/pkgconfig" \
--pkg-config-flags="--static" \
--prefix="${WORKSPACE}" \
--extra-version="${EXTRA_VERSION}"

INSTALL_FOLDER="/usr" # not recommended, overwrites system ffmpeg package
if [[ "$OSTYPE" == "darwin"* ]]; then
INSTALL_FOLDER="/usr/local"
else
if [ -d "$HOME/.local" ]; then # systemd-standard user path
INSTALL_FOLDER="$HOME/.local"
elif [ -d "/usr/local" ]; then
INSTALL_FOLDER="/usr/local"
execute make -j $MJOBS
execute make install

if [ -d "$CWD/.git.bak" ]; then
mv "$CWD/.git.bak" "$CWD/.git"
fi
fi

verify_binary_type
INSTALL_FOLDER="/usr" # not recommended, overwrites system ffmpeg package
if [[ "$OSTYPE" == "darwin"* ]]; then
INSTALL_FOLDER="/usr/local"
else
if [ -d "$HOME/.local" ]; then # systemd-standard user path
INSTALL_FOLDER="$HOME/.local"
elif [ -d "/usr/local" ]; then
INSTALL_FOLDER="/usr/local"
fi
fi

echo ""
echo "Building done. The following binaries can be found here:"
echo "- ffmpeg: $WORKSPACE/bin/ffmpeg"
echo "- ffprobe: $WORKSPACE/bin/ffprobe"
echo "- ffplay: $WORKSPACE/bin/ffplay"
echo ""
verify_binary_type

INSTALL_NOW=0
if [[ "$AUTOINSTALL" == "yes" ]]; then
INSTALL_NOW=1
elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
read -r -p "Install these binaries to your $INSTALL_FOLDER folder? Existing binaries will be replaced. [Y/n] " response
case $response in
"" | [yY][eE][sS] | [yY])
INSTALL_NOW=1
;;
esac
fi
echo ""
echo "Building done. The following binaries can be found here:"
echo "- ffmpeg: $WORKSPACE/bin/ffmpeg"
echo "- ffprobe: $WORKSPACE/bin/ffprobe"
echo "- ffplay: $WORKSPACE/bin/ffplay"
echo ""

if [ "$INSTALL_NOW" = 1 ]; then
if command_exists "sudo" && [[ $INSTALL_FOLDER == /usr* ]]; then
SUDO=sudo
INSTALL_NOW=0
if [[ "$AUTOINSTALL" == "yes" ]]; then
INSTALL_NOW=1
elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
read -r -p "Install these binaries to your $INSTALL_FOLDER folder? Existing binaries will be replaced. [Y/n] " response
case $response in
"" | [yY][eE][sS] | [yY])
INSTALL_NOW=1
;;
esac
fi
$SUDO cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/bin/ffmpeg"
$SUDO cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/bin/ffprobe"
$SUDO cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/bin/ffplay"
if [ $MANPAGES = 1 ]; then
$SUDO mkdir -p "$INSTALL_FOLDER/share/man/man1"
$SUDO cp "$WORKSPACE/share/man/man1"/ff* "$INSTALL_FOLDER/share/man/man1"
if command_exists "mandb"; then
$SUDO mandb -q

if [ "$INSTALL_NOW" = 1 ]; then
if command_exists "sudo" && [[ $INSTALL_FOLDER == /usr* ]]; then
SUDO=sudo
fi
$SUDO cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/bin/ffmpeg"
$SUDO cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/bin/ffprobe"
$SUDO cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/bin/ffplay"
if [ $MANPAGES = 1 ]; then
$SUDO mkdir -p "$INSTALL_FOLDER/share/man/man1"
$SUDO cp "$WORKSPACE/share/man/man1"/ff* "$INSTALL_FOLDER/share/man/man1"
if command_exists "mandb"; then
$SUDO mandb -q
fi
fi
echo "Done. FFmpeg is now installed to your system."
fi
echo "Done. FFmpeg is now installed to your system."
else
echo "--skip-ffmpeg-build set, ffmpeg will not be built";
fi

exit 0