# nginx-http-flv-module
[![Build Status](https://app.travis-ci.com/winshining/nginx-http-flv-module.svg?branch=master)](https://app.travis-ci.com/winshining/nginx-http-flv-module)
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>
### Credits
* 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 (for play) | √ | x | HTTPS-FLV and chunked response supported |
| GOP cache | √ | x | |
| 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 |
| `reuseport` support | √ | x | |
| Timer for access log | √ | x | |
| JSON style stat | √ | x | |
| Stat for recordings | √ | x | |
## Compatibility
The [NGINX](http://nginx.org) version **SHOULD** be equal to or greater than 1.2.6, the compatibility with other versions is unknown.
## Systems supported
* Linux (recommended) / FreeBSD / MacOS / Windows (limited).
## Players supported
* [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
* [Flash player](https://www.adobe.com/products/flashplayer.html) will be no longer supported officially by Adobe after December 31, 2020, refer to [Adobe Flash Player EOL General Information Page](https://www.adobe.com/products/flashplayer/end-of-life.html) for details. Plugins that use flash player won't work after the major browsers subsequently remove flash player.
* [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 compilation on Unix-like systems or MSVC for compilation on Windows.
* GDB for debug on Unix-like systems.
* [FFmpeg](http://ffmpeg.org) or [OBS](https://obsproject.com) for publishing media streams.
* [VLC](http://www.videolan.org) (recommended) or [flv.js](https://github.com/Bilibili/flv.js) (recommended) for playing media streams.
* [PCRE](http://www.pcre.org) for NGINX if regular expressions needed.
* [OpenSSL](https://www.openssl.org) for NGINX if encrypted access needed.
* [zlib](http://www.zlib.net) for NGINX if compression needed.
## Build
### Note
nginx-http-flv-module has all features that [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) provides, so **DON'T** compile nginx-http-flv-module along with [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module).
### On Windows
For details about 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.
#### Note
If some compilers which do not support x64 perfectly, VS2010 for example, are used to compile the module, please make sure that the default settings are used (target machine type x86).
### On Unix-like systems
Download [NGINX](http://nginx.org) and nginx-http-flv-module.
Uncompress them.
cd to NGINX source directory & run this:
#### Compile the module into [NGINX](http://nginx.org)
./configure --add-module=/path/to/nginx-http-flv-module
make
make install
or
#### Compile the module as a dynamic module
./configure --add-dynamic-module=/path/to/nginx-http-flv-module
make
make install
#### Note
If the module is compiled as a dynamic module, the [NGINX](http://nginx.org) version **MUST** be equal to or greater than 1.9.11.
## Usage
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
For simplicity, transcoding is not used (so **-c copy** is used):
ffmpeg -re -i MEDIA_FILE_NAME -c copy -f flv rtmp://example.com[:port]/appname/streamname
#### Note
Some legacy versions of [FFmpeg](http://ffmpeg.org) don't support the option `-c copy`, the options `-vcodec copy -acodec copy` can be used instead.
The `appname` is used to match an application block in rtmp block (see below for details).
The `streamname` can be specified at will but can **NOT** be omitted.
The **default port for RTMP** is **1935**, if some other ports were used, `:port` must be specified.
### Play
#### via HTTP-FLV
http://example.com[:port]/dir?[port=xxx&]app=appname&stream=streamname
#### 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").
* If [flv.js](https://github.com/Bilibili/flv.js) is used to play the stream, make sure that the published stream is encoded properly, for [flv.js](https://github.com/Bilibili/flv.js) supports **ONLY H.264 encoded video and AAC/MP3 encoded audio**.
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.
The **default port for RTMP** is **1935**, if some other ports were used, `port=xxx` must be specified.
The value of `app` (appname) is used to match an application block, but if the requested `app` appears in several server blocks and those blocks have the same address and port configuration, host name matches `server_name` directive will be additionally used to identify the requested application block, otherwise the first one is matched.
The value of `stream` (streamname) is used to match the name of published stream.
#### Example
Assume that `listen` directive specified in `http` block is:
http {
...
server {
listen 8080; #not default port 80
...
location /live {
flv_live on;
评论0