开放代码社区 › nginx-http-flv-module

nginx-http-flv-module

开发工具C

nginx-http-flv-module 一款基于 nginx-rtmp-module 的流媒体服务器。 English README。 如果您喜欢这个模块,可以通过赞赏来支持我的工作,非常感谢! Igor Sysoev,NGINX 的作者。 Roman Arutyunyan,nginx-rtmp-module 的作者。 贡献者,详情见 AUTHORS。 nginx-rtmp-module 提供的所有功能。

AI/机器学习Web后端前端工具部署/运维
作者:用户6868语言:C更新:2026-10-27
仓库地址
https://gitee.com/winshining/nginx-http-flv-module.git

前往原仓库

README

# nginx-http-flv-module

![nginx-http-flv-module workflow](https://github.com/winshining/nginx-http-flv-module/actions/workflows/nginx-http-flv-module.yml/badge.svg?branch=master)

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

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

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

![reward_qrcode_winshining](https://web-code-img.oss-cn-shanghai.aliyuncs.com/readme/eb6d947fe0253f9b81b4ffca.png)

### 感谢

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

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

* 贡献者,详情见 [AUTHORS](https://gitee.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 (HTTP/1.x 播放) |           √           |         x         |      支持 HTTPS-FLV 和 chunked 回复      |
|         GOP 缓存         |           √           |         x         |                                          |
|         虚拟主机         |           √           |         x         |                                          |
|   省略 `listen` 配置项   |           √           |       见备注      |        配置中必须有一个 `listen`         |
| RTMP/HTTP-FLV 纯音频支持 |           √           |       见备注      |`wait_video` 或 `wait_key` 开启后无法工作 |
|       HLS 单轨支持       |           √           |         x         |                                          |
|     `reuseport` 支持     |           √           |         x         |                                          |
|     定时打印访问记录     |           √           |         x         |                                          |
|   JSON 风格的数据信息    |           √           |         x         |                                          |
|      录制的数据信息      |           √           |         x         |                                          |
|        大小端无关        |           √           |       见备注      |        `big-endian` 分支部分支持         |

## 兼容性

[NGINX](http://nginx.org) 的版本**应该**大于或者等于 1.2.6,与其他版本的兼容性未知。

## 支持的系统

* Linux(推荐)/ FreeBSD / MacOS / Windows(受限)。

## 支持的播放器

* [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).

### 注意

* Adobe 将在 2020 年 12 月 31 日之后停止对 [flash 播放器](https://www.adobe.com/products/flashplayer.html) 的官方支持,详情见 [Adobe Flash Player EOL General Information Page](https://www.adobe.com/products/flashplayer/end-of-life.html)。主流浏览器随后将移除 flash 播放器,使用 flash 播放器的插件将不再可用。

* [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 系统上,需要 GDB,用于调试软件(可选)。

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

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

* 如果 NGINX 要支持正则表达式,需要 [PCRE库](http://www.pcre.org)。

* 如果 NGINX 要支持加密访问,需要 [OpenSSL库](https://www.openssl.org)。

* 如果 NGINX 要支持压缩,需要 [zlib库](http://www.zlib.net)。

## 创建

### 注意

nginx-http-flv-module 包含了 [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) 所有的功能,所以**不要**将 nginx-http-flv-module 和 [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) 一起编译。

### 在 Windows 上

编译步骤请参考 [Building nginx on the Win32 platform with Visual C](http://nginx.org/en/docs/howto_build_on_win32.html),不要忘了在 `Run configure script` 步骤中添加 `--add-module=/path/to/nginx-http-flv-module`。

#### 注意

如果使用没有完整支持 x64 的编译器来编译此模块,例如 VS2010,请务必使用默认设置(目标机器类型 x86)。

### 在类 Unix 系统上

下载 [NGINX](http://nginx.org) 和 nginx-http-flv-module。

将它们解压到某一路径。

打开 NGINX 的源代码路径并执行:

#### 将模块编译进 [NGINX](http://nginx.org)

    ./configure --add-module=/path/to/nginx-http-flv-module
    make
    make install

或者

#### 将模块编译为动态模块

    ./configure --add-dynamic-module=/path/to/nginx-http-flv-module
    make
    make install

#### 注意

如果将模块编译为动态模块,那么 [NGINX](http://nginx.org) 的版本号**必须**大于或者等于 1.9.11。

## 使用方法

关于 [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) 用法的详情,请参考 [README.md](https://github.com/arut/nginx-rtmp-module/blob/master/README.md)。

### 发布

为了简单起见,不用转码:

    ffmpeg -re -i MEDIA_FILE_NAME -c copy -f flv rtmp://example.com[:port]/appname/streamname

#### 注意

一些旧版本的 [FFmpeg](http://ffmpeg.org) 不支持选项 `-c copy`,可以使用选项 `-vcodec copy -acodec copy` 替代。

`appname` 用于匹配 rtmp 配置块中的 application 块(更多详情见下文)。

`streamname` 可以随意指定,但是**不能**省略。

**RTMP 默认端口**为 **1935**,如果要使用其他端口,必须指定 `:port`。

### 播放

#### HTTP-FLV 方式

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

#### 注意

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

* 如果使用 [flv.js](https://github.com/Bilibili/flv.js) 播放流,那么请保证发布的流被正确编码,因为 [flv.js](https://github.com/Bilibili/flv.js) **只支持 H.264 编码的视频和 AAC/MP3 编码的音频**。

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

**HTTP 默认端口**为 **80**, 如果使用了其他端口,必须指定 `:port`。

**RTMP 默认端口**为 **1935**,如果使用了其他端口,必须指定 `port=xxx`。

参数 `app` 的值(appname)用来匹配 application 块,但是如果请求的 `app` 出现在多个 server 块中,并且这些 server 块有相同的地址和端口配置,那么还需要用匹配主机名的 `server_name` 配置项来区分请求的是哪个 application 块,否则,将匹配第一个 application 块。

参数 `stream` 的值(streamname)用来匹配发布的流的名称。

#### 例子

假设在 `http` 配置块中的 `listen` 配置项是:

    http {
        ...
        server {
            listen 8080; #不是默认的 80 端口
            ...

            location /live {
                flv_live on;
            }
        }
    }

在 `rtmp` 配置块中的 `listen` 配置项是:

    rtm