3个平台下的ffmpeg——ffmpeg编译

时间:2022-02-25 04:35:34

ffmpeg编译

 

需要在3个平台(win\linux\arm)下使用ffmpeg的库,所以进行了ffmpeg的编译。

其中ffmpeg的编译也有许多依赖,不同平台依赖的也不一样,少了一个依赖可能就少了一个功能了。

 

Windows下的ffmpeg:

 

Win下的ffmpeg就懒得编译了,因为官网已经有现成的了。

http://ffmpeg.zeranoe.com/builds/

 

 

Linux下的ffmpeg:

 

ffmpeg没有自带h264的编码库最起码会用到libx264,这个可以去网上下载last_stable_x264.tar.bz2。下面还有加入librtmp的编译。

 

解压成目录x264_stable

 

####进入x264-stable

./configure --prefix=/usr/local/x264 --enable-shared --enable-static --enable-yasm

make

make install

 

####编译ffmpeg:::::

sudo ./configure --enable-shared --disable-static --disable-yasm --enable-libx264  --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-pthreads--enable-librtmp --prefix=/home/linux/Work/ffmpeg3.2_linux --extra-cflags=-I/usr/local/x264/include --extra-ldflags=-L/usr/local/x264/lib

make

make install

 

###成功后,

去执行./ffmpeg 错误,缺少ffmpeg库,在/etc/ld.so.conf里加上路径,然后sudo ldconfig

之后还错误,缺少libx264.so.xxx库,这个要软连过去::

ln -sf /usr/local/x264/lib/libx264.so.148 /usr/lib/libx264.so.148

可以成功执行ffmpeg.

 

可以成功执行程序:

gcc -o  runtest test.c  -lpthread -lm -I. -L./lib_ffmpeg/lib -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc -lswscale -lswresample

 

如果程序出现但是出现错误

[h264_nvenc @ 0x1bb8160] Cannot load libcuda.so.1

那就是还没编译进x264

 

----重新编译ffmpeg链接librtmp

参考:http://blog.csdn.net/fireroll/article/details/8607955 

下载 http://rtmpdump.mplayerhq.hu/download/ 

 

主要步骤:(他的是把librtmp编成静态库,集成到ffmpeg)

cd rtmpdump

cd librtmp

gedit Makefile::

prefix=3RDLIB_INSTALL_PATH

...

#CRYPTO=OPENSSL

CRYPTO=

...

#SO_LDFLAGS_posix=-shared -Wl,-soname,$@

SO_LDFLAGS_posix=-Wl,-soname,$@ //////////这里可能没有,已经写在下面的编译里了。

...

#SHARED=yes

SHARED=no

 

make

cd .. (返回上一级目录)

make SYS=posix XDEF=-DNO_SSL CRYPTO= SHARED=  (这里参考了READMESYS=posix

make install

 

编译ffmpeg:

注释了configure里的enable librtmp 一行,加入一些编译项:

 

 

sudo ./configure --enable-shared --enable-static --disable-yasm --enable-libx264  --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-postproc --enable-pthreads --enable-librtmp --prefix=/home/linux/Work/ffmpeg3.2_linux --extra-cflags="-I/usr/local/librtmp/include -I/usr/local/x264/include"  --extra-ldflags="-L/usr/local/librtmp/lib -L/usr/local/x264/lib" --extra-libs="-lrtmp -lx264"

////之前一直不成功,是因为下错了librtmp,导致一直找不到RTMP_Socket ,现在使用的版本为2.3

sudo make

sudo make install

 

 

 

arm下的ffmpeg:

 

参考 http://blog.csdn.net/just__be__yourself/article/details/51872060

 

首先,arm下的ffmpeg将来会用到很多功能,例如编解码,网络媒体流等等,所以我编译了很多依赖进去。尤其是想要推流rtmp必须编译librtmp进去,否则推流会失败。

依赖的库有x264librtmpxvidcore

由于x264 librtmp也要交叉编译。

X264::

 http://blog.csdn.net/zjqlovell/article/details/48463913 

 

  1) [root@demo x264]# ./configure --enable-pthread --enable-static --enable-shared --host=arm-linux --disable-asm

 

  2)修改config.mak

 

SRCPATH=.

prefix=/usr/local/x264_arm

exec_prefix=${prefix}

bindir=${exec_prefix}/bin

libdir=${exec_prefix}/lib

includedir=${prefix}/include

SYS_ARCH=ARM

SYS=LINUX

CC=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-gcc

CFLAGS=-Wshadow -O3 -ffast-math  -Wall -I. -I$(SRCPATH) -std=gnu99 -D_GNU_SOURCE -fomit-frame-pointer -fno-tree-vectorize

COMPILER=GNU

COMPILER_STYLE=GNU

DEPMM=-MM -g0

DEPMT=-MT

LD=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-gcc -o

LDFLAGS= -L/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/lib -lm -L/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/lib -lpthread -L/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/lib -ldl

LIBX264=libx264.a

