ffmpeg compile configuration to support h264 video encoding, support avfilter to add watermark
During the installation of ffmpeg, you need to install the required dependencies:
- nasm: cross-platform support for assembly and compilation
- x264: H264 codec
- freetype2: ttf font library support
- x264 installation
下载x264https://www.videolan.org/developers/x264.html
git clone https://code.videolan.org/videolan/x264.git
Configure./configure
eric@eric-PC:~/Documents/linux/x264$ ls
AUTHORS config.guess COPYING example.c input tools x264cli.h x264res.manifest
autocomplete.c config.sub doc extras Makefile version.sh x264dll.c x264res.rc
common configure encoder filters output x264.c x264.h
eric@eric-PC:~/Documents/linux/x264$ ./configure
Found no assembler
Minimum version is nasm-2.13
If you really want to compile without asm, configure with --disable-asm.
Prompt that nasm is missing, execute sudo apt-get install nasm, and then configure
eric@eric-PC:~/Documents/linux/x264$ ./configure --enable-static --enable-shared
platform: X86_64
byte order: little-endian
system: LINUX
cli: yes
libx264: internal
shared: yes
static: yes
bashcompletion: yes
asm: yes
interlaced: yes
avs: avxsynth
lavf: no
ffms: no
mp4: no
gpl: yes
thread: posix
opencl: yes
filters: crop select_every
lto: no
debug: no
gprof: no
strip: no
PIC: yes
bit depth: all
chroma format: all
You can run 'make' or 'make fprofiled' now.
Compile and install x264
eric@eric-PC:~/Documents/linux/x264$ make
eric@eric-PC:~/Documents/linux/x264$ sudo make installinstall -d /usr/local/bin
install x264 /usr/local/bin
install -d /usr/local/include /usr/local/lib/pkgconfig
install -m 644 ./x264.h x264_config.h /usr/local/include
install -m 644 x264.pc /usr/local/lib/pkgconfig
install -d /usr/local/lib
ln -f -s libx264.so.161 /usr/local/lib/libx264.so
install -m 755 libx264.so.161 /usr/local/lib
install -d /usr/local/lib
install -m 644 libx264.a /usr/local/lib
gcc-ranlib /usr/local/lib/libx264.a
install -d /usr/share/bash-completion/completions
install -m 644 -T ./tools/bash-autocomplete.sh /usr/share/bash-completion/completions/x264
- Install ffmpeg
First install the freetype font library, avfilter adds the dependency of the text watermark; download freetype: https://www.freetype.org/download.html ;
Configure, compile, install, read version information
eric@eric-PC:~/Documents/linux/freetype-2.10.4$ ./configure
eric@eric-PC:~/Documents/linux/freetype-2.10.4$ make
eric@eric-PC:~/Documents/linux/freetype-2.10.4$ sudo make install
eric@eric-PC:~/Documents/linux/freetype-2.10.4$ pkg-config --modversion freetype2
23.4.17
Download ffmpeg
eric@eric-PC:~/Documents/linux-c$ git clone https://gitee.com/mirrors/ffmpeg.git
正克隆到 'ffmpeg'...
remote: Enumerating objects: 7513, done.
remote: Counting objects: 100% (7513/7513), done.
remote: Compressing objects: 100% (3603/3603), done.
remote: Total 610183 (delta 5174), reused 5268 (delta 3903), pack-reused 602670
接收对象中: 100% (610183/610183), 149.26 MiB | 2.55 MiB/s, 完成.
处理 delta 中: 100% (489283/489283), 完成.
配置、编译、安装ffmpeg
./configure --enable-static --enable-shared --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-ffmpeg --enable-libx264 --enable-gpl --enable-libfreetype --enable-libopenjpeg
eric@eric-PC:~/Documents/linux-c/ffmpeg$ ./configure --enable-static --enable-shared --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-ffmpeg --enable-libx264 --enable-gpl --enable-libfreetype
eric@eric-PC:~/Documents/linux-c/ffmpeg$ make
eric@eric-PC:~/Documents/linux-c/ffmpeg$ sudo make install
View the installed ffmpeg
eric@eric-PC:/$ ffmpeg
ffmpeg version N-99957-g837eb320b8 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Uos 8.3.0.3-3+rebuild)
configuration: --enable-static --enable-shared --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-ffmpeg --enable-libx264 --enable-gpl --enable-libfreetype
libavutil 56. 60.100 / 56. 60.100
libavcodec 58.112.103 / 58.112.103
libavformat 58. 64.100 / 58. 64.100
libavdevice 58. 11.102 / 58. 11.102
libavfilter 7. 90.100 / 7. 90.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {
[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'