天天看点

Linux下FFmpeg安装配置好后,使用中的一些问题。

最近项目需要用到FFmpeg,于是按照网上的教程配置了一下,配置成功后在编译时出现了一些问题,这里记录一下。

这是安装成功后的情况

Linux下FFmpeg安装配置好后,使用中的一些问题。

这个界面显示安装成功,并且环境也配置成功。在代码中使用时出现一些问题。我的代码中包含头文件

#include <libavutil/opt.h>
#include <libavcodec/avcodec.h>
#include <libavutil/imgutils.h>
           

1. 编译时出现错误:

fatal error:libavutil/opt.h:没有那个文件或目录
compilation terminated.
fatal error:libavcodec/avcodec.h:没有那个文件或目录
compilation terminated.
fatal error:libavutil/imgutils.h:没有那个文件或目录
compilation terminated.
           

解决方法:

在编译时指明头文件的路径/usr/local/ffmpeg/include。我原本的命令是:

gcc test.c -o test
           

更改命令为:

gcc test.c -o test -I /usr/local/ffmpeg/include
           

编译成功。具体路径按照个人安装时设置而定。

2. 编译时出现错误:

acc.c:(.text+0x1e3):对‘avcodec_register_all’未定义的引用
acc.c:(.text+0x1ed):对‘avcodec_alloc_context3’未定义的引用
acc.c:(.text+0x278):对‘av_get_channel_layout_nb_channels’未定义的引用
acc.c:(.text+0x2a0):对‘avcodec_find_encoder_by_name’未定义的引用
acc.c:(.text+0x2da):对‘avcodec_open2’未定义的引用
acc.c:(.text+0x2f7):对‘av_frame_alloc’未定义的引用
acc.c:(.text+0x350):对‘av_samples_get_buffer_size’未定义的引用
acc.c:(.text+0x366):对‘av_malloc’未定义的引用
acc.c:(.text+0x3a3):对‘avcodec_fill_audio_frame’未定义的引用
acc.c:(.text+0x3af):对‘av_init_packet’未定义的引用
acc.c:(.text+0x436):对‘avcodec_encode_audio2’未定义的引用
acc.c:(.text+0x46b):对‘av_free_packet’未定义的引用
           

解决办法:

虽然指明了路径,但是头文件之间存在依赖关系,程序编译没有指明头文件的调用顺序,编译时添加:

-L /usr/local/ffmpeg/lib -lavformat -lavcodec -lswresample -lavutil
           

3. 安装好FFmpeg后我需要用到fdk-aac,所以得安装fdk-aac后重新安装一下FFmpeg,在进行FFmpeg的make步骤时出现错误

libavcodec/libfdk-aacenc.o libavcodec/libfdk-aacenc.c: In function ‘aac_encode_init’: libavcodec/libfdk-aacenc.c:293:34: error: ‘AACENC_InfoStruct {aka struct }’ has no member named ‘encoderDelay’ 
avctx->initial_padding = info.encoderDelay;
           

这个错误是因为安装的fdk-aac版本太新了,可以安装低一点的版本。我是安装了fdk-aac-2.0.0后出现了错误,换到fdk-aac-0.1.6后成功。

fdk-aac下载链接:https://sourceforge.net/projects/opencore-amr/files/fdk-aac/

继续阅读