博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 使用Nginx rtmp 模块
阅读量:6576 次
发布时间:2019-06-24

本文共 4823 字,大约阅读时间需要 16 分钟。

  hot3.png

1,编译android上面可以使用的nginx,添加选项--add-module=/path/nginx-rtmp-module,准备android上面shell可以使用的ffmpeg和相关库文件以及m3u8的segmenter文件
2,在手机的data/data/android.nginx目录下把编译生成的nginx相关文件放到该目录下
3,编写配置文件
-----------------------------------nginx.conf start here----------------------------------------------------
user root;
worker_processes 2;
error_log /data/data/android.nginx/logs/error.log;
error_log /data/data/android.nginx/logs/error.log notice;
error_log /data/data/android.nginx/logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 4096;
application myapp {
live on;
}
}
}
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 801;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /data/data/android.rtmp;
}
location / {
root /data/data/android.rtmp/test/rtmp-publisher;
}
}
server {
listen 80 default;
server_name localhost;
autoindex on;
autoindex_exact_size on;
root /data/data/android.wwwroot;
index index.html index.htm index.php;
#charset koi8-r;
#access_log logs/host.access.log main;
#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$ {
fastcgi_index index.php;
client_max_body_size 64m;
fastcgi_pass unix:/data/data/android.php-fpm/tmp/php-fpm.socket;
fastcgi_param SCRIPT_FILENAME /data/data/android.wwwroot$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.flv$ {
flv;
}
location ~ \.mp4$ {
mp4;
}
# 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 default;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 default;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!
;
# ssl_prefer_server_ciphers on;
# location / {
# root 
;
# index index.html index.htm;
# }
#}
}
-----------------------------------nginx.conf end here----------------------------------------------------
4,adb push nginx.conf /data/data/android.nginx/conf/
5,启动nginx,在/data/data/android.nginx目录下,执行./nginx -c ./conf/nginx.conf
6,准备ffmpeg文件
adb shell
su
chmod 777 /system/bin/
adb push ffmpeg /system/bin/
adb shell
su
cd system/bin
chmod 777 ffmpeg
exit
exit
adb push libvorbisenc.so.2 /system/lib
adb push libvorbis.so.0 /system/lib
adb push libogg.so.0 /system/lib
adb push libtheoraenc.so.1 /system/lib
adb push libtheoradec.so.1 /system/lib
adb push libmp3lame.so.0 /system/lib
adb push libfdk-aac.so.0 /system/lib
adb push segmenter /system/bin
adb shell
su
cd /system/bin
chmod 777 segmenter
exit
exit
7,准备相关文件
adb push 1.flv /data/data/android.wwwroot/
8,准备rtmp相关文件
在/data/data/目录下建立rtmp目录,使用adb push的方法把nginx-rtmp-module目录下所有文件push到/data/data/rtmp目录下
修改该目录下的./test/rtmp-publisher/player.html
---------------------------player.html start here---------------------------------------------------------------
!DOCTYPE html>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var flashVars = {
streamer: 'rtmp://192.168.1.2/myapp',
file:'test1'
}; 
swfobject.embedSWF("RtmpPlayer.swf", "rtmp-publisher", "500", "400", "9.0.0",null, flashVars); 
</script>

Flash not installed

---------------------------player.html end here---------------------------------------------------------------
9,推流
"rtmp://192.168.1.2/myapp"表示url, "test1"表示stream
推流方式1:ffmpeg -re -i 1.flv -f flv rtmp://192.168.1.2/myapp/test1
注意:要把相关文件push到
我这里把这个简单写成pushrtmp的批处理
---------------------------------pushrtmp start here-----------------------------------------------------------
!/system/bin/sh
file=$1 
file_name=`echo ${file} | busybox awk -F '.' '{ print $1 "" }'` 
ffmpeg -re -i ./$1.flv -f flv rtmp://192.168.1.$2/myapp/test1
---------------------------------pushrtmp end here-----------------------------------------------------------
执行方式就是简单的./pushrtmp 1 2就可以了
10,测试
在另一台机器上访问http://192.168.1.2:801/player.html就可以了

转载于:https://my.oschina.net/doz/blog/69019

你可能感兴趣的文章
sql语句之查询操作
查看>>
angularJS表达式详解!
查看>>
jquery的一点点认识
查看>>
localhost或本机ip无法连接数据库问题解决与原因
查看>>
git的基本使用
查看>>
Latent Semantic Analysis (LSA) Tutorial第一部分(转载)
查看>>
【CF311E】biologist
查看>>
将vim打造成python开发工具
查看>>
sql中去掉字段的所有空格
查看>>
添加头像
查看>>
Django 模板层
查看>>
Html5学习进阶一 视频和音频
查看>>
ap.net core 教程(三)
查看>>
【转】虚拟机下安装小红帽Linux9.0图解
查看>>
经验的总结,需要记录。
查看>>
我的家庭私有云计划-21
查看>>
运维人员如何最大限度避免误删除文件(20160627更新)
查看>>
《构建高可用Linux服务器(第二版)》正式发售
查看>>
Nginx upstream的几种分配方式
查看>>
高薪源于专注和极致!
查看>>