程序员人生 网站导航

使用nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器笔记(七)

栏目:综合技术时间:2015-03-17 08:37:49

第7部份

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

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

1、用到的源码包

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

增加对rtmp的支持下载nginx-rtmp-module,地址:https://github.com/arut/nginx-rtmp-module#example-nginxconf

openssl  :  http://www.openssl.org/source/

2、配置

我的步骤是:首先将上面的3个源码包放在了文件夹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 library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option.

添加nginx-rtmp-module模块需要Openssl library,百度下发现都是需要两条命令就能够了:

apt-get install openssl apt-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⑴.0.0q

这样不会出错了。

3、make

紧接着履行

make

经过漫长的充满希望的等待,最后完成终究还是出错了
/home/wangrui/456/openssl⑴.0.0q/.openssl/lib/libssl.a /home/wangrui/456/openssl⑴.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⑴.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⑴.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⑴.0.0q/.openssl/lib/libssl.a(s23_meth.o): Relocations in generic ELF (EM: 3) /home/wangrui/456/openssl⑴.0.0q/.openssl/lib/libssl.a: could not read symbols: File in wrong format collect2: ld returned 1 exit status make[1]: *** [objs/nginx] 毛病 1 make[1]:正在离开目录 `/home/wangrui/456/android-nginx' make: *** [build] 毛病 2

关键毛病在

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

在网上看到1篇文章:

could not read symbols报警

里面的1段话提示了我:

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

这个毛病多是由于在编译nginx和编译openssl的时候使用了不同的gcc,在编译openssl的时候可能使用了系统默许的gcc,致使arm环境下辨认不了libssl.a这个静态库。

查看下libssl.a的类型:

objdump -a /home/wangrui/456/openssl⑴.0.0q/.openssl/lib/libssl.a

其中

objdump -a xx.a

可以查看静态库文件是32位还是64位类型。

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

结果显示:

在归档文件 /home/wangrui/456/openssl⑴.0.0q/.openssl/lib/libssl.a 中: s2_meth.o: 文件格式 elf32-i386 rw-r--r-- 0/0 2148 Mar 5 10:14 2015 s2_meth.o s2_srvr.o: 文件格式 elf32-i386 rw-r--r-- 0/0 13304 Mar 5 10:14 2015 s2_srvr.o s2_clnt.o: 文件格式 elf32-i386 rw-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-gcc cp 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⑴.0.0q/.openssl/lib/libssl.a /home/wangrui/456/openssl⑴.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,完全的配置文件以下:

user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } rtmp { server { listen 1935; application myapp { live on; } application hls { live on; hls on; hls_path /data/misc/hls; } } } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /hls { types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /data/misc; add_header Cache-Control no-cache; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ .php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }

(6)将交叉编译完成的包移到ARM开发板上面

adb push /sdcard/nginx-rtmp2/ /data/misc/nginx-rtmp/

(7)进入到/data/misc/nginx-rtmp2/sbin目录下:

./nginx -p /data/misc/nginx-rtmp2 -c conf/nginx.conf

运行 nginx

(8)在ARM开发板阅读器中输入

http://localhost/

出现

Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.


总结:1个人弄这之前从没碰过的移植,真是各处碰壁阿,各种毛病只有你想不到,没有他出现不了的。不过当编译通过、安装成功以后兴奋感还是蛮不错的。继续加油。。。。


------分隔线----------------------------
------分隔线----------------------------

最新技术推荐