live_m3u8
#EXTM3U
#EXT-X-VERSioN:3
#EXT-X-TARGETDURATION:5
#EXT-X-MEDIA-SEQUENCE:1465827036
#EXTINF:5.000,
#EXT-X-PROGRAM-DATE-TIME:2016-07-11T03:07:04Z
CHANNEL00000001/1660800/_1.ts
#EXTINF:5.000,
#EXT-X-PROGRAM-DATE-TIME:2016-07-11T03:07:09Z
CHANNEL00000001/1660800/_2.ts
#EXTINF:5.000,
#EXT-X-PROGRAM-DATE-TIME:2016-07-11T03:07:14Z
CHANNEL00000001/1660800/_3.ts
将上述m3u8文件保存为live.m3u8,放到Apache文档目录下,用VLC播放以下网址:
Http://localhost/live.m3u8
测试发现,开始播放的第一个文件不是_1.ts,多次测试后发现:
只要列表中的文件超过三个,播放的总是列表中的最后三个文件
live m3u8文件列表是需要实时更新的,我们做测试的话,可以先在最后面加上#EXT-X-ENDLIST,这个方法经测试有效,但这样已经不是live m3u8模式
live m3u8更新规则
live m3u8文件列表需要不断更新,更新规则:
移除一个文件播放列表中靠前的(认为已播放的)文件,不断更新EXT-X-MEDIA-SEQUENCE标签,以步长为1进行递增
生成m3u8
#!/bin/sh
echo "#EXTM3U"
echo "#EXT-X-MEDIA-SEQUENCE:1642"
echo "#EXT-X-TARGETDURATION:10"
for loop in `ls -rt *.ts`
do
echo "#EXTINF:10,"
echo $loop
done
echo "#EXT-X-ENDLIST"
nginx
user root;
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 0;
server {
listen 80;
server_name localhost;
location / {
if ($request_uri ~ ".*/./mp4\?fid=(.*?)&.*") {
rewrite ^(.*)/.*$ $1/$arg_fid? redirect;
}
root /opt1/voole_live_m3u8/;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
相关文章