准备工作:

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. day64_SpringMVC学习笔记_02

    1.springmvc对多视图的支持 (1)导入xml格式视图支持的jar包   注意:springmvc本身就支持xml格式,所以不用导入其他支持的jar包了. (2)在springmvc.xml中 ...

  2. 记一道有趣的Twitter面试题

    微信上的“程序员的那些事”想必是很多码农们关注的公众账号之一,我也是其粉丝,每天都会看看里面有没有什么趣事,前段时间“程序员的那些事”分享了一篇博文<我的Twitter技术面试失败了>挺有 ...

  3. tensorflow的卷积和池化层(二):记实践之cifar10

    在tensorflow中的卷积和池化层(一)和各种卷积类型Convolution这两篇博客中,主要讲解了卷积神经网络的核心层,同时也结合当下流行的Caffe和tf框架做了介绍,本篇博客将接着tenso ...

  4. 第9月第13天 传递lua匿名函数到c/c++

    1. lua函数都在refid_fun refid_fun[refid] = fun TOLUA_API int toluafix_ref_function(lua_State* L, int lo, ...

  5. sqlserver2008R2数据库自动备份脚本

    CREATE proc [dbo].[usp_autoBackupDB] @dbname sysname=null --要备份的数据库名,不指定即为全部备份 ,)='d:\' --备份目录路径 ,)= ...

  6. keepalived vrrp_script脚本不执行解决办法

    首先打开日志观察: tail -f /var/log/messages 然后新开一个客户端重启keepalived , systemctl restart keepalived.service 看日志 ...

  7. 【黑客免杀攻防】读书笔记10 - switch-case分支

    0x1 switch-case分支 switch-case其实就是if-else语句的另一种体现形式.但大于3之后的switchc-case.编译器会对代码进行优化. 1.1 简单switch-cas ...

  8. python模块分析之hashlib加密(二)

    前言 hashlib模块是py3.+用来对字符串进行hash加密的模块,核心算法是md5,明文与密文是一一对应不变的关系:用于注册.登录时用户名.密码等加密使用. 模块分析 hashlib模块有多种加 ...

  9. fastdfs:安装nginx

    #安装依赖 yum -y install gcc yum -y install gcc-c++ yum -y install zlib-devel yum -y install pcre-devel ...

  10. PHPWeb开发相关知识

    转载:https://blog.csdn.net/wj610671226/article/details/78426698 正则表达式 作用:分割.查找.匹配.替换字符串 分割符:正斜线(/).has ...