1、ubuntu打开摄像头
虚拟机打开Camare功能,查看/dev/video1设备
ffmpeg -f video4linux2 -framerate 20 -video_size 640*480 -i /dev/video0 -f flv rtmp://192.168.27.129/live
2、nginx部署,
/usr/local/nginx/sbin/nginx -s reload
其中nginx和rtmp模块源码下载到如下。
编译ngx+rtmp,
./configure --with-debug --prefix=/usr/local/nginx --add-module=/opt/nginx-rtmp-module --with-http_ssl_module
make
make install
nginx启动,
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx -s reload
3、电脑端/手机端打开vlc,访问。手机端如果访问,需要在虚拟机增加NAT配置,其中192.168.27.129为虚拟机IP。
手机端访问电脑的192.168.7.41
rtmp://192.168.7.41:8091/live
4、当电脑端和手机端同时访问时,观察nginx日志,ps -ef | grep nginx
查看21221进程的socket信息,fd11是电脑打开vlc时的socket,fd12是手机打开vlc时的socket。
2020/09/01 08:03:35 [debug] 21221#0: *20 RTMP send nmsg=1, priority=2 #201
2020/09/01 08:03:35 [debug] 21221#0: *20 send: fd:12 272 of 272
2020/09/01 08:03:35 [error] 21221#0: *20 try send data len[272],sendlen[272] (110: Connection timed out), client: 192.168.1.144, server: 0.0.0.0:1935
2020/09/01 08:03:35 [debug] 21221#0: *17 RTMP send nmsg=1, priority=2 #185
2020/09/01 08:03:35 [debug] 21221#0: *17 send: fd:11 272 of 272
2020/09/01 08:03:35 [error] 21221#0: *17 try send data len[272],sendlen[272] (110: Connection timed out), client: 192.168.27.1, server: 0.0.0.0:1935
2020/09/01 08:03:35 [error] 21221#0: *17 s->out_queue[256],out_pos[184] (110: Connection timed out), client: 192.168.27.1, server: 0.0.0.0:1935
可以看到,两个链接fd,接收数据时的队列不同,fd11队列已经累计到201,fd12队列累计到185