Nginx-rtmp-mudule rtmp is an excellent car-eye-http-flv-module is a streaming media server modified on Nginx-rtmp-mudule rtmp basis, in addition to support Flash player, Players that are now common are also supported. A perfect way to achieve the HTTP mode of FLV Live Function.
This article briefly introduces the main functions and use of the module:
Function
All features provided by Nginx-rtmp-module.
FLV live stream playback based on HTTP Protocol.
GOP cache, reducing playback latency (h. + video and AAC audio).
Transfer-Encoding: chunked
http reply with support Mode.
Configuration items can be omitted from the server block of the rtmp configuration listen
.
Support for Virtual Hosts.
Supported Systems
- Linux (recommended)/freebsd/macos/windows (limited).
Supported players
- VLC (rtmp & http-flv)/obs (rtmp & http-flv)/jw Player (rtmp)/flv.js (http-flv).
Depend on
On Unix-like systems, GNU make is required to invoke the compiler to compile the Software.
On Unix-like systems, the need for gcc/on Windows requires msvc for compiling software.
On a unix-like system, gdb is required for debugging software (optional).
FFmpeg, which is used to publish media streams.
VLC player (recommended) for playing media streaming.
If Nginx wants to support regular expressions, the Pcre library is Required.
If Nginx wants to support encrypted access, the OpenSSL library is Required.
If Nginx is to support compression, the Zlib library is Required.
Create on Windows
To compile the steps please refer to building nginx on the Win32 platform with Visual C, do not forget to Run configure script
add in step --add-module=/path/to/nginx-http-flv-module
.
On Unix-like Systems
Download Nginx and Nginx-http-flv-module.
Unzip them to a certain path.
Open the Nginx source code path and Execute:
Compile the module into Nginx
./configure --add-module=/path/to/nginx-http-flv-modulemakemake install
Compiling a module into a dynamic module
./configure --add-dynamic-module=/path/to/nginx-http-flv-modulemakemake install
Attention
If the module is compiled into a dynamic module, then the version number of Nginx must be greater than or equal to 1.9.11.
Release
ffmpeg -re -i example.mp4 -vcodec copy -acodec copy -f flv rtmp://example.com[:port]/appname/streamname
appname
Used to match the application Block in the RTMP configuration block (see below for more details).
streamname
can be arbitrarily specified.
The default port for Rtmp is 1935 and must be specified if you want to use a different port :port
.
Play (HTTP)
http://example.com[:port]/dir?[port=xxx&]app=myapp&stream=mystream
The parameters are dir
used to match the location block in the HTTP configuration block (see below for more details).
The HTTP default port is 80, which must be specified if other ports are used :port
.
The default port for RTMP is 1935, which must be specified if other ports are used port=xxx
.
Parameters are app
used to match the application block, but if the request app
appears in more than one server block, and the server blocks have the same address and port configuration, server_name
the Configure the item to differentiate which application block is requested, otherwise the first application block will be Matched.
Parameters stream
are used to match the streamname of the publishing Stream.
Example
Assume that the http
configuration items in the configuration block listen
are:
http { ... server { listen 8080; #不是默认的80端口 ... location /live { flv_live on; } }}
The rtmp
configuration items in the configuration block listen
are:
rtmp { ... server { listen 1985; #不是默认的1935端口 ... application myapp { live on; } }}
Then the http-based playback URL is:
http://example.com:8080/live?port=1985&app=myapp&stream=mystream
Attention
If you are using HTTP version 1.1 (http/1.1), The chunked_transfer_encoding
configuration entry is turned on by Default.
Because some players do not support HTTP block transfers, It is best to specify in the location specified in this case flv_live on;
chunked_transfer_encoding off
, otherwise playback will Fail.
nginx.conf Example Note
Configuration Items rtmp_auto_push
, rtmp_auto_push_reconnect
and rtmp_socket_dir
does not work on windows, except for Windows 10 17063 and later versions, because the multi-process mode relay
requires support for UNIX domain sockets, see UNIX domain socket on Windows 10.
Worker_processes 4; #运行在Windows上时, set to 1 because Windows does not support UNIX domain socketworker_cpu_affinity 0001 0010 0100 1000; #运行在Windows上时, omit this configuration item error_log logs/error.log error; when #如果此模块被编译为动态模块并且要使用与RTMP相关的功 # can, you must specify the following configuration item and it must precede the events configuration # entry , or the Nginx does not load this module or fails to load #load_module modules/ngx_rtmp_module.so;events {worker_connections 1024;} HTTP {include mime.types; Default_type application/octet-stream; Keepalive_timeout 65; Server {listen 80; location/{root/var/www; Index index.html index.htm; } error_page 502 503 504/50x.html; Location =/50x.html {root html; } location/live {flv_live on, #打开HTTP播放FLV直播流功能 chunked_transfer_encoding on; #支持 ' transfer- Encoding:chunked ' way back Add_header ' Access-control-allow-origin ' *; #添加额外的HTTP头 add_header ' access-control-allow-credentials ' true '; #添加额外的HTTP头} Location/stat { #push和pull状态的配置 Rtmp_stat all; Rtmp_stat_stylesheet stat.xsl; } location/stat.xsl {root/var/www/rtmp; #指定stat. xsl location}}}rtmp_auto_push on;rtmp_auto_push _reconnect 1s;rtmp_socket_dir/tmp;rtmp {out_queue 4096; Out_cork 8; Max_streams 64; Server {listen 1935; server_name www.test.*; #用于虚拟主机名后缀通配 application MyApp {live on; Gop_cache on; #打开GOP缓存, Decrease Playback delay}} server {listen 1935; server_name *.test.com; #用于虚拟主机名前缀通配 application MyApp {live on; Gop_cache on; #打开GOP缓存, Decrease Playback delay}} server {listen 1935; server_name www.test.com; #用于虚拟主机名完全匹配 application MyApp {live on; Gop_cache on; #打开GOP缓存, Decrease Playback delay}}}
Car-eye Open Source platform official Website: www.car-eye.cn; Car-eye Open Source Platform source download: Https://github.com/Car-eye-team about Car-eye problem consultation can add QQ group 590411159.
Car-eye-http-flv-module implements the FLV Live function of Nginx-rtmp-mudule http mode