Build static FFmpeg (Part I)

Build static FFmpeg (Part I)

Today I will build FFmpeg with minimalist module. Objective is compile FFmpeg with libx264 (H.264 support) and libssl (RTMPS support) only.

Install tools & Dependencies package

apt-get install \
autoconf \
automake \
build-essential \
cmake \
git \
pkg-config \
wget \
yasm nasm libssl-dev

Prepare module

I recommend "FFmpeg Static Build" collected by John Van Sickle.

mkdir $HOME/ffempg-static
cd $HOME/ffempg-static


cd /root/ffmpeg-static
tar -xvf libx264-git.tar.xz
./configure --prefix=/root/ffmpeg-static/workspace --enable-static --enable-pic 
make -j
make install

check library
Before build FFmpeg, make sure that your environement know all library. You should see openssl, libssl, libcryto and x264 libraries. Use pkg-config for checking.

export PKG_CONFIG_PATH=/root/ffmpeg-static/workspace/lib/pkgconfig
pkg-config --list-all

Prepare FFmpeg source code then compile it###

cd /root/ffmpeg-static
tar -xvf ffmpeg-4.1.tar.xz
cd ffmpeg-4.1

./configure --prefix=/root/ffmpeg-static/workspace \
--extra-version=patrickz --disable-debug --disable-shared --enable-static \
--disable-doc --enable-gpl  --enable-nonfree --enable-version3 \
--pkg-config-flags="--static" \
--enable-libx264 \
--enable-openssl \
--enable-filters \
--extra-cflags="-I--prefix=/root/ffmpeg-static/workspace/include -static" \
--extra-ldflags="-L--prefix=/root/ffmpeg-static/workspace/lib -static" 

make -j

After compile, you cloud see new file ffmpeg, ffmpeg_g, ffprobe, ffprobe_g. File with suffix "_g" is debug mode.

to make sure the "ffmpeg" is static program, you can use command ldd ffmpeg, the resule should be "not a dynamic executable"

ldd ./ffmpeg
./ffmpeg -buildconf


Now let's stream to RTMPS server. I try streaming to facebook live!

./ffmpeg -f lavfi -re -i "life=s=300x200:mold=10:r=25:ratio=0.1:death_color=#C83232:life_color=#00ff00,scale=1200:800:flags=16" \
-f lavfi -re -i sine=frequency=1000:sample_rate=44100 -pix_fmt yuv420p -c:v libx264 -b:v 1000k -g 30 -keyint_min 120 \
-profile:v baseline -preset veryfast -c:a aac -b:a 96k  -f flv "rtmps://{YOUR RTMP KEY}"


That's it. Now you can just copy only file "ffmpeg" to another machine. It is static program so no need portable or included dynamic link module anymore.

Next time, I will build FFmpeg with another module