Skip to content

Instantly share code, notes, and snippets.

@chaiyujin
Last active July 11, 2023 15:00
Show Gist options
  • Save chaiyujin/bad7241e3459c0c96b28afc9de6e9e70 to your computer and use it in GitHub Desktop.
Save chaiyujin/bad7241e3459c0c96b28afc9de6e9e70 to your computer and use it in GitHub Desktop.
FFmpeg Build Script
LIB_ROOT=$HOME/libs
CONFIG_ARGS=(
--target-os=none # use none to prevent any os specific configurations
--arch=x86_32 # use x86_32 to achieve minimal architectural optimization
--enable-cross-compile # enable cross compile
--disable-x86asm # disable x86 asm
--disable-inline-asm # disable inline asm
--disable-asm # disable asm
--disable-stripping # disable stripping
--disable-programs # disable programs build (incl. ffplay, ffprobe & ffmpeg)
--disable-doc # disable doc
--nm="llvm-nm -g"
--ar=emar
# --as=llvm-as # NOTE: it will stuck.
--ranlib=llvm-ranlib
--cc=emcc
--cxx=em++
--objcc=emcc
--dep-cc=emcc
)
mkdir -p $LIB_ROOT
# Download.
if [ ! -f "$LIB_ROOT/ffmpeg-6.0.tar.xz" ]; then
echo "Download $LIB_ROOT/ffmpeg-6.0.tar.xz"
curl -L https://ffmpeg.org/releases/ffmpeg-6.0.tar.xz -o $LIB_ROOT/ffmpeg-6.0.tar.xz
fi
# Unpackage
if [ ! -d "$LIB_ROOT/ffmpeg-6.0" ]; then
echo "Unpackage into $LIB_ROOT/ffmpeg-6.0"
tar -xvf $LIB_ROOT/ffmpeg-6.0.tar.xz -C $LIB_ROOT
fi
# Delete unnecessary files which affect compliation.
if [ -f "$LIB_ROOT/ffmpeg-6.0/VERSION" ]; then
rm $LIB_ROOT/ffmpeg-6.0/VERSION
fi
# Build
if [ ! -f "$LIB_ROOT/ffmpeg-6.0/_build_done_lock" ]; then
echo "Begin to build $LIB_ROOT/ffmpeg-6.0"
cd $LIB_ROOT/ffmpeg-6.0 &&
emconfigure ./configure "${CONFIG_ARGS[@]}" &&
make -j4 &&
touch $LIB_ROOT/ffmpeg-6.0/_build_done_lock
else
echo "Found lock '$LIB_ROOT/ffmpeg-6.0/_build_done_lock'. Delete it to rebuild."
fi
#!/bin/bash
# Read official guide for more details
# https://trac.ffmpeg.org/wiki/CompilationGuide/macOS
# > Step 0: Install 'brew'
# https://brew.sh/
# > Step 1: Install dependency by 'brew'
brew install \
automake libtool git wget sdl nasm \
fdk-aac lame libass libvorbis libvpx \
opus shtool texi2html theora x264 x265 xvid \
;
# > Step 2: Options
CODEC_OPTS=()
CODEC_OPTS+=("--enable-gpl")
CODEC_OPTS+=("--enable-libmp3lame")
CODEC_OPTS+=("--enable-libx264")
CODEC_OPTS+=("--enable-libx265")
CODEC_OPTS+=("--enable-libxvid")
CODEC_OPTS+=("--enable-opencl")
CODEC_OPTS+=("--enable-videotoolbox")
CODEC_OPTS+=("--disable-lzma")
INSTALL_PATH="$HOME/Software/ffmpeg_build"
# > Step3: Build & Install
# make sure the directory is correct.
cd ffmpeg-5.0.1 && \
PATH="$INSTALL_PATH/bin:$PATH" \
PKG_CONFIG_PATH="$INSTALL_PATH/lib/pkgconfig" \
pkg_config='pkg-config --static' \
./configure \
--prefix="$INSTALL_PATH" \
--pkg-config-flags="--static" \
--extra-cflags="-I$INSTALL_PATH/include -march=native" \
--extra-ldflags="-L$INSTALL_PATH/lib" \
--extra-libs="-lpthread -lm" \
--bindir="$INSTALL_PATH/bin" \
--cc=clang --host-cflags= --host-ldflags= \
--enable-static --enable-shared --enable-pthreads \
${CODEC_OPTS[@]} && \
PATH="$INSTALL_PATH/bin:$PATH" make -j 8 && \
make install
#!/bin/bash
# Read official guide for more details
# https://trac.ffmpeg.org/wiki/CompilationGuide
# > Step 1: Install dependency by 'apt'
sudo apt install \
nasm libass-dev libfdk-aac-dev libmp3lame-dev \
libopus-dev libvorbis-dev libvpx-dev libx264-dev libx265-dev \
;
# > Step 2: Options
CODEC_OPTS=()
CODEC_OPTS+=("--enable-gpl")
CODEC_OPTS+=("--enable-nonfree")
CODEC_OPTS+=("--enable-libass")
CODEC_OPTS+=("--enable-libfdk-aac")
CODEC_OPTS+=("--enable-libfreetype")
CODEC_OPTS+=("--enable-libmp3lame")
CODEC_OPTS+=("--enable-libopus")
CODEC_OPTS+=("--enable-libvorbis")
CODEC_OPTS+=("--enable-libvpx")
CODEC_OPTS+=("--enable-libx264")
CODEC_OPTS+=("--enable-libx265")
INSTALL_PATH="$HOME/Software/ffmpeg_build"
# > Step3: Build & Install
# make sure the directory is correct.
cd ffmpeg-5.0.1 && \
PATH="$INSTALL_PATH/bin:$PATH" \
PKG_CONFIG_PATH="$INSTALL_PATH/lib/pkgconfig" \
pkg_config='pkg-config --static' \
./configure \
--prefix="$INSTALL_PATH" \
--pkg-config-flags="--static" \
--extra-cflags="-I$INSTALL_PATH/include" \
--extra-ldflags="-L$INSTALL_PATH/lib" \
--extra-libs="-lpthread -lm" \
--bindir="$INSTALL_PATH/bin" \
--cc=gcc --host-cflags= --host-ldflags= \
--enable-static --enable-shared --enable-pthreads \
${CODEC_OPTS[@]} && \
PATH="$INSTALL_PATH/bin:$PATH" make -j 8 && \
make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment