Learning articles:https://ffmpeg.xianwaizhiyin.net/build-ffmpeg/configure-args.html
source code
After removing some documentation
~/ffmpeg-4.2.2 $ ls
compat fftools libavformat libswresample presets
configure libavcodec libavresample libswscale tests
doc libavdevice libavutil Makefile tools
ffbuild libavfilter libpostproc
doc/build_system.txt, some tutorials on compiling FFmpeg.
doc/filter_design.txt , the design principle of filter filter.
doc/writing_filters.txt, how to write a filter and add it to FFmpeg.
doc/issue_tracker.txt, FFmpeg bug or feature tracking process
doc/multithreading.txt, there are two types of multithreading in FFmpeg, Slice threading and Frame threading
doc/optimization.txt, the codec optimization method, FFmpeg also has some functions that can be optimized by assembly SIMD. If some of its functions are optimized to be obscure, you can check the early gitlog.
doc/rate_distortion.txt, a brief discussion of distortion rates.
compile parameters
Environment directory
prefix represents the prefix directory
libdir represents the static library directory
shlibdir is the installation directory of the dynamic library. By default, the dynamic library will be installed to the system's dynamic library directory.
pkgconfigdir represents the installation directory of the pkg file
pkg is used to find the installation directory of FFmpeg static library and dynamic library for third-party software.
link library
--disable-static\ --enable-shared , FFmpeg will generate a static library by default
--extra-cflags, pass flags options to the C compiler
--extra-cxxflags, pass flag options to the C++ compiler
--extra-ldflags, pass flags options to LD linker
--extra-ldexeflags, options passed to the linker when generating exe
--extra-ldsoflags, the option passed to the linker when generating the so dynamic library
--extra-libs, specifying additional libraries, is actually adding options to the linker
--env="ENV=override" This is the most important, it can override environment variables
Compilation speed, program size
--enable-small, reduce the size of FFmpeg.
--disable-doc, do not compile and generate documentation, which can save compilation time.
--disable-programs, enable/disable executables (ffmpeg). Do not generate --disable-ffplay for one, if all are closed, only static library\dynamic library will be generated.
--disable-avdevice, --disable-avcodec, --disable-avformat, --disable-swresample, --disable-swscale, --disable-postproc, --disable-avfilter. Open/closed libraries, if you only need executable files, you can specify not to generate these libraries, but the program may lack the function of a certain library. (You can manually close some libraries when developing the filter module, which will reduce a lot of compilation time)
--disable-indevs --disable-outdevs --disable-bsfs --disable-protocols --disable-filters --disable-encoders --disable-decoders --disable-muxers --disable-demuxers --disable-parsers For these ten corresponding devices, we first close all of them and then release the ones we need, mainly to reduce the code size. If there is no subsequent configuration, ffmpeg will be compiled with the smallest volume, but without any functions.
Since the default compilation will add a lot of encoders/decoders and demultiplexers to ffmpeg.exe, this method can be used to make the program smaller and compile faster in embedded devices or zero-time development . Other filters, protocols, can also be cropped like this.
executable program properties
--disable-pthreads, --disable-w32threads, --disable-os2threads Turn off multithreading. If disabled, the performance will drop a lot
--disable-network, if you do not need to deal with network protocols, you can enable this option, which can reduce the size of the software and save compilation time.
Encoder
--enable-libx264, enable x264 as codec for h.264. --enable-libx265, enable x265 as codec for h.265. (It is usually these 2 now, and there was h262 before)
--enable-encoder=rawvideo --enable-encoder=mpeg4 enable encoder rawvideo corresponds to yuv, mpeg4 corresponds to mp4
--enable-decoder=rawvideo --enable-decoder=mpeg4 --enable-decoder=movtext Enable the decoder, here you need to enable movtext to decompress mp4
--enable-muxer=aiff --enable-muxer=h263 --enable-muxer=mp4 --enable-muxer=rawvideo enable compositor
--enable-demuxer=aac --enable-demuxer=aiff --enable-demuxer=h263 --enable-demuxer=mov --enable-demuxer=rawvideo enable splitter
--enable-parser=aac --enable-parser=h263 --enable-parser=mpegaudio --enable-parser=mpeg4video 使能解析器
--enable-indev=v4l2 --enable-outdev=v4l2 Enable input device, output device (if not enabled, only codec can not capture video)
--enable-filter=scale enable filter, this is used to convert yuv format, yuv has multiple formats to convert each other.
Environment tools (different platforms use different tools)
--cc=CC Specifies the compiler for C programs. --cxx=CXX Specify the C++ compiler. --ld=LD specifies the linker.
--custom-allocator, a custom memory allocator, you can replace malloc with jemalloc and the like.
--arch=x86_32/i386/x86_64/arm64,
- protocol
--enable-protocol=file
Enable file protocol, this must be released,
Compilation script (hereinafter referred to as configure
)
~/ffmpeg-4.2.2 $ cat load.sh
#!/bin/bash
if [ -d build ];then
mkdir build
fi
./configure \
--prefix=build \
--enable-gpl \
--enable-nonfree \
--enable-debug=3 \
--disable-optimizations \
--disable-asm \
--disable-stripping \
--disable-ffprobe \
--disable-ffplay
The code version is controlled by git, and configure
the new files generated after execution are as follows:
~/ffmpeg-4.2.2 $ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
config.h
doc/config.texi
ffbuild/.config
ffbuild/config.fate
ffbuild/config.log
ffbuild/config.mak
ffbuild/config.sh
libavcodec/bsf_list.c
libavcodec/codec_list.c
libavcodec/parser_list.c
libavdevice/indev_list.c
libavdevice/outdev_list.c
libavfilter/filter_list.c
libavformat/demuxer_list.c
libavformat/muxer_list.c
libavformat/protocol_list.c
libavutil/avconfig.h
Execute it again forever configure
and you can also see the main configuration file as follows
License: nonfree and unredistributable
config.h is unchanged
libavutil/avconfig.h is unchanged
libavfilter/filter_list.c is unchanged
libavcodec/codec_list.c is unchanged
libavcodec/parser_list.c is unchanged
libavcodec/bsf_list.c is unchanged
libavformat/demuxer_list.c is unchanged
libavformat/muxer_list.c is unchanged
libavdevice/indev_list.c is unchanged
libavdevice/outdev_list.c is unchanged
libavformat/protocol_list.c is unchanged
ffbuild/config.sh is unchanged
Then filter configure
the printed information after execution. The printed information here is to tell you after executing make to compile: the program you will get and the function information it will have
~/ffmpeg-4.2.2 $ cat log | grep :
External libraries:
External libraries providing hardware acceleration:
Libraries:
Programs:
Enabled decoders:
Enabled encoders:
Enabled hwaccels:
Enabled parsers:
Enabled demuxers:
Enabled muxers:
Enabled protocols:
Enabled filters:
Enabled bsfs:
Enabled indevs:
Enabled outdevs:
License: nonfree and unredistributable
Then execute make -j16 to compile and run. The 16 here means to compile with 16 sub-threads at the same time. I only know a little about shell multi-threading technology. I don’t know much about the tool of make. Domestic articles explain it vaguely. There is an article Said **"The number after j should be twice the number of CPU cores"** I don't know if it is accurate, so far I have deliberately used the shell to test 16 threads and unlimited threads respectively (my computer has 8 cores) , it is obvious that unlimited threads take much less time than 16 (maybe I don’t quite understand the difference between shell multi-threading and program process multi-threading), if you are interested, you can study it yourself
After make, look at the file changes. It is still the same. After git status
adding configurtion
the previous files here, the newly generated files are basically .d和.o
files. There are 3533 files changed or generated.
~/ffmpeg-4.2.2 $ git status | wc -l
3533
Compiled information:
~/ffmpeg-4.2.2 $ du ffmpeg ffmpeg_g
68M ffmpeg
68M ffmpeg_g
~/ffmpeg-4.2.2 $ ldd ffmpeg_g
linux-vdso.so.1 (0x00007ffea3f66000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4c782ef000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f4c782d3000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4c780ab000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4c7a510000)
~/ffmpeg-4.2.2 $ file ffmpeg_g
ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=5a51fa6f5eb1997656814577ef36b945fd21a07b, for GNU/Linux 3.2.0, with debug_info, not stripped
It can be seen that it still depends on some dynamic libraries of the system, even in the case of static linking (the script is not added in the previous script to --enable-shared
compile with static libraries)
full static compilation
Need to add 3 more static flags
~/ffmpeg-4.2.2 $ cat load.sh
#!/bin/bash
if [ ! -d build ];then
mkdir build
fi
#在执行 这条命令之前,需要安装一些必备的静态库,因为操作系统为了节省硬盘空间,默认可能只有动态库,一些静态库需要手动安装的
#sudo apt install libc6-dev build-essential -y
./configure \
--prefix=build \
--enable-gpl \
--enable-nonfree \
--enable-debug=3 \
--disable-optimizations \
--disable-asm \
--disable-stripping \
--disable-ffprobe \
--disable-ffplay \
--extra-cflags="-static" \
--extra-ldflags="-static" \
--pkg-config-flags="--static"
compiled information
~/ffmpeg-4.2.2 $ file ffmpeg_g
ffmpeg_g: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=9d75510c5c79ba9e47b1ea617e4f97308c75795e, for GNU/Linux 3.2.0, with debug_info, not stripped
~/ffmpeg-4.2.2 $ du ffmpeg_g
69M ffmpeg_g
Download-compile script (Android)
#!/bin/bash
cd ~/
if [ ! -f "ffmpeg-4.2.2.tar.bz2" ];then
wget https://ffmpeg.org/releases/ffmpeg-4.2.2.tar.bz2
tar -xjvf ffmpeg-4.2.2.tar.bz2
fi
cd ffmpeg-4.2.2
path=($(ls ~/Library/Android/sdk/ndk/))
export NDK=$HOME/Library/Android/sdk/ndk/${path[0]}
echo -e " \033[31m 检测ndk-build 版本,将使用${NDK}进行编译\033[0m"
echo -e "\n请选择要编译的版本架构:[64/32]"
read archbit
if [[ $archbit = 64 ]];then
echo "start build for 64bit..."
ARCH=aarch64
CPU=armv8-a
API=23
PLATFORM=aarch64
ANDROID=android
CFLAGS=""
LDFLAGS=""
elif [[ $archbit = 32 ]];then
echo "start build for 32bit..."
ARCH=arm
CPU=armv7-a
API=23
PLATFORM=armv7a
ANDROID=androideabi
CFLAGS="-mfloat-abi=softfp -march=$CPU"
LDFLAGS="-Wl,--fix-cortex-a8"
else
exit
fi
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin
export SYSROOT=$NDK/toolchains/llvm/prebuilt/darwin-x86_64/sysroot
export CROSS_PREFIX=$TOOLCHAIN/$ARCH-linux-$ANDROID-
export CC=$TOOLCHAIN/$PLATFORM-linux-$ANDROID$API-clang
export CXX=$TOOLCHAIN/$PLATFORM-linux-$ANDROID$API-clang++
export PREFIX=../ffmpeg-android/$CPU
function build_android {
./configure \
--prefix=$PREFIX \
--cross-prefix=$CROSS_PREFIX \
--target-os=android \
--arch=$ARCH \
--cpu=$CPU \
--cc=$CC \
--cxx=$CXX \
--nm=$TOOLCHAIN/$ARCH-linux-$ANDROID-nm \
--strip=$TOOLCHAIN/$ARCH-linux-$ANDROID-strip \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="$CFLAGS" \
--extra-ldflags="$LDFLAGS" \
--extra-ldexeflags=-pie \
--enable-runtime-cpudetect \
--disable-static \
--enable-shared \
--disable-ffprobe \
--disable-ffplay \
--disable-debug \
--disable-doc \
--enable-avfilter \
--enable-decoders \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j16
make install
}
build_android
Similarly, the required functions are canceled on the above. The script here is only the automatic compilation function, and the specific ffmpeg functions you want to use can also be taken on demand
Original link: Understanding ffmpeg compilation and parameter interpretation_HNHuangJingYu's Blog-CSDN Blog
★The business card at the end of the article can receive free audio and video development learning materials, including (FFmpeg, webRTC, rtmp, hls, rtsp, ffplay, srs) and audio and video learning roadmaps, etc.
see below!