Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Building FFmpeg from Source on CentOS 7 with libx264 and libxvid Support

Notes May 15 1

Preparing the Build Environment

Compiling FFmpeg on CentOS 7 requires a C compiler and several dependencies to enable specific encoding capabilities. Before beginning the compilation process, ensure that the basic development tools are available.

yum install gcc gcc-c++ make -y

Installing the NASM Assembler

The libx264 library requires the Netwide Assembler (NASM) for optimized assembly routines. Version 2.13 or higher is typically required.

cd /usr/local/src
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.gz
tar -xzf nasm-2.15.05.tar.gz
cd nasm-2.15.05
./configure
make && make install

Compiling libx264

With the assembler ready, download and compile the x264 library. We will install it into a custom prefix directory to keep the system clean and manage library paths manually during the FFmpeg build.

cd /usr/local/src
git clone --depth 1 https://code.videolan.org/videolan/x264.git
cd x264
./configure --prefix=/usr/local/ffmpeg_deps/x264 --enable-shared --enable-pic
make && make install

Compiling libxvid

The Xvid codec provides high-quality MPEG-4 ASP compression. Download the source code and build it from the generic build directory.

cd /usr/local/src
wget http://downloads.xvid.org/downloads/xvidcore-1.3.3.tar.gz
tar -xzf xvidcore-1.3.3.tar.gz
cd xvidcore/build/generic
./configure --prefix=/usr/local/ffmpeg_deps/xvid
make && make install

Building FFmpeg

Download the FFmpeg source code (version 4.4.3 in this example). The configuration step must explicitly include the paths to the previously compiled libraries using --extra-cflags and --extra-ldflags.

cd /usr/local/src
wget http://ffmpeg.org/releases/ffmpeg-4.4.3.tar.gz
tar -xzf ffmpeg-4.4.3.tar.gz
cd ffmpeg-4.4.3

export X264_PATH=/usr/local/ffmpeg_deps/x264
export XVID_PATH=/usr/local/ffmpeg_deps/xvid

./configure \
    --prefix=/usr/local/ffmpeg \
    --enable-gpl \
    --enable-nonfree \
    --enable-libx264 \
    --enable-libxvid \
    --enable-shared \
    --enable-pthreads \
    --enable-avfilter \
    --extra-cflags="-I${X264_PATH}/include -I${XVID_PATH}/include" \
    --extra-ldflags="-L${X264_PATH}/lib -L${XVID_PATH}/lib"

make && make install

Configuring Runtime Libraries

After installation, the system must be informed of the location of the shared libraries. Add the library paths to the dynamic linker configuration and reload the cache.

echo "/usr/local/ffmpeg/lib" >> /etc/ld.so.conf
echo "/usr/local/ffmpeg_deps/x264/lib" >> /etc/ld.so.conf
echo "/usr/local/ffmpeg_deps/xvid/lib" >> /etc/ld.so.conf
ldconfig

Verify the installation by checking the version:

/usr/local/ffmpeg/bin/ffmpeg -version

Cross-Platform Usage Notes

Binaries compiled on CentOS 7 generally function correctly on newer distributions like Ubuntu 16.04 or CentOS 8, provided the kernel and system libraries are compatible. If encountering errors related to missing shared objects like libxcb.so.1 when running the binary on a minimal system, install the missing dependency:

yum install libxcb -y

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.