windows部署nginx+rtmp服务器并进行推拉流

音视频应用开发系列文章目录

准备资源

OBS:用于推流

VLC:用于拉流

NGINX4WIN:前人Windows编译版http://nginx-win.ecsds.eu/download/nginx 1.7.11.3 Gryphon.zip

NGINX源码:自行编译的可以下载http://nginx.org/download/

nginx-rtmp-module:https://github.com/arut/nginx-rtmp-module/

配置NGINX

解压“nginx 1.7.11.3 Gryphon.zip” -> nginxroot

解压“nginx-rtmp-module-master.zip” -> nginx-rtmp-module

将nginx-rtmp-module文件夹放到nginxroot根目录下

进入nginxroot/conf目录下,复制文件nginx-win.conf -> nginx-win-rtmp.conf

在nginx-win-rtmp.conf中添加rtmp配置,添加后完整配置如下


#user  nobody;
# multiple workers works !
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  8192;
    # max value 32768, nginx recycling connections+registry optimization = 
    #   this.value * 20 = max concurrent connections currently tested with one worker
    #   C1000K should be possible depending there is enough ram/cpu power
    # multi_accept on;
}

# 新添加rtmp字段
rtmp {
	server {
		listen 1935; # rtmp监听端口 
		chunk_size 4000; # 块大小
		application live { # rtmp推流路径
			live on; # 开启实时
			hls on; # 开启hls
			hls_path E:/install/nginx/nginx-1.7.11.3-Gryphon/html/rtmp_live; # rtmp推流缓存路径
			hls_fragment 5s; # 每个TS文件包含5秒视频
		}
	}
}

http {
    #include      /nginx/conf/naxsi_core.rules;
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr:$remote_port - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

#     # loadbalancing PHP
#     upstream myLoadBalancer {
#         server 127.0.0.1:9001 weight=1 fail_timeout=5;
#         server 127.0.0.1:9002 weight=1 fail_timeout=5;
#         server 127.0.0.1:9003 weight=1 fail_timeout=5;
#         server 127.0.0.1:9004 weight=1 fail_timeout=5;
#         server 127.0.0.1:9005 weight=1 fail_timeout=5;
#         server 127.0.0.1:9006 weight=1 fail_timeout=5;
#         server 127.0.0.1:9007 weight=1 fail_timeout=5;
#         server 127.0.0.1:9008 weight=1 fail_timeout=5;
#         server 127.0.0.1:9009 weight=1 fail_timeout=5;
#         server 127.0.0.1:9010 weight=1 fail_timeout=5;
#         least_conn;
#     }

    sendfile        off;
    #tcp_nopush     on;

    server_names_hash_bucket_size 128;

```
```

}

启动NGINX

win命令行下进入nginxroot目录

运行nginx.exe -c conf/nginx-win-rtmp.conf

nginx+rtmp服务启动,现在可进行推拉流

OBS推流

FFMPEG推流

若没有OBS和摄像头,可用ffmpeg命令进行本地媒体文件推流

ffmpeg -re -i xxx.mp4 -c copy -f flv rtmp://192.168.30.191:1935/live

VLC拉流

FFMPEG拉流

ffplay rtmp://192.168.30.191:1935/live

发布了131 篇原创文章 · 获赞 195 · 访问量 38万+

猜你喜欢

转载自blog.csdn.net/KayChanGEEK/article/details/102843083