||
主要参考:
https://trac.ffmpeg.org/wiki/CompilationGuide/Centos
https://blog.csdn.net/hanzheng260561728/article/details/73744450
但是发现老是出现ld链接错误,例如写个最简单的:
int main(int argc, const char *argv[])
{
av_register_all();
return 0;
}
编译会出现错误:
undefined reference to `av_register_all()' collect2: error:
ld returned 1 exit status
那按照下面的步骤来避免该问题:
mkdir ~/software
cd ~/software/
rpm -Uhv rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum install automake autoconf make gcc gcc-c++ libtool zlib zlib-devel curl curl-devel alsa-lib alsa-lib-devel gettext gettext-devel expat expat-devel nasm pkgconfig bzip2 -y
yum install yasm yasm-devel gnutls gnutls-devel lame lame-devel faac faac-devel -y
下面由于nasm版本太老,自己重新安装:
yum remove nasm
cd ~/software/
curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2
tar xjvf nasm-2.13.02.tar.bz2
cd nasm-2.13.02
./autogen.sh
./configure
make
make install
不再使用库faac,改用fdk-aac库:
//不要用这个,新版本对ffmpeg编译产生错误:git clone --depth 1 https://github.com/mstorsjo/fdk-aac
wget https://jaist.dl.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-0.1.6.tar.gz
tar xvf fdk-aac-0.1.6.tar.gz
fdk-aac-0.1.6/
autoreconf -fiv
./configure --enable-shared --enable-static
make
make install
使用新版本的yasm:
yum remove yasm
curl -O -L 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
make
make install
使用x264的一个特定版本,不要使用最新版本,会有编译错误:
wget ftp://ftp.videolan.org/pub/x264/snapshots/x264-snapshot-20140201-2245.tar.bz2
tar xjvf x264-snapshot-20140201-2245.tar.bz2
cd x264-snapshot-20140201-2245/
./configure --enable-shared --enable-static --disable-opencl
make
make install
最后是安装ffmpeg3.3:
自己去官网下载或者我上传到到这里链接:https://pan.baidu.com/s/1ZzMR_01cJOyvGa0IyGuCiA 提取码:ih2r
cd ffmpeg-3.3.2/
./configure --prefix=/usr/local/ --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-static --enable-zlib --enable-libmp3lame --enable-libx264 --enable-pic --enable-libfdk_aac --enable-gpl --enable-nonfree
make
make install
然后是pkconfig路径设置一下:
gedit /etc/profile
在最后一行加上:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH
保存重启。
然后我们写个最简单的代码:test.c:
#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#ifdef _STDINT_H
#undef _STDINT_H
#endif
extern "C" {
#include <stdint.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
}
#endif
int main(int argc, const char *argv[])
{
av_register_all();
return 0;
}
然后编译:
g++ -o test test.c $(pkg-config --cflags --libs libavformat libavcodec)
是不是成功了。
注意如果自己写依赖库的时候,而不用$(pkg-config --cflags --libs libavformat libavcodec)的时候,注意库的先后顺序,参考:
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-7-24 09:29
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社