module+ffmpeg搭建流媒体服务器笔记(七)

第七部分

之前已经将标准版的Nginx移植到了ARM开发板上面并且运行成功,而我的目的是要利用FFMPEG和NGINX来实现HLS视频直播,所以还需要在此基础上添加nginx-rtmp-module模块。

有了之前的移植经验,有些工作就好做一些了,但是还是遇到很多的问题,记录下:

1、用到的源码包

android-nginx : https://bitbucket.org/ntakimura/android-nginx/downloads

增加对rtmp的支持,下载nginx-rtmp-module,地址:

openssl :

2、配置

我的步骤是:首先将上面的三个源码包放在了文件夹456下,进入/456/android/nginx目录下执行配置命令:

auto/configure–crossbuild=android-arm–prefix=/sdcard/nginx-rtmp2 –add-module=/home/wangrui/456/nginx-rtmp-module–with-cc=/home/wangrui/local/android-toolchain/bin/arm-linux-androideabi-gcc–without-pcre –without-http_rewrite_module    –without-http_userid_module –with-cc-opt=-Wno-sign-compare结果出现问题:

auto/configure: error: SSL modules require the OpenSSL library.You can either do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using –with-openssl=<path> option.添加nginx-rtmp-module模块需要Openssl library,百度下发现都是需要两条命令就可以了:

apt-get install opensslapt-get install libssl-dev但是我执行时显示我已经安装了最新版本,都已经安装好了,重试后还是出错,那就在配置命令中添加:

auto/configure–crossbuild=android-arm–prefix=/sdcard/nginx-rtmp2 –add-module=/home/wangrui/456/nginx-rtmp-module–with-cc=/home/wangrui/local/android-toolchain/bin/arm-linux-androideabi-gcc–without-pcre –without-http_rewrite_module      –without-http_userid_module –with-cc-opt=-Wno-sign-compare –with-openssl=/home/wangrui/456/openssl-1.0.0q这样不会出错了。

3、make

紧接着执行

make经过漫长的充满希望的等待,最后完成终于还是出错了/home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a /home/wangrui/456/openssl-1.0.0q/.openssl/lib/libcrypto.a -lz/home/wangrui/local/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: /home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a(s23_meth.o): Relocations in generic ELF (EM: 3)/home/wangrui/local/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: /home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a(s23_meth.o): Relocations in generic ELF (EM: 3)/home/wangrui/local/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: /home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a(s23_meth.o): Relocations in generic ELF (EM: 3)/home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a: could not read symbols: File in wrong formatcollect2: ld returned 1 exit statusmake[1]: *** [objs/nginx] 错误 1make[1]:正在离开目录 `/home/wangrui/456/android-nginx'make: *** [build] 错误 2

关键错误在

/home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a: could not read symbols: File in wrong format赶紧百度下,网上给出的答案基本上都是说以前make留下的有文件,影响到了这次的交叉编译,建议换个新的源码包重新编译,但是我每次都是下载的新的源码包还是出现同样的错误,可见我的错误原因不在这。

在网上看到一篇文章:

里面的一段话提醒了我:

“请确定在操作系统位数相同的环境下进行编译,否则删除原库文件重新生成“

这个错误可能是因为在编译nginx和编译openssl的时候使用了不同的gcc,在编译openssl的时候可能使用了系统默认的gcc,导致arm环境下识别不了libssl.a这个静态库。

查看下libssl.a的类型:

objdump -a /home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a其中

objdump -a xx.a可以查看静态库文件是32位还是64位类型。

另外对于动态库 xx.so文件的类型查看使用 file 命令就可以了。

结果显示:

在归档文件 /home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a 中:s2_meth.o:文件格式 elf32-i386rw-r–r– 0/0 2148 Mar 5 10:14 2015 s2_meth.os2_srvr.o:文件格式 elf32-i386rw-r–r– 0/0 13304 Mar 5 10:14 2015 s2_srvr.os2_clnt.o:文件格式 elf32-i386rw-r–r– 0/0 12740 Mar 5 10:14 2015 s2_clnt.o 。。。。。。 可见文件格式为 elf32-i386并不是ARM环境下的格式,也就是openssl编译的时候用的是linux下默认的gcc导致出错。

知道大致的错误原因之后,便将openssl单独交叉编译下获取libssl.a文件然后和之前的替换下。

(1)首先编写配置文件 my_configure_openssl.sh

#!/bin/sh./config no-asm shared \–prefix=/home/wangrui/nginx_ndk/build \(2)执行配置文件之后,进入Makefile,修改Makefile文件

找到CC= gcc,替换为CC= /home/wangrui/local/android-toolchain/bin/arm-linux-androideabi-gcc找到AR= ar $(ARFLAGS) r,替换为AR= /home/wangrui/local/android-toolchain/bin/arm-linux-androideabi-ar $(ARFLAGS) r找到RANLIB= /usr/bin/ranlib,替换为RANLIB= /home/wangrui/local/android-toolchain/bin/arm-linux-androideabi-ranlib找到NM= nm,修改为NM= /home/wangrui/local/android-toolchain/bin/arm-linux-androideabi-nm找到MAKEDEPPROG= gcc,,修改为MAKEDEPPROG= /home/wangrui/local/android-toolchain/bin/arm-linux-androideabi-gcccp Makefile Makefile.ok

(3)执行 make && make install

这样在/home/wangrui/nginx_ndk/build/lib目录下会有libssl.a和libcrypto.a文件

然后进入到/home/wangrui/456/android-nginx/objs目录下修改Makefile文件:

将其中的两处

/home/wangrui/456/openssl-1.0.0q/.openssl/lib/libssl.a /home/wangrui/456/openssl-1.0.0q/.openssl/lib/libcrypto.a -lz修改为

/home/wangrui/nginx_ndk/build/lib/libssl.a /home/wangrui/nginx_ndk/build/lib/libcrypto.a -lz然后重新 make

成功

(4) make install

完成。

(5)修改nginx.conf文件,使其支持rtmp和hls,完整的配置文件如下:

何愁没有快乐的泉溪在歌唱,何愁没有快乐的鲜花绽放!

module+ffmpeg搭建流媒体服务器笔记(七)

相关文章:

你感兴趣的文章:

标签云: