nginx-http-flv-module
A media streaming server based on nginx-rtmp-module.
中文说明.
Donate if you like this module. Many thanks to you!
Credits
Igor Sysoev, the creator of NGINX.
Roman Arutyunyan, who created nginx-rtmp-module.
Contributors, refer to AUTHORS for details.
Features
All features nginx-rtmp-module provides.
Other features provided by nginx-http-flv-module vs nginx-rtmp-module:
| Features | nginx-http-flv-module | nginx-rtmp-module | Remarks |
|---|---|---|---|
| HTTP-FLV (HTTP/1.x for play) | √ | x | HTTPS-FLV and chunked response supported |
| GOP cache | √ | x | |
| Virtual Host | √ | x | |
Omit listen directive |
√ | See remarks | There MUST be at least one listen directive |
| Audio-only support for RTMP/HTTP-FLV | √ | See remarks | Won't work if wait_video or wait_key is on |
| Single-track support for HLS | √ | x | |
reuseport support |
√ | x | |
| Timer for access log | √ | x | |
| JSON style statistics | √ | x | |
| Statistics for recordings | √ | x | |
| Independent of endianness | √ | See remarks | Partially supported in branch big-endian |
Compatibility
The NGINX 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
Note
Flash player will be no longer supported officially by Adobe after December 31, 2020, refer to Adobe Flash Player EOL General Information Page for details. Plugins that use flash player won't work after the major browsers subsequently remove flash player.
flv.js can only run with browsers that support Media Source Extensions.
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.
VLC (recommended) or flv.js (recommended) for playing media streams.
PCRE for NGINX if regular expressions needed.
OpenSSL for NGINX if encrypted access needed.
zlib for NGINX if compression needed.
Build
Note
nginx-http-flv-module has all features that nginx-rtmp-module provides, so DON'T compile nginx-http-flv-module along with nginx-rtmp-module.
On Windows
For details about build steps, please refer to Building nginx on the Win32 platform with Visual C, 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 and nginx-http-flv-module.
Uncompress them.
cd to NGINX source directory & run this:
Compile the module into NGINX
./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 version MUST be equal to or greater than 1.9.11.
Usage
For details of usages of nginx-rtmp-module, please refer to 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 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 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 is used to play the stream, make sure that the published stream is encoded properly, for 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;
}
}
}
And listen directive specified in rtmp block is:
rtmp {
...
server {
listen 1985; #not default port 1935
...
application myapp {
live on;
}
}
}
And the name of published stream is mystream, then the url of playback based on HTTP is:
http://example.com:8080/live?port=1985&app=myapp&stream=mystream
Note
Since some players don't support HTTP chunked transmission, it's better to specify chunked_transfer_encoding off; in location where flv_live on; is specified in this case, or play will fail.
via RTMP
rtmp://example.com[:port]/appname/streamname
via HLS
http://example.com[:port]/dir/streamname.m3u8
via DASH
http://exam
