使用nginx+nginx-rtmp-module+ffmpeg搭建流媒體服務(wù)器筆記(七)
來源:程序員人生 發(fā)布時(shí)間:2015-03-17 08:37:49 閱讀次數(shù):7593次
第7部份
之前已將標(biāo)準(zhǔn)版的Nginx移植到了ARM開發(fā)板上面并且運(yùn)行成功,而我的目的是要利用FFMPEG和NGINX來實(shí)現(xiàn)HLS視頻直播,所以還需要在此基礎(chǔ)上添加nginx-rtmp-module模塊。
有了之前的移植經(jīng)驗(yàn),有些工作就好做1些了,但是還是遇到很多的問題,記錄下:
1、用到的源碼包
android-nginx :
https://bitbucket.org/ntakimura/android-nginx/downloads
增加對(duì)rtmp的支持,下載nginx-rtmp-module,地址:https://github.com/arut/nginx-rtmp-module#example-nginxconf
openssl : http://www.openssl.org/source/
2、配置
我的步驟是:首先將上面的3個(gè)源碼包放在了文件夾456下,進(jìn)入/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
結(jié)果出現(xiàn)問題:
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,百度下發(fā)現(xiàn)都是需要兩條命令就能夠了:
apt-get install openssl
apt-get install libssl-dev
但是我履行時(shí)顯示我已安裝了最新版本,都已安裝好了,重試后還是出錯(cuò),那就在配置命令中添加:
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
這樣不會(huì)出錯(cuò)了。
3、make
緊接著履行
make
經(jīng)過漫長(zhǎng)的充滿希望的等待,最后完成終究還是出錯(cuò)了
/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
關(guān)鍵毛病在
/home/wangrui/456/openssl⑴.0.0q/.openssl/lib/libssl.a: could not read symbols: File in wrong format
趕快百度下,網(wǎng)上給出的答案基本上都是說之前make留下的有文件,影響到了這次的交叉編譯,建議換個(gè)新的源碼包重新編譯,但是我每次都是下載的新的源碼包還是出現(xiàn)一樣的毛病,可見我的毛病緣由不在這。
在網(wǎng)上看到1篇文章:
could not read symbols報(bào)警
里面的1段話提示了我:
“請(qǐng)肯定在操作系統(tǒng)位數(shù)相同的環(huán)境下進(jìn)行編譯,否則刪除原庫(kù)文件重新生成“
這個(gè)毛病多是由于在編譯nginx和編譯openssl的時(shí)候使用了不同的gcc,在編譯openssl的時(shí)候可能使用了系統(tǒng)默許的gcc,致使arm環(huán)境下辨認(rèn)不了libssl.a這個(gè)靜態(tài)庫(kù)。
查看下libssl.a的類型:
objdump -a /home/wangrui/456/openssl⑴.0.0q/.openssl/lib/libssl.a
其中
objdump -a xx.a
可以查看靜態(tài)庫(kù)文件是32位還是64位類型。
另外對(duì)動(dòng)態(tài)庫(kù) xx.so文件的類型查看使用 file 命令就能夠了。
結(jié)果顯示:
在歸檔文件 /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
其實(shí)不是ARM環(huán)境下的格式,也就是openssl編譯的時(shí)候用的是linux下默許的gcc致使出錯(cuò)。
知道大致的毛病緣由以后,便將openssl單獨(dú)交叉編譯下獲得libssl.a文件然后和之前的替換下。
(1)首先編寫配置文件 my_configure_openssl.sh
#!/bin/sh
./config no-asm shared
--prefix=/home/wangrui/nginx_ndk/build
(2)履行配置文件以后,進(jìn)入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目錄下會(huì)有l(wèi)ibssl.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 .ht
access 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開發(fā)板上面
adb push /sdcard/nginx-rtmp2/ /data/misc/nginx-rtmp/
(7)進(jìn)入到/data/misc/nginx-rtmp2/sbin目錄下:
./nginx -p /data/misc/nginx-rtmp2 -c conf/nginx.conf
運(yùn)行 nginx
(8)在ARM開發(fā)板閱讀器中輸入
http://localhost/
出現(xiàn)
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.
總結(jié):1個(gè)人弄這之前從沒碰過的移植,真是各處碰壁阿,各種毛病只有你想不到,沒有他出現(xiàn)不了的。不過當(dāng)編譯通過、安裝成功以后興奮感還是蠻不錯(cuò)的。繼續(xù)加油。。。。
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)