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

第七部分

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

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

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、配置

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

在网上看到一篇文章:

could not read symbols报警

里面的一段话提醒了我:

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

这个错误可能是因为在编译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-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-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,完整的配置文件如下:

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.  


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


  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值