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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章