---
title: "Windows nginx RTMP ==> 直播&&点播"
author: "xiaojiit"
date: "2017-12-22T12:51:39Z"
tags: []
categories: ["Web前端"]
slug: "windows-nginx-rtmp"
draft: false
lastmod: "2017-12-22T12:51:39Z"
id: 2405434
url: "https://sharejava.iteye.com/blog/2405434"
---

> 部署环境：windows10  
> 最终结果：HLS点播（随意拖动进度条的那种）、直播（rtmp）、HLS直播（流转换）  
> 知识点：ffmpeg（强大的视音频工具）、nginx windows版本使用、直播点播介绍、obs工具 vlc工具的使用等  
> 协议：RTMP、HLS

* * *

> 参考：ubuntu 下 nginx 直播 点播 博客

[http://selimatmaca.com/index.php/live-streaming（英文](http://selimatmaca.com/index.php/live-streaming%EF%BC%88%E8%8B%B1%E6%96%87)）

| [Part1 - Live Streaming Introduction](http://selimatmaca.com/index.php/live-streaming/137-live-streaming) |

| [Part2 - Encoder Software - Adding IP Camera into OBS Studio](http://selimatmaca.com/index.php/live-streaming/138-encoder-software) |

| [Part3 - Installing Nginx with RTMP Module and Streaming RTMP](http://selimatmaca.com/index.php/live-streaming/139-installing-nginx-with-rtmp-module-and-hls-streaming) | |

| [Part4 - Installing FFMPEG with Extra Encoding and Decoding Libraries](http://selimatmaca.com/index.php/live-streaming/141-installing-ffmpeg-with-extra-encoding-and-decoding-libraries) | |

| [Part5 - HLS Streaming with Nginx Rtmp Module](http://selimatmaca.com/index.php/live-streaming/142-hls-streaming-with-nginx-rtmp-module) | |

| [Part6 - VideoJS Player for HLS Streaming](http://selimatmaca.com/index.php/live-streaming/143-videojs-player-for-hls-streaming) | |

| [Part7 - HLS Streaming over HTTPS](http://selimatmaca.com/index.php/live-streaming/145-hls-streaming-over-https) | |

* * *

#### 下载文件

> 为什么是这个版本呢 (nginx 1.7.11.3 Gryphon)（这是http://nginx-win.ecsds.eu/  
> 组织编译好的，非官方）  
> 这个版本好像是windows平台最后一款支持rtmp直播模块的nginx windows编译版本（非官方）

> 其他版本不行么？  
> 可以啊，自己编译（推荐虚拟机编译）

> vm虚拟机下载及密钥  
> [http://blog.csdn.net/qqduxingzhe/article/details/78217192](http://blog.csdn.net/qqduxingzhe/article/details/78217192)

下载 nginx 1.7.11.3 Gryphon  
[http://nginx-win.ecsds.eu/download/nginx 1.7.11.3 Gryphon.zip](http://nginx-win.ecsds.eu/download/nginx%201.7.11.3%20Gryphon.zip)

下载完成后解压；  
将解压后的目录名:nginx 1.7.11.3 Gryphon改成:nginx-1.7.11.3-Gryphon

下载服务器状态检查程序 stat.xsl  
[https://github.com/arut/nginx-rtmp-module/](https://github.com/arut/nginx-rtmp-module/)

将nginx-rtmp-module-master.zip解压后复制到目录:nginx-1.7.11.3-Gryphon下，  
保证stat.xls的目录为:nginx-1.7.11.3-Gryphon\\nginx-rtmp-module\\stat.xsl

* * *

#### 配置文件

> 想了解更多关于nginx的知识（尤其是服务器配置，可查看）  
> 《实战Nginx：取代Apache的高性能Web服务器》pdf电子书下载（本书有点老了，）  
> [http://blog.licess.com/nginx-pdf-download/](http://blog.licess.com/nginx-pdf-download/)

> nginx-1.7.11.3-Gryphon 文件夹下

配置文件 conf\\nginx-win.conf插入如下内容

> 1 rtmp 直播 接收端处理RTMP协议

```
rtmp { # 配置RTMP模块
    server { # 服务器
        listen 1935; # 监听端口, 默认为1935
        chunk_size 4000; # 数据块大小 4000
        application live { # 应用名称, 可理解为直播房间的名称
            live on; # 直播 [on]开启
        }
    }
}
```

> 2 HLS 直播 接收端处理HLS协议

```
rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        application hls {
            live on;
            hls on; # hsl开启
            hls_path C:/nginx-1.7.11.3-Gryphon/html/hls; # hls路径
            hls_fragment 5s; # hls碎片时间
        }
    }
}
```

* * *

#### 启动服务器

进入windows的cmd;

```
cd nginx-1.7.11.3-Gryphon
```

```
nginx.exe -c conf\nginx-win.conf
```

![2.png](http://upload-images.jianshu.io/upload_images/3858745-e9a0ac23ad96d057.png?imageMogr2%2Fauto-orient%2Fstrip%7CimageView2%2F2%2Fw%2F1240)

> [http://localhost/，可访问](http://localhost/%EF%BC%8C%E5%8F%AF%E8%AE%BF%E9%97%AE)

![1.png](http://upload-images.jianshu.io/upload_images/3858745-f9209f77b181a740.png?imageMogr2%2Fauto-orient%2Fstrip%7CimageView2%2F2%2Fw%2F1240)

* * *

#### 直播 播放端 OBS 开源 跨平台 可编程

> 前提：配置文件  
> OBS open broadcast software 下载  
> [https://obsproject.com/download](https://obsproject.com/download)

> 开启OBS，配置媒体源，当前为本地文件 licha.mkv  
> 配置OBS软件，参考：[http://selimatmaca.com/index.php/live-streaming/138-encoder-software](http://selimatmaca.com/index.php/live-streaming/138-encoder-software)

![2.png](http://upload-images.jianshu.io/upload_images/3858745-8dc38f933e3c7b2d.png?imageMogr2%2Fauto-orient%2Fstrip%7CimageView2%2F2%2Fw%2F1240)

> 配置OBS，流媒体  
> rtmp 协议  
> localhost 自定义流媒体服务器访问地址  
> live 最上面的配置文件 application live  
> test 1流名称 hls协议，或者 2流密钥 rtmp协议

![3.png](http://upload-images.jianshu.io/upload_images/3858745-4e568d9341d4df02.png?imageMogr2%2Fauto-orient%2Fstrip%7CimageView2%2F2%2Fw%2F1240)

![4.png](http://upload-images.jianshu.io/upload_images/3858745-673d2de9682b19af.png?imageMogr2%2Fauto-orient%2Fstrip%7CimageView2%2F2%2Fw%2F1240)

> 点击，开启推流

* * *

#### windows演示 ==&gt; 直播 接收端 VLC 开源 跨平台

> 1 最上面的配置文件，配置RTMP直播  
> 上述，配置好OBS之后，  
> VLC打开网络串流，访问，[rtmp://localhost/live/test]()

![6.png](http://upload-images.jianshu.io/upload_images/3858745-568283320f7bbbee.png?imageMogr2%2Fauto-orient%2Fstrip%7CimageView2%2F2%2Fw%2F1240)

> 2 最上面的配置文件，配置HLS直播

![7.png](http://upload-images.jianshu.io/upload_images/3858745-bdb00bda5d12910b.png?imageMogr2%2Fauto-orient%2Fstrip%7CimageView2%2F2%2Fw%2F1240)

* * *

#### android ==&gt; 直播 接收端 VLC

> Android 如何直播RTMP流 HLS流

> [http://www.truiton.com/2015/03/stream-rtmp-live-android/（英文](http://www.truiton.com/2015/03/stream-rtmp-live-android/%EF%BC%88%E8%8B%B1%E6%96%87)）  
> 开启chrome翻译的话，看起来难度不大

> vlc lib android 文档  
> [https://wiki.videolan.org/LibVLC/#libVLC\_on\_Android](https://wiki.videolan.org/LibVLC/#libVLC_on_Android)

* * *

#### web 浏览器 ==&gt; 直播 接收端 js

videojs

> videojs的话，支持RTMP 需要额外的插件，可能以后都不支持RTMP了  
> flash可能、马上、很快，要死了？

* * *

#### 参考文章

> windows下 OBS+nginx 实现rtmp直播流的基础搭建  
> [http://www.jianshu.com/p/0e751c8b8fed](http://www.jianshu.com/p/0e751c8b8fed)

> 很多，，

* * *