FFmpeg adds a watermark to the video, according toThe official documentationFFmpeg also needs to be added during compilation and installation–enable-libfreetype, –enable-libfontconfig, –enable-libfribidiThese parameters, and these components need to compile and install from the outside, I see a lot of bloggers directly use FFmpeg command watermark, but there is no detailed component installation process, the following mainly introduces these components including FFmpeg compile and install the complete process.

Installation environment

centos7.6

Install freetype

Download a version from the Freetype website

Wget HTTP: / / https://bigsearcher.com/mirrors/nongnu/freetype/freetype-2.10.0.tar.bz2Copy the code

Decompression.

The tar JXF freetype - 2.10.0. Tar..bz2Copy the code

Compile the installation and set the installation directory to /usr/local/freetype.

./configure --prefix=/usr/local/freetype
Copy the code
make && make install
Copy the code

Configure environment variables edit vim /etc/profile and add it on the last line.

export PKG_CONFIG_PATH="/usr/local/freetype/lib/pkgconfig:$PKG_CONFIG_PATH"
Copy the code

The editor vim/etc/ld. So. Conf. D/ffmpeg. Conf. Add the following line:

/usr/local/freetype/lib
Copy the code

Then use: wq! Save the configuration and exit. Run ldconfig to make the configuration take effect.

Install libxml2

Download a version of libxml2 from the libxml2 website.

Wget HTTP: / / http://xmlsoft.org/sources/libxml2-2.9.10.tar.gzCopy the code

Decompression.

The tar - XZF libxml2-2.9.10. Tar. GzCopy the code

Compile the installation and set the installation directory to /usr/local/libxml2.

./configure --prefix=/usr/local/libxml2
Copy the code
make && make install
Copy the code

Errors may occur in the middle:

The solution is to install the corresponding Python dev package.

yum install python-devel
Copy the code

Use make && make install again to compile and install. Configure the environment variable vim /etc/profile.

export PKG_CONFIG_PATH="/usr/local/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH"
Copy the code

The editor vim/etc/ld. So. Conf. D/ffmpeg. Conf. Add the following line to the last line:

/usr/local/libxml2/lib
Copy the code

Then use: wq! Save the configuration and exit. Run ldconfig to make the configuration take effect.

Install the fontconfig

Download a version from the Fontconfig website.

Wget HTTP: / / https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.9.92.tar.gzCopy the code

Decompression.

The tar - XZF fontconfig - 2.9.92. Tar. GzCopy the code

Compile and install.

./configure --enable-libxml2 --with-freetype-config=/usr/local/freetype/include/freetype2/freetype/config --prefix=/usr/local/fontconfig
Copy the code
make && make install
Copy the code

Configure the environment variable vim /etc/profile.

export PKG_CONFIG_PATH="/usr/local/fontconfig/lib/pkgconfig:$PKG_CONFIG_PATH"
Copy the code

The editor vim/etc/ld. So. Conf. D/ffmpeg. Conf. Add the following line to the last line:

/usr/local/fontconfig/lib
Copy the code

Then use: wq! Save the configuration and exit. Run ldconfig to make the configuration take effect.

Install fribidi

Download fribidi

 wget https://codeload.github.com/fribidi/fribidi/zip/master
Copy the code

Decompress master (install the zip decompression tool) and install other dependencies.

unzip master
cd fribidi-master/
yum install libtool
yum install autoconf
yum install automake
./autogen.sh
Copy the code

Compile and install.

./configure --prefix=/usr/local/fribidi
Copy the code
make && make install
Copy the code

Configure the environment variable vim /etc/profile.

export PKG_CONFIG_PATH="/usr/local/fribidi/lib/pkgconfig:$PKG_CONFIG_PATH"
Copy the code

The editor vim/etc/ld. So. Conf. D/ffmpeg. Conf. Add the following line to the last line:

/usr/local/fribidi/lib
Copy the code

Then use: wq! Save the configuration and exit. Run ldconfig to make the configuration take effect.

Install FFmpeg

Download the source code from the official website

wget https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
Copy the code

Decompression.

tar jxf ffmpeg-snapshot.tar.bz2
Copy the code

Make sure the following environment has been configured previously in /etc/profile, if not, see below.

export PKG_CONFIG_PATH=/usr/local/freetype/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/usr/local/fontconfig/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/usr/local/fribidi/lib/pkgconfig:$PKG_CONFIG_PATH
Copy the code

The configuration of FFmpeg.

./configure --enable-shared --enable-decoder=h264 --enable-parser=h264 --enable-libfreetype --enable-libfontconfig --enable-libfribidi --arch=x86_32 --prefix=/usr/local/ffmpeg
Copy the code

Compile and install.

make  &&  make install
Copy the code

Let’s try it with a HelloWorld watermark.

ffmpeg -re -i input.mp4 -vf "drawtext=fontfile=simhei.ttf: text='helloworld':x=10:y=10:fontsize=50:fontcolor=white:shadowy=2"The -f FLV RTMP: / / 127.0.0.1:1935 / live / 123Copy the code

You can see the watermark loading successfully!!