Linux 下的 FFmpeg 安装编译环境配置总结

1. 安装编译

官网下载地址:http://ffmpeg.org/
官网安装指导 : http://trac.ffmpeg.org/wiki/CompilationGuide(并选择对应平台)

在安装编译的时候可以根据需要安装并编译其他依赖的库,FFmpeg 依赖的库很多,在编译安装的时候需要耐心与细心,否则很容易出问题。

2. 安装编译过程中出现的问题

  • 问题1 - YASM 编译 x86 目录下的文件时报错

YASM libavcodec/x86/hevc_idct.o
libavcodec/x86/hevc_idct.asm:88: error: instruction expected after label
libavcodec/x86/hevc_idct.asm:89: error: instruction expected after label
libavcodec/x86/hevc_idct.asm:89: error: redefinition of vpbroadcastw.loop'
libavcodec/x86/hevc_idct.asm:88: error:
vpbroadcastw.loop’ previously defined here
libavcodec/x86/hevc_idct.asm:104: error: instruction expected after label
libavcodec/x86/hevc_idct.asm:104: error: redefinition of vpbroadcastw.loop'
libavcodec/x86/hevc_idct.asm:88: error:
vpbroadcastw.loop’ previously defined here
libavcodec/x86/hevc_idct.asm:105: error: instruction expected after label
libavcodec/x86/hevc_idct.asm:105: error: redefinition of vpbroadcastw.loop'
libavcodec/x86/hevc_idct.asm:88: error:
vpbroadcastw.loop’ previously defined here
libavcodec/x86/hevc_idct.asm:120: error: instruction expected after label
libavcodec/x86/hevc_idct.asm:120: error: redefinition of vpbroadcastw.loop'
libavcodec/x86/hevc_idct.asm:88: error:
vpbroadcastw.loop’ previously defined here
libavcodec/x86/hevc_idct.asm:121: error: instruction expected after label
libavcodec/x86/hevc_idct.asm:121: error: redefinition of vpbroadcastw.loop'
libavcodec/x86/hevc_idct.asm:88: error:
vpbroadcastw.loop’ previously defined here
make: * [libavcodec/x86/hevc_idct.o] 错误 1


在编译汇编代码文件时,报出如上错误。
还记得在按照官网的编译安装指导过程中最开始的准备工作中,需要安装 Yasm。

Yasm
An assembler for x86 optimizations used by x264 and FFmpeg. Highly recommended or your resulting build may be very slow.
(中文意思:Yasm 是一个 x264 和 FFmpeg 使用的x86平台优化的汇编器,强烈建议安装使用否则将导致编译非常的缓慢)

If your repository provides yasm version ≥ 1.2.0 then you can install that instead of compiling:

sudo apt-get install yasm

Otherwise you can compile:

cd ~/ffmpeg_sources
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install

以上提到了 x86, 而编译出错的路径中也包含了 x86, 说明它们之间是有关联的,
其实出现以上错误,是没有完全按照官网指导来进行操作,在最后 make 的时候官网是如下调用的:

PATH="$HOME/bin:$PATH" make

而出现错误的调用是:

make

它们的区别在于 make 前指定了安装新版本的 Yasm 程序的目录,使得 make 会到指定的目录去调用 Yasm。

3. 编译项目工程出现的问题

  • 问题1 - 编译时库文件中报出大量的 undefined reference to 错误
//usr/local/lib/libavcodec.a(atrac3plusdec.o): In function `atrac3p_decode_frame':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/atrac3plusdec.c:358: undefined reference to `av_log'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/atrac3plusdec.c:353: undefined reference to `avpriv_report_missing_feature'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/atrac3plusdec.c:346: undefined reference to `av_log'
//usr/local/lib/libavcodec.a(atrac3plusdec.o): In function `atrac3p_decode_close':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/atrac3plusdec.c:72: undefined reference to `av_freep'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/atrac3plusdec.c:73: undefined reference to `av_freep'
//usr/local/lib/libavcodec.a(atrac3plusdec.o): In function `atrac3p_decode_init':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/atrac3plusdec.c:153: undefined reference to `av_log'
//usr/local/lib/libavcodec.a(atrac3plusdec.o): In function `set_channel_params':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/atrac3plusdec.c:139: undefined reference to `av_log'
//usr/local/lib/libavcodec.a(atrac3plusdec.o): In function `av_mallocz_array':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/./libavutil/mem.h:233: undefined reference to `av_mallocz'
//usr/local/lib/libavcodec.a(atrac3plusdec.o): In function `atrac3p_decode_init':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/atrac3plusdec.c:174: undefined reference to `avpriv_float_dsp_alloc'
//usr/local/lib/libavcodec.a(aura.o): In function `aura_decode_frame':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/aura.c:54: undefined reference to `av_log'
//usr/local/lib/libavcodec.a(avrndec.o): In function `decode_frame':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:116: undefined reference to `av_pix_fmt_get_chroma_sub_sample'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:134: undefined reference to `av_log'
//usr/local/lib/libavcodec.a(avrndec.o): In function `end':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:95: undefined reference to `av_freep'
//usr/local/lib/libavcodec.a(avrndec.o): In function `init':
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:44: undefined reference to `av_log'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:52: undefined reference to `av_log'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:58: undefined reference to `av_dict_set'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:67: undefined reference to `av_log'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:69: undefined reference to `av_dict_free'
/home/ffmpeg/ffmpeg_source/ffmpeg-git/libavcodec/avrndec.c:74: undefined reference to `av_image_check_size'

出现以上错误,基本上是链接库文件时出了问题,而且链接库文件时需要按照一定的顺序来链接,上层库需要放在底层库的左边,比如 libavcodec 库调用了 libavutil 库中的 av_log() 函数, 那么链接时 libavcodec 库需要放在 libavutil 库的左边,这样链接时才能正常,可以参考如下链接顺序:

-lavdevice -lavfilter -lavformat -lavcodec -lavutil

另外在编译时还会报出其他一些 undefined reference to 错误,基本上都是没有链接指定的库导致的,Google 或者 Baidu 搜索一下就知道需要链接的是什么库了。

猜你喜欢

转载自blog.csdn.net/qq1452008/article/details/76572462
今日推荐