指令参数说明
--disable-static,--enable-shared,这两个选项分别是 禁止生成静态库 跟 生成动态库。FFmpeg 默认会生成静态库,但是他不能同时生成静态库跟动态库,如果你启动了 --enable-shared,那就只会生成动态库,不会生成静态库。如果你需要同时用到静态库跟动态库,那就需要编译两次
--enable-small,把 FFmpeg 的体积减少。
--disable-programs,不生成 ffmpeg.exe ,ffplay.exe ,ffprobe.exe 可执行文件。只生成静态库或者动态库。也可以单独指定某个 exe 不生成,例如 --disable-ffplay
--disable-doc,不编译生成文档,可以节省编译时间。
--disable-avdevice,--disable-avcodec,--disable-avformat,--disable-swresample,--disable-swscale,--disable-postproc,--disable-avfilter。如果你只需要exe文件,可以指定不生成这些库,但是可能 exe 会缺少某个库的功能,具体待确认
configure 脚本提供了各种裁剪功能,例如可以只启用某个编解码器,其他的编解码器全部不要,这样能大大缩小可执行文件的体积。 做法是先用 --disable-encoders 禁用所有的编码器,然后用 --enable-encoder=NAME启用某一个编码器。 封装格式也可以这样裁剪,--disable-muxers 禁用所有的复用器,--enable-muxer=NAME 启用某一个复用器。 由于 默认的编译会给 ffmpeg.exe 加上很多的编/解码器跟解/复用器,在嵌入式设备上为了使程序体积更小,可以采用此种方法。 其他的 滤镜,协议,也可以如此裁剪。
--enable-libx264,启用 x264 作为 h.264 的编解码器。
--enable-libx265,启用 x265 作为 h.265 的编解码器。
编译依赖脚本
chmod +x ./ffbuild/version.sh
chmod +x ./ffbuild/pkgconfig_generate.sh
指定编译参数
./configure --enable-shared --prefix=/opt/medias/ffmpeg/ --disable-x86asm --enable-libx264 --enable-libx265 --enable-gpl --extra-cflags="-I/opt/medias/x264/include -I/opt/medias/x265/include" --extra-ldflags="-L/opt/medias/x264/lib/ -L/opt/medias/x265/lib/"
ERROR: x264 not found using pkg-config
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/medias/x264/lib/pkgconfig:/opt/medias/x265/lib/pkgconfig
Ubuntu16.04.10
1)指令安装
添加源:sudo add-apt-repository ppa:djcj/hybrid
更新源:sudo apt-get update
下载安装:sudo apt-get -y install ffmpeg
2)源码编译安装
1.下载源码:git clone git://source.ffmpeg.org/ffmpeg.git
2.生成配置:./configure --enable-shared --prefix=/home/dong/ffmpeg/ffmpeg/build/ --disable-x86asm
旧版本可以使用--disable-yasm禁用汇编语言,新版本支持enable-x86asm / --disable-x86asm instead.启用/禁用汇编加速
注意:WARNING: The --disable-yasm option is only provided for compatibility and will be removed in the future. Use --enable-x86asm / --disable-x86asm instead.启用/禁用汇编加速
3. make && make install
4 版本查询
/home/dong/ffmpeg/ffmpeg/build/lib/pkgconfig目录下保存每个模块的版本号
libavcodec.pc libavdevice.pc libavfilter.pc libavformat.pc libavutil.pc libswresample.pc libswscale.pc
pkg-config libavdevice --modversion
查询的是当前系统目录下libavdevice的版本号,默认是从/usr/lib/pkgconfig, /usr/local/lib/pkgconfig,/usr/share/pkgconfig/开始查询libavdevice.pc,
如果需要优先找到源码编译的版本号,需要进行如下的设置
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig;$PKG_CONFIG_PATH
5 各个版本下载网址
6 添加额外库
1、yasm(libx264需要依赖yasm)
sudo apt-get install yasm
2、libx264
sudo apt-get install libx264-dev
3、libfaac
sudo apt-get install libfaac-dev
4、libmp3lame
sudo apt-get install libmp3lame-dev
5、libtheora
sudo apt-get install libtheora-dev
6、libvorbis
sudo apt-get install libvorbis-dev
7、libxvid
sudo apt-get install libxvidcore-dev
8、libxext
sudo apt-get install libxext-dev
9、libxfixes
sudo apt-get install libxfixes-dev./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-pthreads --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libxvid --enable-x11grab --enable-libvorbis
Debian GNU/Linux 11 (bullseye)
make -j8 多线程有风险,可能生成0KB的中间文件,实际上可能是系统资源不足,采用多线程编译,导致系统崩溃,因此生成了
aacdec_template.c的中间文件是0kb的,导致出现大量的undefined reference to
/usr/bin/ld: libavformat/libavformat.a: error adding symbols: archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
make: *** [Makefile:136: ffmpeg_g] Error 1
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `set_default_channel_config':
/opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:548:(.text+0x2728): undefined reference to `ff_tags_per_config'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:548:(.text+0x272c): undefined reference to `ff_tags_per_config'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:549:(.text+0x2730): undefined reference to `ff_aac_channel_layout_map'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:549:(.text+0x2734): undefined reference to `ff_aac_channel_layout_map'
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `assign_channels':
/opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:323:(.text+0x456c): undefined reference to `ff_aac_channel_map'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:323:(.text+0x4570): undefined reference to `ff_aac_channel_map'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:318:(.text+0x49d0): undefined reference to `ff_aac_channel_map'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:318:(.text+0x4c84): undefined reference to `ff_aac_channel_map'
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `get_vlc2':
/opt/gb/ffmpeg-7.0.1/libavcodec/get_bits.h:660:(.text+0x7428): undefined reference to `ff_vlc_scalefactors'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/get_bits.h:660:(.text+0x742c): undefined reference to `ff_vlc_scalefactors'
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `decode_spectrum_and_dequant':
/opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:1704:(.text+0x7844): undefined reference to `ff_vlc_spectral'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:1704:(.text+0x7848): undefined reference to `ff_vlc_spectral'
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `get_che':
/opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:657:(.text+0x9648): undefined reference to `ff_tags_per_config'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:657:(.text+0x964c): undefined reference to `ff_tags_per_config'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:679:(.text+0x96c8): undefined reference to `ff_tags_per_config'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:679:(.text+0x96cc): undefined reference to `ff_tags_per_config'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:679:(.text+0x9840): undefined reference to `ff_tags_per_config'
/usr/bin/ld: libavcodec/aacdec_fixed.o:/opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:679: more undefined references to `ff_tags_per_config' follow
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `set_default_channel_config':
/opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:549:(.text+0x9ca0): undefined reference to `ff_aac_channel_layout_map'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:549:(.text+0x9ca4): undefined reference to `ff_aac_channel_layout_map'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:548:(.text+0x9ca8): undefined reference to `ff_tags_per_config'
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `get_vlc2':
/opt/gb/ffmpeg-7.0.1/libavcodec/get_bits.h:660:(.text+0xa01c): undefined reference to `ff_vlc_scalefactors'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/get_bits.h:660:(.text+0xa024): undefined reference to `ff_vlc_scalefactors'
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `aac_decode_er_frame':
/opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:3061:(.text+0xc170): undefined reference to `ff_tags_per_config'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:3061:(.text+0xc174): undefined reference to `ff_tags_per_config'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:3062:(.text+0xc188): undefined reference to `ff_aac_channel_layout_map'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:3062:(.text+0xc18c): undefined reference to `ff_aac_channel_layout_map'
/usr/bin/ld: libavcodec/aacdec_fixed.o: in function `aac_static_table_init':
/opt/gb/ffmpeg-7.0.1/libavcodec/aacdec_template.c:1126:(.text.unlikely+0x170): undefined reference to `ff_aacdec_common_init_once'
/usr/bin/ld: libavcodec/aacdec_fixed.o:(.data.rel.ro+0x58): undefined reference to `ff_aac_ch_layout'
/usr/bin/ld: libavcodec/aacsbr_fixed.o: in function `read_sbr_envelope':
/opt/gb/ffmpeg-7.0.1/libavcodec/aacsbr_template.c:829:(.text+0xd28): undefined reference to `ff_aac_sbr_vlc'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacsbr_template.c:829:(.text+0xd2c): undefined reference to `ff_aac_sbr_vlc'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacsbr_template.c:829:(.text+0xd38): undefined reference to `ff_aac_sbr_vlc'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacsbr_template.c:825:(.text+0xf04): undefined reference to `ff_aac_sbr_vlc'
/usr/bin/ld: /opt/gb/ffmpeg-7.0.1/libavcodec/aacsbr_template.c:825:(.text+0xf08): undefined reference to `ff_aac_sbr_vlc'
/usr/bin/ld: libavcodec/aacsbr_fixed.o:/opt/gb/ffmpeg-7.0.1/libavcodec/aacsbr_template.c:815: more undefined references to `ff_aac_sbr_vlc' follow
/usr/bin/ld: libavcodec/mpegaudiodsp.o: in function `ff_mpadsp_init':
/opt/gb/ffmpeg-7.0.1/libavcodec/mpegaudiodsp.c:95:(.text.unlikely+0x29c): undefined reference to `ff_mpadsp_init_aarch64'
/usr/bin/ld: libavcodec/libavcodec.so.61: hidden symbol `ff_tags_per_config' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make: *** [ffbuild/library.mak:119: libavcodec/libavcodec.so.61] Error 1