准备工作:

1.安装nginx和rtmp模块

2.安装ffmepg(用来推流)

以上准备工作参见这篇博客:http://www.cnblogs.com/damiao/p/5231221.html

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

让nginx支持HLS的更多相关文章

  1. 转: 基于nginx的hls直播系统

    转自:http://blog.csdn.net/cjsafty/article/details/9108587 看点: 1. 详细解解答了 nginx rtmp配置过程. 前写了一篇基于nginx的h ...

  2. Nginx搭建hls流媒体服务器

    第一种方案:ffmpeg+nginx   新的ffmpeg已经支持HLS.(本人也参与了代码供献,给自己做个广告:))   点播:   生成hls分片:   ffmpeg -i <媒体文件> ...

  3. Nginx支持比Apache高并发的原因

    1.先从各自使用的多路复用IO模型说起:  select模型:(apache使用,由于受模块等限制,用的不多)   单个进程能够 监视的文件描述符的数量存在最大限制 select()所维护的 存储大量 ...

  4. 配置Nginx支持SSL SNI(一个IP绑定多个证书) 以及Haproxy实现多域名证书

    概述 传统的每个SSL证书签发,每个证书都需要独立ip,假如你编译openssl和nginx时候开启TLS SNI (Server Name Identification) 支持,这样你可以安装多个S ...

  5. Nginx 支持 WAF 防护功能实战

    WAF(Web Application Firewall),中文名称叫做“Web应用防火墙 WAF的定义是这样的:Web应用防火墙是通过执行一系列针对HTTP/HTTPS的安全策略来专门为Web应用提 ...

  6. Nginx 支持 CI 框架的配置并禁止使用 ip 访问

    #CIserver {        listen      80;        server_name www.ci.com;        index       index.php index ...

  7. 让服务器apache/iis/nginx支持.apk/ipa文件下载

    服务器iis支持.apk文件下载的设置 IIS服务器不能下载.apk文件的原因:iis的默认MIME类型中没有.apk文件,所以无法下载. IIS服务器不能下载.apk文件的解决办法:既然.apk无法 ...

  8. Nginx支持连接数的问题

    据网上有人说nginx的配置中: nginx支持的最大连接数与以下因素有关: worker_processes ; events { worker_connections ; } ulimit -a ...

  9. 配置nginx,支持php的pathinfo路径模式

    nginx模式默认是不支持pathinfo模式的,类似index.php/index形式的url会被提示找不到页面.下面的通过正则找出实际文件路径和pathinfo部分的方法,让nginx支持path ...

随机推荐

  1. 工欲善其事必先利其器,用Emmet提高HTML编写速度

    HTML代码写起来很费事,因为它的标签多. 一种解决方法是采用模板,在别人写好的骨架内,填入自己的内容.还有一种很炫的方法----简写法. 常用的简写法,目前主要是Emmet和Haml两种.这两种简写 ...

  2. 在C#中使用.NET SDK创建控制

    下载示例工程 - 8 Kb 介绍 在这篇教程中,我将使用.NET架构创建一个简单的时钟控制示例,这个控制是一个显示当前时间的时钟,我将指导读者实现秒针并显示钟点数.文章加亮处是创建这个控制的关键点,读 ...

  3. centos7.2 安装 composer

    安装Composer https://pkg.phpcomposer.com/#how-to-install-composer  # 下载composer.phar curl -sS https:// ...

  4. imperva—waf 敏感字段显现

    imperva WAF中看到的日志内容信息有些都是敏感的  比如登录登出的信息 如何调整敏感信息的现实方式,并可以自定义敏感字段? 这里添加字段就可以了 这样就将******转变为明文了

  5. 【Pyhon】获取文件MIME类型,根据文件类型自定义文件后缀

    场景 下载样本,都是MD5命名的无后缀文件,需要自己手动查询然后修改文件后缀. 根据文件类型自定义后缀可以很方便地根据后缀判断用什么工具分析. 使用说明 libmagic 地址:https://pyp ...

  6. mysql5.7主从复制--在线变更复制类型【转】

    这里说一下关于如何在线变更复制类型(日志复制到全局事物复制),参考课程:mysql5.7复制实战 先决条件     (1)集群中所有的服务器版本均高于5.7.6(2)集群中所有的服务器gtid_mod ...

  7. PHP URL中包含中文,查看时提示404

    使用Microsoft Web Platform在IIS里配置安装一个wordpress,一切顺利. 当添加一片文章时,自动生成URL类似如下: http://localhost/wordpress/ ...

  8. 获取同一接口多个实现类的bean

    @Service("taskExecutorFactory") public class TaskExecutorFactory implements ApplicationCon ...

  9. MongoDB:数据导入CSV文件之错误记录

    测试主机1:Windows 10,MongoDB 3.6.3,WPS 10.1,Notepad++ 7.5.3, 测试主机2:Ubuntu 16.04,MongoDB 4, 今天测试了将数据从文件—— ...

  10. pyqt5-组件

    组件(widgets)是构建一个应用的基础模块.PyQt5有广泛的各式各样的组件,包含:复选按钮(QCheckBox),切换按钮(ToggleButton),滑块条(QSlider),进度条(Prog ...