ubuntu18.04 nginx配置播放

之前章节讲了如何编辑安装播放mp4需要的模块

接下说说,怎么配置ginx,下面共两个文件

在nginx.conf 的http区块未尾新增一个
include player.conf
然后在同级目录新建一个文本player.conf
内容如下

server {
		listen 8080;
		server_name localhost;

		#charset koi8-r;

		#access_log  logs/host.access.log  main;
		root /mnt/c/player;
		index index.html index.htm;

		location / {
			# mp4;
			# mp4_buffer_size 1m;
			# mp4_max_buffer_size 5m;
			# limit_rate 50k;
		}

		#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   /mnt/c/player;
		}


		location /control {
			# 开始录制 curl "http://localhost:8080/control/record/start?app=hls&name=demo&rec=rec1"
			# 停止录制 curl "http://localhost:8080/control/record/stop?app=hls&name=demo&rec=rec1"
			rtmp_control all;
		}


		# This URL provides RTMP statistics in XML
		location /stat {
			rtmp_stat all;

			# Use this stylesheet to view XML as web page
			# in browser
			rtmp_stat_stylesheet stat.xsl;
		}


		location /stat.xsl {
			# XML stylesheet to view RTMP stats.
			# Copy stat.xsl wherever you want
			# and put the full directory path here
			root /mnt/c/player/stat;
		}

		location /hls {

			# Serve HLS fragments

			types {
				application/vnd.apple.mpegurl m3u8;
				video/mp2t ts;
			}


			alias /mnt/c/player/rtmp/hls;
			expires -1;


			add_header Cache-Control no-cache;
		}
		# location ~* .flv$ 
		# {
		# 	flv;
		# }
		location ~* .mp4$
		# location ~ .*.mp4$
		# location ~ \.mp4$
		# location ~* /mp4s
		# location ~* .*\.(mp4|flv)$ 
		{
			# try_files      $uri =404;
			# root /mnt/c/player;
			mp4;
			mp4_buffer_size 1m;
			mp4_max_buffer_size 5m;
			# 下载1m后再限速
			limit_rate_after 1m;
			limit_rate 512k;
			# limit_conn perip 1; #1.15版本
			# limit_conn perserver 1; #1.15版本
			# mp4_limit_rate_after 30s; #1.15版本
			# mp4_limit_rate on; #1.15版本
		}
}

在nginx.conf 的未尾新增一个
include rtmp.conf
然后在同级目录新建一个文本rtmp.conf
内容为

rtmp {
    server {
		# rtmp默认端口
		listen 1935;
		# 数据传输块的大小
		chunk_size 4096;
		# 多个频道的直播就可以live_cctv1、live_cctv2名字
		application live{
			# enable live streaming
			live on;

			max_connections 1024;

			recorder rec1 {
			    record all manual; 
			    record_suffix -%Y-%m-%d-%H_%M_%S.mp4; 
			    record_unique on; 
			    record_path /mnt/c/player/rtmp/mp4s;
			} 

			# publish only from localhost
			allow publish 127.0.0.1;
			deny publish all;

			#allow play all;
		}

		application hls{
			live on;
			# 把直播服务器改成可实时回放
			hls on;
			# 对视频切片进行保护,防止马赛克
			wait_key on;
			# 每个视频切片的时长
			hls_fragment 10s;
			# 可以回看的时间
			hls_playlist_length 60s;
			# 播放切片视频文件hls存放位置
			hls_path /mnt/c/player/rtmp/hls;
			# 连续模式
			hls_continuous on;
			# 对多余的切片进行删除
			hls_cleanup off;
			# 嵌套模式
			hls_nested on;

			recorder rec1 {
			    record all manual;
			    record_suffix -%Y-%m-%d-%H_%M_%S.mp4;
			    record_unique on;
				# 录制视频文件flv存放路径
			    record_path /mnt/c/player/rtmp/mp4s;
			}

		}

		# video on demand
		application vod {
			# 播放视频文件flv存放路径
			play /mnt/c/player/rtmp/flvs;
		}

		application vod2 {
			# 播放视频文件mp4存放路径
			play /mnt/c/player/rtmp/mp4s;
		}

    }
    
}
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注