AR=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-ar rc

RANLIB=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-ranlib

STRIP=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-strip

 

make

sudo make install

成功。

 

###

librtmp::

http://blog.csdn.net/zjqlovell/article/details/47312453 

http://blog.csdn.net/chengkai_/article/details/52061960 

 

首先要编译两个依赖库有 zlib 和  openssl,所有的库都可以在其官网下载。

openssl

 

./config CC=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-gcc --prefix=/usr/local/openssl_arm

sudo make

sudo make install

 

zlib:

sudo ./configure

修改Makefile

CC=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-gcc

LDSHARED=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map

CPP=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-gcc -E

AR=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-ar

ARFLAGS=rc

RANLIB=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-ranlib

prefix =/usr/local/zlib_arm

 

sudo make

sudo make install

成功。

 

依赖库成功后,正式开始编译librtmp

////之前一直不成功,是因为下错了librtmp,导致一直找不到RTMP_Socket ,现在使用的版本为2.3

 

修改 librtmp/Makefile:::

prefix=/usr/local/librtmp_arm

 

XCFLAGS=-I/usr/local/include -I/usr/local/zlib_arm/include -I/usr/local/openssl_arm/include -L/usr/local/lib -L/usr/local/zlib_arm/lib -L/usr/local/openssl_arm/lib

 

CROSS_COMPILE=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-

 

SYS=posix

CRYPTO=OPENSSL

 

#SHARED=yes

SHARED=no

然后make 这个Makefile文件

再修改 源代码根目录下的Makefile

prefix=/usr/local/librtmp_arm

 

XCFLAGS=-I/usr/local/include -I/usr/local/zlib_arm/include -I/usr/local/openssl_arm/include

 

XLDFLAGS=-L/usr/local/lib -L/usr/local/zlib_arm/lib -L/usr/local/openssl_arm/lib

 

CROSS_COMPILE=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-

 

SYS=posix

#SYS=mingw

 

CRYPTO=OPENSSL

 

make SYS=posix CROSS_COMPILE=arm-hisiv200-linux- INC=-I/usr/local/include XDEF=-DNO_SSL CRYPTO= SHARED=

sudo make install

成功!

 

####

Libxvidcore :  

http://ftp.br.debian.org/debian-multimedia/pool/main/x/xvidcore/ 

 

 

开始编译ffmpeg:

这里依赖x264librtmpxvidcorelibzlibcryptolibssl,后两个都在openssl里::

 

sudo ./configure --enable-cross-compile --target-os=linux --arch=arm --enable-shared --disable-static --disable-yasm  --enable-libx264  --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-postproc --enable-libxvid --enable-pthreads --enable-librtmp --prefix=/home/linux/Work/ffmpeg3.2_hi200so --extra-cflags="-I/usr/local/librtmp_arm/include -I/usr/local/x264/include -I/usr/local/include -I/usr/local/openssl_arm/include -I/usr/local/zlib_arm/include -I/usr/local/xvid_arm/include"  --extra-ldflags="-L/usr/local/librtmp_arm/lib -L/usr/local/x264/lib -L/usr/local/lib -L/usr/local/openssl_arm/lib -L/usr/local/zlib_arm/lib -L/usr/local/xvid_arm/lib" --extra-libs="-lrtmp -lx264 -ldl -lssl -lcrypto -lz -lxvidcore" --cc=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-gcc

 

出错:

之前我编译的时候会出错:

arm-hisiv200-linux-gcc is unable to create an executable file.

C compiler test failed.

 

If you think configure made a mistake, make sure you are using the latest

version from Git.  If the latest version fails, report the problem to the

ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.

Include the log file "config.log" produced by configure as this will help

solve the problem.

 

》》》方法是要加入工具链的库,在/usr/local/lib 里,链接 上 -ldl

期间出现什么未找到,未定义,都是库路径或者没有加入该库。

还有出现的C compiler test failed.

都是工具链gcc路径不对,工具链没有加入头文件和库,没有加入-ldl

或者加入的x264librtmpxvidcorelibzlibcryptolibssl等没有交叉编译。

 

 

然后要修改config.mak

AR=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-ar

RANLIB=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-ranlib

STRIP=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-strip

只用修改这里

 

然后

sudo make

sudo make install

成功。

arm上运行,缺少库的话,都复制放在ffmpeglib里。运行./ffmpeg成功》

 

出错:

之前我运行程序错误:

Assertion v>0 && v<=(0 ? 32 : 16) failed at libavutil/mem.c:233

 

av_packet_free这里出错,

百度了:根据上述代码段,在FFmpeg编译configure时,尝试了将-enable-memalign-hack选项去掉,发现能正常工作了。不过,暂时还不清楚为什么会这样~~~

av_packet_free(&Gparg->v_queue->avPacket[i]);改回free就不报错。

在板子上ffmpeg,发现编译选项里多了-enable-memalign-hack这个选项,居然是我手动加入的......重新编译去掉这个选项,程序就不会出错了。