Nginx支持HLS配置

准备工作:

1.安装nginx和rtmp模块

2.安装ffmepg(用来推流)

以上准备工作参见这篇博客:http://www.jianshu.com/p/99f7b4581f8b

1.配置nginx

用记事本工具打开

/usr/local/etc/nginx/nginx.conf
找到server 修改

server {
listen 8080;
server_name localhost;

   #charset koi8-r;

   #access_log  logs/host.access.log  main;

   location / {
       root   html;
       index  index.html index.htm;
   }

   location /hls {
       # Serve HLS fragments
       types {
           application/vnd.apple.mpegurl m3u8;
           video/mp2t ts;
       }
       root html;
       add_header Cache-Control no-cache;
   }

   location /dash {
       # Serve DASH fragments
       root /tmp;
       add_header Cache-Control no-cache;
   }


   #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   html;
   }

   # proxy the PHP scripts to Apache listening on 127.0.0.1:80
   #
   #location ~ \.php$ {
   #    proxy_pass   http://127.0.0.1;
   #}

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
   #
   #location ~ \.php$ {
   #    root           html;
   #    fastcgi_pass   127.0.0.1:9000;
   #    fastcgi_index  index.php;
   #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
   #    include        fastcgi_params;
   #}

   # deny access to .htaccess files, if Apache's document root
   # concurs with nginx's one
   #
   #location ~ /\.ht {
   #    deny  all;
   #}

}
找到rtmp 修改下面这个地方

rtmp {
server {
listen 1935;
application live1 {
live on;
record off;
}

    # HLS

    # For HLS to work please create a directory in tmpfs (/tmp/hls here)
    # for the fragments. The directory contents is served via HTTP (see
    # http{} section in config)
    #
    # Incoming stream must be in H264/AAC. For iPhones use baseline H264
    # profile (see ffmpeg example).
    # This example creates RTMP stream from movie ready for HLS:
    #
    # ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264
    #    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
    #    -f flv rtmp://localhost:1935/hls/movie
    #
    # If you need to transcode live stream use 'exec' feature.
    #
    application hls {
        live on;
        hls on;
        hls_path /usr/local/var/www/hls;
    }

    # MPEG-DASH is similar to HLS

    application dash {
        live on;
        dash on;
        dash_path /tmp/dash;
    }
}

}
保存配置文件,重新加载nginx配置

/usr/local/Cellar/nginx-full/1.8.1/bin/nginx -s reload
2.进行推流测试

ffmpeg -loglevel verbose -re -i /Users/Rick/Movies/Demo.mov -vcodec libx264 -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://localhost:1935/hls/movie
然后你就可以在这个目录
/usr/local/var/www/hls
看到生成一个个ts的文件,还会生成一个movie.m3u8的文件

在Safari里输入地址查看视频(需要等movie.m3u8文件生成后),也可以用iPad或者iPhone上的Safari来访问(其他设备记得需要把localhost改为nginx的ip地址)
http://localhost:8080/hls/movie.m3u8

作者:嗷大喵
链接:https://www.jianshu.com/p/089b70f57bca
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值