如何更改Nginx hls文件的名称?

时间:2019-01-04 02:12:06

标签: ubuntu nginx hls

使用本教程,我已经成功为Nginx设置了配置文件,该文件几乎可以完美运行。

https://www.vultr.com/docs/setup-nginx-on-ubuntu-to-stream-live-hls-video

唯一的问题是它输出的文件名是“ index.m3u8”,而我希望它是“ playlist.m3u8”。

我的网址目前看起来像这样,用于访问流。 https://myurl.com/live/test/index.m3u8 而我想要的是https://myurl.com/live/test/playlist.m3u8

这是我的配置文件:)

worker_processes  auto;
error_log  logs/error.log debug;

events {
	worker_connections  1024;
}

rtmp {
	server {
	listen 1935;
	allow play all;

#creates our "live" full-resolution HLS videostream from our incoming encoder stream and tells where to put the HLS video manifest and video fragments
	application live {
		allow play all;
		live on;
		record off;
		hls on;
		hls_nested on;
		hls_path /HLS/live;
		hls_fragment 10s;

	#creates the downsampled or "trans-rated" mobile video stream as a 400kbps, 480x360 sized video
		exec ffmpeg -i rtmp://localhost:1935/$app/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -s 480x360 -b:v 400k maxrate 400k -bufsize 400k -threads 0 -r 30 -f flv rtmp://localhost:1935/mobile/$;
	}

#creates our "mobile" lower-resolution HLS videostream from the ffmpeg-created stream and tells where to put the HLS video manifest and video fragments
	application mobile {
		allow play all;
		live on;
		hls on;
		hls_nested on;
		hls_path /HLS/mobile;
		hls_fragment 10s;
	}

	# #allows you to play your recordings of your live streams using a URL like "rtmp://my-ip:1935/vod/filename.flv"
	# application vod {
	# play /video_recordings;
	# }
	}
}


http {
include       mime.types;
default_type  application/octet-stream;

server {
listen 80;
server_name localhost;

#creates the http-location for our full-resolution (desktop) HLS stream - "http://my-ip/live/my-stream-key/index.m3u8"      
location /live {
	types {
		application/vnd.apple.mpegurl m3u8;
	}
	alias /HLS/live;
	add_header Cache-Control no-cache;
}

#creates the http-location for our mobile-device HLS stream - "http://my-ip/mobile/my-stream-key/index.m3u8"        
location /mobile {
	types {
		application/vnd.apple.mpegurl m3u8;
	}
	alias /HLS/mobile;
	add_header Cache-Control no-cache;
}   

#allows us to see how stats on viewers on our Nginx site using a URL like: "http://my-ip/stats"     
location /stats {
	stub_status;
}
#allows us to host some webpages which can show our videos: "http://my-ip/my-page.html"     
location / {	
	root   html;
	index  index.html index.htm;
}   
}
}

我将很高兴能获得所有的帮助。

关于丹尼尔。

1 个答案:

答案 0 :(得分:1)

作为一种简单的解决方法,您可以创建从index.m3u8playlist.m3u8的符号链接

exec ln -sf /HLS/$app/$name/index.m3u8 /HLS/$app/$name/playlist.m3u8;

将其添加到application live块内

application live {
        allow play all;
        live on;
        record off;
        hls on;
        hls_nested on;
        hls_path /HLS/live;
        hls_fragment 10s;

        #creates the downsampled or "trans-rated" mobile video stream as a 400kbps, 480x360 sized video
        exec ffmpeg -i rtmp://localhost:1935/$app/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -s 480x360 -b:v 400k maxrate 400k -bufsize 400k -threads 0 -r 30 -f flv rtmp://localhost:1935/mobile/$;
        exec ln -sf /HLS/$app/$name/index.m3u8 /HLS/$app/$name/playlist.m3u8;
}