


The content of this article is about how to understand the HTTP-FLV live broadcast module nginx-http-flv-module based on the nginx-rtmp-module module. It has certain reference value and friends in need can refer to it. I hope it helps you.
Currently, many individuals and manufacturers are preparing to commercialize this module. According to feedback from netizens, there are already live broadcast websites using this module abroad. The most famous manufacturer preparing for commercial use is Huawei. Netizens and manufacturers have reported many bugs. After repairs, the function has become more and more stable. I would like to express my gratitude.
2018-06-04: A CDN manufacturer officially launched nginx-http-flv-module, using RTMP mode, turning on gop_cache configuration (turning off the interleave configuration, there will be lag or no sound when turning it on) , currently we don’t know how to fix it), their customers include Inke and Weihou.
2018-06-28: An online video manufacturer officially launched nginx-http-flv-module, using HTTP-FLV method, without enabling gop_cache configuration. It has not been fully activated yet, waiting. Observe stability.
2018-07-28: In response to the needs of some netizens, rpm installation packages for RHEL6 (CentOS 6) and RHEL7 (CentOS 7) have been provided, see nginx-http-flv-module -packages.
Function comparison between nginx-http-flv-module and nginx-rtmp-module:
Function | nginx-http-flv-module | nginx-rtmp-module | Remark |
HTTP-FLV | √ | × | nginx-http-flv-module supports HTTPS-FLV |
GOP Cache | √ | × | |
vhost | √ | × | |
Omit listen configuration | √ | x |
|
JSON style stat | √ | x | |
RTMP 302 | Beta | × | nginx-http-flv-module as server or client |
2018-03-09 Update:
In recent times, the stability of the module has been mainly tested on different platforms. Currently, no problem has been found when playing this part. Due to conditions, it has not been tested except for the FreeBSD platform. Windows 7. Both Debian 7.x and macOS Sierra have been tested. Since Nginx officially does not support Windows very well and does not use the most powerful IOCP interface on the Windows platform (select is used), the operating efficiency on the Windows platform is not very high. , manifested in the long waiting time for push streaming, 3s, and the first screen time is very long, 4s. The number of clients is limited due to the selection itself, and the default is 1024. The one with the shortest push streaming waiting time and first screen time is macOS Sierra. When tested on this machine, it basically pushed and opened within seconds. I paid special attention last night. When compiling under macOS Sierra, both SO_REUSEPORT and TCP_FASTOPEN are supported. The former allows each sub-process of Nginx to listen and has a dedicated accept queue, which solves the thundering herd effect; the latter The actual data is already carried when SYN is initiated, instead of transmitting the actual data after the handshake is completed. Pushing and opening in seconds may be related to these two options. However, macOS Sierra does not support binding a process to a CPU, so there may be overhead in process context switching, and the efficiency may not be as good as Linux when the system load is heavy. Since macOS Sierra is a company computer, no stress test was performed. My laptop is installed with Debian 7.x. Because the kernel version is lower, the two options supported on macOS Sierra are not supported. During the test, the push waiting time and the first screen time were between Windows 7 and macOS Sierra. When tested on the server (system CentOS 6.4, supporting SO_REUSEPORT but not TCP_FASTOPEN), it was similar to that on macOS Sierra, but considering the server's CPU The performance is much more powerful, so macOS Sierra performs best when the load is not high. Since macOS Sierra is updated from Mac OS X, and the bottom layer of Mac OS X was originally developed based on FreeBSD, it is speculated that the performance on FreeBSD should also be good.
In addition, I recently tried to add the function of converting RTMP 302 redirection to HTTP 302 redirection. Since many players do not support RTMP 302 redirection, the function of supporting HTTP 302 redirection is basically standard. Tested VLC is supported. At present, the function is basically completed, but the troublesome part is that when using the sending interface of the HTTP framework, the linked list will form a loop after playing for a long time, so the progress cannot be continued and it has not been updated to github. The following is the main rtmp configuration snippet of nginx and the HTTP 302 redirection screenshot during VLC playback: the push stream is pushed on the application named hls (FFmpeg does not support RTMP 302 redirection, so it can only be pushed to hls).
application myapp {
rewrite '^/myapp/(.*)' '/hsl/$1';
}
1.HTTP 302 Brief diagram of redirection packet capture
2. HTTP 302 redirection packet capture details diagram
nginx-http-flv-module turned on the gop_cache configuration item, flv.js was different from other mainstream players (such as vlc) In comparison, the first screen time is the fastest with almost no delay. The pull source used is the live broadcast source of Hong Kong Satellite TV: rtmp://live.hkstv.hk.lxdns.com/live/hks.
Updated on 2018-03-27:
I just changed some code and there was a bug, which is really annoying. Recently, in response to some netizens' requests for the function of adding customized HTTP headers, the sending function was modified. I tried again to introduce the filter interface of Nginx's HTTP framework, but it still failed, so I simply and crudely picked out the last filter module and header_filter module. Removed a lot of unused code. The official stable version of Nginx, nginx-1.12.2, is used for compilation on github. As a result, some netizens reported today that the compilation failed. After checking, it happened that these macros that could not be found were added to nginx-1.11.10, which I have been using since I modified nginx-rtmp-module, and the version used by netizens was lower. It just can't be compiled, it has been fixed.
2018-03-29 Update:
A few days ago, some netizens reported that when using nginx-1.13.1 and above versions to compile with nginx-http-flv-module, use flv. js will fail to play the pull stream. See the 2018-03-25 update. The problem has been fixed. There is also a problem of pushing the stream first and then using flv.js to play it. It is a bug that can be easily fixed. The problem has been fixed. Latest version of Nginx and a slightly older version (nginx-1.11.10) have been tested.
2018-04-05 record:
This time is not an update:) Yesterday, some netizens reported that when using flv.js to play push streams, they could not be played. I thought nginx-http-flv -The module has a problem again. I tested it myself and compiled it with the latest nginx-1.13.10. There is no problem in playing push and pull streams. I also compiled it with the official stable version nginx-1.12.2 and there is still no problem. , when I was preparing to see what went wrong in the evening, a netizen reported that the browser limited the number of flv.js. He was using Chrome. According to the test, a single browser could only open 6 flv.js. I used Firefox to test it at noon today. After a while, it was the same problem. The seventh flv.js could not be played. Then I opened VLC to play it, and there was no problem. From this, I can confirm that it is not a problem with nginx-http-flv-module. However, this is very important information. There is a limit to the number of browsers that support flv.js playback. Chrome and Firefox both have a limit of 6. Other browsers have not been tested.
Updated on 2018-04-06:
The previous statistical data has not included the accepted number and output of http-flv live broadcast, and it has been added now. Now the support for flv.js has been stable. The following is a screenshot of using flv.js to play:
A commercial manufacturer reported that when the video source is pure video, no matter what playback method is used There is no problem with the playback connection, but the video data has not been received. After debugging, it was found that there was a bug in the logic of judging pure audio, which caused nginx-http-flv-module to loop infinitely in the interface for sending audio and video data. Now it is repair.
Updated on 2018-04-14:
Some netizens reported yesterday that when the gop_cache option is turned on, push streaming will cause memory leaks. It has been found that the gop cache module allocation is not released when the push flow is turned off. Caused by memory, fixed. In addition, according to feedback from netizens, there is a problem with the on_connect and on_play commands in multi-process mode. Please do not use these two commands in multi-process mode for the time being until they are fixed.
Updated on 2018-04-15:
A commercial manufacturer reported that the memory would continue to grow during the random flash test, and it was suspected that there was a memory leak. During debugging at night, it was confirmed that there was indeed a memory leak, and it was due to This was caused by not releasing the memory pool in the ngx_http_request_t structure, which has been fixed.
Updated on 2018-04-21:
Some netizens reported that in multi-process mode, on_play is used for authentication operations, but when pushing, the local relay (sub-process that accepts the push) Pushing the stream to other child processes) will also perform on_play authentication, which is unreasonable (but not actually a bug) because authentication has been performed before. Now the on_play operation of the local relay has been removed. nginx-http-flv-module does not care what on_play is used for, but considering that the local relay should no longer perform on_play operations, the modified code is relatively simple and recovery is easy. , so modify it like this temporarily. In addition, the stress test crash problem reported by netizen @qqzzzx has been partially fixed. The remaining problem is that there will be a memory leak after the stress test group is disconnected. After the fix, it will be updated to github.
2018-04-25 update:
The stress test crash problem has been fixed, and the possible problem of excessive CPU usage has also been solved. The stress test has been for more than 1 hour (srs -Bench's own test video, 500 HTTP-FLV and 200 RTMP), no problems have been found yet, welcome to report bugs.
Updated on 2018-05-12:
Some netizens reported that turning on the gop_cache option would cause stress testing to consume a lot of memory in some cases. It is not sure if there is a memory leak. The stress test cannot be reproduced many times. Netizens pointed out that it is easier to reproduce the stress test tool and the server if they are not on the same host. It is indeed easier to reproduce the stress test in this way. However, if the memory consumption is relatively large, stop the stress test, and then repeat the stress test and the number of concurrency remains unchanged. The memory will not increase, which proves that it is not a memory leak problem. After repeatedly checking the source code, I guessed that when sending the GOP, the GOP data was put into the sending ring array at once. Since Nginx is asynchronous and non-blocking, Nginx may not actually send the data from the ring array to network (for example, when the network bandwidth between the server and the client is insufficient), the allocated memory cannot be recycled immediately, and after the GOP is actually sent, the allocated memory is no longer released (in the memory pool, and with It has nothing to do with the connection, only the configuration structure). Subsequent data transmission is not like the GOP data that is sent all at once, so the recycled memory cannot be fully used and a large part is idle. Now modify the gop cache module to use its own independent memory pool, and release this memory pool after the GOP is sent.
2018-05-14 update:
Fixed a memory leak bug introduced in the 2018-05-12 update. The code was incomprehensible for a long time, and then problems occurred as soon as it was changed. Condition. Fix the bug that the high version of gcc compilation project fails (I checked online, gcc-7.x.x will check whether the switch case has fall through when adding certain compilation options), but I don’t have a very high version of gcc at hand. , so there may still be some undiscovered compilation errors, and we are currently waiting for replies from netizens.
Updated on 2018-05-16:
During the day, I compiled and installed gcc-7.2.0 and found all the fall through compilation warnings (which are regarded as errors in Nginx compilation options). Bug fixed.
2018-05-18 record:
This is not an update. In the 2018-05-12 update, I guess it will be special to turn on the gop_cache option during the stress test (the tool used is srs-bench). The reason for consuming memory. After checking the log tonight, I found that the previous guess was not the main reason. It can be seen from the log that Nginx always receives 128 bytes of data. If the chunk_size configuration item is not specified in the configuration, the default is 4096 bytes. That is to say, after the server sends the Set Chunk Size protocol control message, the client The client did not respond to the Set Chunk Size protocol control message, so the server has continued to use the previous 128 bytes. In the worst case, it will cause nginx-http-flv-module to allocate memory to package the data after receiving the data. Using (4096 RTMP header maximum size) so many bytes of space to pack 128 bytes of data wastes 32 times more data. Use ffmpeg for comparison testing. ffmpeg will respond to the Set Chunk Size protocol control message, so it will not cause memory waste. An issue has been submitted to the author of SRS (Simple-RTMP-Server). I will update nginx-http-flv-module's handling of this exception when I have time.
Updated on 2018-05-20:
The problem of particularly memory consumption in some cases has been fixed. If the usage is still very large, it may be due to the secondary reason mentioned above. Caused.
2018-06-14 update:
Fixed a problem reported by netizens. The value of the ngx_stat_active parameter was incorrect after running for a period of time. It was found that it was caused by repeated subtraction operations and has been fixed. , does not affect normal function use.
Updated on 2018-06-19:
Synchronized the bug fixes in several pull requests of nginx-rtmp-module. Basically, they are some obvious bugs. No major modifications. Sync over. In addition, the function of directly pushing fmp4 has been added to nginx-http-flv-module. Tonight, it has been implemented to directly push pure video fmp4 to browsers that support MSE (Media Source Extensions, currently not supported by Safari on iOS). Play in, and the audio will be added later.
2018-06-25 update:
The basic function of pushing fmp4 has been basically completed. Some netizens pushed a PR that supports stat in JSON format. It has been merged. I tried it and found it very good. A small bug was also fixed.
2018-06-29 update:
Modify the original rtmp information in the stat to http-flv. In view of the fact that two manufacturers have officially commercialized RTMP (turn on gop_cache) and HTTP-FLV. (without gop_cache enabled), milestone version 1.2.4 was released.
2018-07-09 Update:
Fixed 3 small bugs: when turning on the DASH function, it may cause an infinite loop because the data read from the file is 0; repair the xml method The problem that the version number of nginx-http-flv-module cannot be displayed in the stat (PR from a netizen); fix the bug of returning 405 (Method Not Allowed) when the HEAD request does not configure flv_live locations
The above is the detailed content of How to understand the HTTP-FLV live broadcast module nginx-http-flv-module implemented based on nginx-rtmp-module module. For more information, please follow other related articles on the PHP Chinese website!

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
