hillpig的个人博客分享 http://blog.sciencenet.cn/u/hillpig 畅想ing,思考ing,前行ing Email:bluevaley@gmail.com

博文

编译ffmpeg3.3版

已有 3735 次阅读 2018-8-30 18:08 |个人分类:创新教育|系统分类:科研笔记

 主要参考:

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/

wget -c ftp://195.220.108.108/linux/dag/redhat/el6/en/x86_64/dag/RPMS/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

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)的时候,注意库的先后顺序,参考:

https://ffmpeg.org/faq.html#I_0027m-using-FFmpeg-from-within-my-C-application-but-the-linker-complains-about-missing-symbols-from-the-libraries-themselves_002e




https://blog.sciencenet.cn/blog-419883-1131894.html

上一篇:英语好句子
下一篇:距离计算 - 创新者当时面临的困难系列3
收藏 IP: 61.135.169.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-16 18:19

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部