Skip to content

Commit

Permalink
Merge pull request #25 from winshining/master
Browse files Browse the repository at this point in the history
Sync from winshining/master
  • Loading branch information
plainheart authored Mar 1, 2019
2 parents 61b693c + 4725500 commit e54c725
Show file tree
Hide file tree
Showing 39 changed files with 1,563 additions and 3,004 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ install:
- cd nginx-1.12.2

script:
- ./configure --add-module=../nginx-http-flv-module && make
- ./configure --add-dynamic-module=../nginx-http-flv-module && make
- ./configure --add-module=../nginx-http-flv-module && make -j 8
- ./configure --add-dynamic-module=../nginx-http-flv-module && make -j 8
23 changes: 23 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,26 @@ Project author:
Contacts:
[email protected]
[email protected]

han4235
Suzhou, China

Contacts:
https://github.com/han4235

plainheart
Zhengzhou, China

Contacts:
https://github.com/plainheart

HeyJupiter:
Seattle, US

Contacts:
https://github.com/HeyJupiter

Vladimir Vainer

Contacts:
https://github.com/ferreus
85 changes: 68 additions & 17 deletions README.CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,35 @@

基于[nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module)的流媒体服务器。

[English README](https://github.com/winshining/nginx-http-flv-module/blob/master/README.md)

如果您喜欢这个模块,可以通过赞赏来支持我的工作,非常感谢!

![reward_qrcode_winshining](https://raw.githubusercontent.com/wiki/winshining/nginx-http-flv-module/reward_qrcode_winshining.png)

### 感谢

* Igor Sysoev,[NGINX](http://nginx.org)的作者。

* Roman Arutyunyan,[nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module)的作者。

* 贡献者,详情见[AUTHORS](https://github.com/winshining/nginx-http-flv-module/blob/master/AUTHORS)

# 功能

* [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module)提供的所有功能。

* nginx-http-flv-module的其他功能与[nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module)的对比:

| 功能 | nginx-http-flv-module | nginx-rtmp-module | 备注 |
| :--------------: | :-------------------: | :---------------: | :--------------------------: |
| HTTP-FLV (播放) || x | 支持HTTPS-FLV和chunked回复 |
| GOP缓存 || x | 仅适用于H.264视频和AAC音频 |
| 虚拟主机 || x | |
| 省略`listen`配置 || x | |
| 功能 | nginx-http-flv-module | nginx-rtmp-module | 备注 |
| :--------------: | :-------------------: | :---------------: | :------------------------------------: |
| HTTP-FLV (播放) || x | 支持HTTPS-FLV和chunked回复 |
| GOP缓存 || x | 仅适用于H.264视频和AAC音频 |
| 虚拟主机 || x | |
| 省略`listen`配置 || 见备注 | 配置中必须有一个`listen` |
| 纯音频支持 || 见备注 | `wait_video``wait_key`开启后无法工作 |
| 定时打印访问记录 || x | |
| JSON风格的stat || x | |

# 支持的系统

Expand All @@ -25,17 +42,21 @@

* [VLC](http://www.videolan.org) (RTMP & HTTP-FLV)/[OBS](https://obsproject.com) (RTMP & HTTP-FLV)/[JW Player](https://www.jwplayer.com) (RTMP)/[flv.js](https://github.com/Bilibili/flv.js) (HTTP-FLV).

## 注意

[flv.js](https://github.com/Bilibili/flv.js)只能运行在支持[Media Source Extensions](https://www.w3.org/TR/media-source)的浏览器上。

# 依赖

* 在类Unix系统上,需要GNU make,用于调用编译器来编译软件。

* 在类Unix系统上,需要GCC/在Windows上,需要MSVC,用于编译软件。
* 在类Unix系统上,需要GCC。或者在Windows上,需要MSVC,用于编译软件。

* 在类Unix系统上,需要GDB,用于调试软件(可选)。

* FFmpeg,用于发布媒体流。
* [FFmpeg](http://ffmpeg.org)或者[OBS](https://obsproject.com),用于发布媒体流。

* VLC播放器(推荐),用于播放媒体流。
* [VLC](http://www.videolan.org)(推荐)或者[flv.js](https://github.com/Bilibili/flv.js)(推荐),用于播放媒体流。

* 如果NGINX要支持正则表达式,需要PCRE库。

Expand Down Expand Up @@ -101,6 +122,10 @@ nginx-http-flv-module包含了[nginx-rtmp-module](https://github.com/arut/nginx-

http://example.com[:port]/dir?[port=xxx&]app=myapp&stream=mystream

### 注意

如果使用[ffplay](http://www.ffmpeg.org/ffplay.html)命令行方式播放流,那么**必须**为上述的url加上引号,否则url中的参数会被丢弃(有些不太智能的shell会把"&"解释为"后台运行")。

参数`dir`用于匹配http配置块中的location块(更多详情见下文)。

**HTTP默认端口****80**, 如果使用了其他端口,必须指定`:port`
Expand Down Expand Up @@ -161,26 +186,41 @@ nginx-http-flv-module包含了[nginx-rtmp-module](https://github.com/arut/nginx-

http://example.com[:port]/dir/streamname.mpd

# 示例图片

## RTMP ([JW Player](https://www.jwplayer.com)) & HTTP-FLV ([VLC](http://www.videolan.org))

![RTMP & HTTP-FLV](samples/jwplayer_vlc.png)

## HTTP-FLV ([flv.js](https://github.com/Bilibili/flv.js))

![HTTP-FLV](samples/flv.js.png)

# nginx-http-flv-module的安装包

详情见[nginx-http-flv-module-packages](https://github.com/winshining/nginx-http-flv-module-packages)

# nginx.conf实例

## 注意

配置项`rtmp_auto_push``rtmp_auto_push_reconnect``rtmp_socket_dir`在Windows上不起作用,除了Windows 10 17063以及后续版本之外,因为多进程模式的`relay`需要Unix domain socket的支持,详情请参考[Unix domain socket on Windows 10](https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows)

最好将配置项`worker_processes`设置为1,因为`ngx_rtmp_stat_module`在多进程模式下每次只能获取一个进程的统计数据。如果统计数据不重要,那么可以将它设置为大于1的数字,最好与CPU的核心数保持一致
最好将配置项`worker_processes`设置为1,因为`ngx_rtmp_stat_module``ngx_rtmp_control_module`在多进程模式下有问题,另外,`vhost`功能在多进程模式下还不能完全正确运行,等待修复

worker_processes 4; #运行在Windows上时,设置为1,因为Windows不支持Unix domain socket
worker_processes 1; #运行在Windows上时,设置为1,因为Windows不支持Unix domain socket
#worker_processes auto; #1.3.8和1.2.5以及之后的版本

worker_cpu_affinity 0001 0010 0100 1000; #只能用于FreeBSD和Linux
#worker_cpu_affinity 0001 0010 0100 1000; #只能用于FreeBSD和Linux
#worker_cpu_affinity auto; #1.9.10以及之后的版本

error_log logs/error.log error;

#如果此模块被编译为动态模块并且要使用与RTMP相关的功
#能时,必须指定下面的配置项并且它必须位于events配置
#项之前,否则NGINX启动时不会加载此模块或者加载失败
#load_module modules/ngx_rtmp_module.so;

#load_module modules/ngx_http_flv_live_module.so;

events {
worker_connections 1024;
Expand Down Expand Up @@ -239,6 +279,14 @@ nginx-http-flv-module包含了[nginx-rtmp-module](https://github.com/arut/nginx-
root /var/www/rtmp; #指定stat.xsl的位置
}

#如果需要JSON风格的stat, 不用指定stat.xsl
#但是需要指定一个新的配置项rtmp_stat_format

#location /stat {
# rtmp_stat all;
# rtmp_stat_format json;
#}

location /control {
rtmp_control all; #rtmp控制模块的配置
}
Expand All @@ -250,9 +298,13 @@ nginx-http-flv-module包含了[nginx-rtmp-module](https://github.com/arut/nginx-
rtmp_socket_dir /tmp;

rtmp {
out_queue 4096;
out_cork 8;
max_streams 64;
out_queue 4096;
out_cork 8;
max_streams 128;
timeout 15s;

log_interval 5s; #log模块在access.log中记录日志的间隔时间,对调试非常有用
log_size 1m; #log模块用来记录日志的缓冲区大小

server {
listen 1935;
Expand Down Expand Up @@ -296,4 +348,3 @@ nginx-http-flv-module包含了[nginx-rtmp-module](https://github.com/arut/nginx-
}
}
}

93 changes: 72 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,35 @@

Media streaming server based on [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module).

[中文说明](https://github.com/winshining/nginx-http-flv-module/blob/master/README.CN.md).

Donate if you like this module. Many thanks to you!

<a href="https://www.buymeacoffee.com/winshining" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/white_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

### Appreciation

* Igor Sysoev, the creator of [NGINX](http://nginx.org).

* Roman Arutyunyan, who created [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module).

* Contributors, refer to [AUTHORS](https://github.com/winshining/nginx-http-flv-module/blob/master/AUTHORS) for details.

# Features

* All features [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) provides.

* Other features provided by nginx-http-flv-module vs [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module):

| Features | nginx-http-flv-module | nginx-rtmp-module | remarks |
| :---------------------: | :-------------------: | :---------------: | :----------------------------------------: |
| HTTP-FLV (subscribe) || x | HTTPS-FLV and chunked response supported |
| GOP cache || x | Only for H.264 video and AAC audio |
| VHOST || x | |
| omit `listen` directive || x | |
| Features | nginx-http-flv-module | nginx-rtmp-module | Remarks |
| :---------------------: | :-------------------: | :---------------: | :---------------------------------------------: |
| HTTP-FLV (subscribe) || x | HTTPS-FLV and chunked response supported |
| GOP cache || x | Only for H.264 video and AAC audio |
| VHOST || x | |
| Omit `listen` directive || See remarks | There MUST be at least one `listen` directive |
| Audio-only support || See remarks | Won't work if `wait_video` or `wait_key` is on |
| Timing log for access || x | |
| JSON style stat || x | |

# Systems supported

Expand All @@ -25,17 +42,21 @@ Media streaming server based on [nginx-rtmp-module](https://github.com/arut/ngin

* [VLC](http://www.videolan.org) (RTMP & HTTP-FLV)/[OBS](https://obsproject.com) (RTMP & HTTP-FLV)/[JW Player](https://www.jwplayer.com) (RTMP)/[flv.js](https://github.com/Bilibili/flv.js) (HTTP-FLV).

## Note

[flv.js](https://github.com/Bilibili/flv.js) can only run with browsers that support [Media Source Extensions](https://www.w3.org/TR/media-source).

# Prerequisites

* GNU make for activating compiler on Unix-like systems to compile software.

* GCC for compiling on Unix-like systems/MSVC for compiling on Windows.
* GCC for compilation on Unix-like systems or MSVC for compilation on Windows.

* GDB for debuging on Unix-like systems.
* GDB for debug on Unix-like systems.

* FFmpeg for publishing media streams.
* [FFmpeg](http://ffmpeg.org) or [OBS](https://obsproject.com) for publishing media streams.

* VLC player (recommended) for playing media streams.
* [VLC](http://www.videolan.org) (recommended) or [flv.js](https://github.com/Bilibili/flv.js) (recommended) for playing media streams.

* PCRE for NGINX if regular expressions needed.

Expand All @@ -51,7 +72,7 @@ nginx-http-flv-module has all features that [nginx-rtmp-module](https://github.c

## On Windows

Build steps please refer to [Building nginx on the Win32 platform with Visual C](http://nginx.org/en/docs/howto_build_on_win32.html), and don't forget to add `--add-module=/path/to/nginx-http-flv-module` in `Run configure script` step.
For details of build steps, please refer to [Building nginx on the Win32 platform with Visual C](http://nginx.org/en/docs/howto_build_on_win32.html), and don't forget to add `--add-module=/path/to/nginx-http-flv-module` in `Run configure script` step.

## On Unix-like systems

Expand Down Expand Up @@ -81,7 +102,7 @@ If the module is compiled as a dynamic module, the [NGINX](http://nginx.org) ver

# Usage

For details about usages of [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module), please refer to [README.md](https://github.com/arut/nginx-rtmp-module/blob/master/README.md).
For details of usages of [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module), please refer to [README.md](https://github.com/arut/nginx-rtmp-module/blob/master/README.md).

## Publish

Expand All @@ -101,6 +122,10 @@ The **default port for RTMP** is **1935**, if some other ports were used, `:port

http://example.com[:port]/dir?[port=xxx&]app=myapp&stream=mystream

### Note

If [ffplay](http://www.ffmpeg.org/ffplay.html) is used in command line to play the stream, the url above **MUST** be enclosed by quotation marks, or arguments in url will be discarded (some shells not so smart will interpret "&" as "run in background").

The `dir` is used to match location blocks in http block (see below for details).

The **default port for HTTP** is **80**, if some other ports were used, `:port` must be specified.
Expand Down Expand Up @@ -141,7 +166,7 @@ And `listen` directive specified in `rtmp` block is:
}
}

Then the url of play based on HTTP is:
Then the url of playback based on HTTP is:

http://example.com:8080/live?port=1985&app=myapp&stream=mystream

Expand All @@ -161,18 +186,32 @@ Since some players don't support HTTP chunked transmission, it's better to speci

http://example.com[:port]/dir/streamname.mpd

# Sample Pictures

## RTMP ([JW Player](https://www.jwplayer.com)) & HTTP-FLV ([VLC](http://www.videolan.org))

![RTMP & HTTP-FLV](samples/jwplayer_vlc.png)

## HTTP-FLV ([flv.js](https://github.com/Bilibili/flv.js))

![HTTP-FLV](samples/flv.js.png)

# Packages for nginx-http-flv-module

Please refer to [nginx-http-flv-module-packages](https://github.com/winshining/nginx-http-flv-module-packages).

# Example nginx.conf

## Note

The directives `rtmp_auto_push`, `rtmp_auto_push_reconnect` and `rtmp_socket_dir` will not function on Windows except on Windows 10 17063 and later versions, because `relay` in multiple processes mode needs help of Unix domain socket, please refer to [Unix domain socket on Windows 10](https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows) for details.

The directive `worker_processes` of value 1 is preferable to other values, because `ngx_rtmp_stat_module` can only get the statistics of one process at a time in multi-processes mode. If the statistics is unimportant, it can be set as number greater than 1, it is better to set it as the number of CPU cores.
The directive `worker_processes` of value 1 is preferable to other values, because there are something wrong with `ngx_rtmp_stat_module` and `ngx_rtmp_control_module` in multi-processes mode, in addtion, `vhost` feature is not perfect in multi-processes mode yet, wating to be fixed.

worker_processes 4; #should be 1 for Windows, for it doesn't support Unix domain socket
worker_processes 1; #should be 1 for Windows, for it doesn't support Unix domain socket
#worker_processes auto; #from versions 1.3.8 and 1.2.5

worker_cpu_affinity 0001 0010 0100 1000; #only available on FreeBSD and Linux
#worker_cpu_affinity 0001 0010 0100 1000; #only available on FreeBSD and Linux
#worker_cpu_affinity auto; #from version 1.9.10

error_log logs/error.log error;
Expand All @@ -181,7 +220,8 @@ The directive `worker_processes` of value 1 is preferable to other values, becau
#to RTMP are needed, the command below MUST be specified and MUST be
#located before events directive, otherwise the module won't be loaded
#or will be loaded unsuccessfully when NGINX is started
#load_module modules/ngx_rtmp_module.so;

#load_module modules/ngx_http_flv_live_module.so;

events {
worker_connections 1024;
Expand Down Expand Up @@ -240,6 +280,14 @@ The directive `worker_processes` of value 1 is preferable to other values, becau
root /var/www/rtmp; #specify in where stat.xsl located
}

#if JSON style stat needed, no need to specify
#stat.xsl but a new directive rtmp_stat_format

#location /stat {
# rtmp_stat all;
# rtmp_stat_format json;
#}

location /control {
rtmp_control all; #configuration of control module of rtmp
}
Expand All @@ -251,9 +299,13 @@ The directive `worker_processes` of value 1 is preferable to other values, becau
rtmp_socket_dir /tmp;

rtmp {
out_queue 4096;
out_cork 8;
max_streams 64;
out_queue 4096;
out_cork 8;
max_streams 128;
timeout 15s;

log_interval 5s; #interval used by log module to log in access.log, it is very useful for debug
log_size 1m; #buffer size used by log module to log in access.log

server {
listen 1935;
Expand Down Expand Up @@ -297,4 +349,3 @@ The directive `worker_processes` of value 1 is preferable to other values, becau
}
}
}

Loading

0 comments on commit e54c725

Please sign in to comment.