{"id":15020827,"url":"https://github.com/winshining/nginx-http-flv-module","last_synced_at":"2025-05-14T00:06:54.436Z","repository":{"id":37359588,"uuid":"95348937","full_name":"winshining/nginx-http-flv-module","owner":"winshining","description":"A media streaming server based on nginx-rtmp-module. In addtion to the features nginx-rtmp-module provides, HTTP-FLV, GOP cache, VHosts (one IP for multi domain names) and JSON style statistics are supported now.","archived":false,"fork":false,"pushed_at":"2025-02-26T04:09:25.000Z","size":3899,"stargazers_count":2842,"open_issues_count":21,"forks_count":580,"subscribers_count":110,"default_branch":"master","last_synced_at":"2025-04-10T13:11:01.532Z","etag":null,"topics":["aac","chunked-transmission","dynamic-module","flvjs","gop-cache","h264","http-flv","json-statistics","live","live-streaming","media-server","nginx","nginx-http-flv","nginx-rtmp","rtmp","vhost","virtual-hosts"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/winshining.png","metadata":{"files":{"readme":"README.CN.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://www.paypal.me/ShingWong"]}},"created_at":"2017-06-25T08:58:29.000Z","updated_at":"2025-04-10T07:47:10.000Z","dependencies_parsed_at":"2023-01-21T04:19:53.950Z","dependency_job_id":"613e834b-f150-4c18-a6d6-d141c16519ed","html_url":"https://github.com/winshining/nginx-http-flv-module","commit_stats":{"total_commits":424,"total_committers":14,"mean_commits":"30.285714285714285","dds":"0.19339622641509435","last_synced_commit":"cdb396ae0864e055292ac1b821c5b5c0dd8fe053"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winshining%2Fnginx-http-flv-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winshining%2Fnginx-http-flv-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winshining%2Fnginx-http-flv-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winshining%2Fnginx-http-flv-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winshining","download_url":"https://codeload.github.com/winshining/nginx-http-flv-module/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043580,"owners_count":22004973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aac","chunked-transmission","dynamic-module","flvjs","gop-cache","h264","http-flv","json-statistics","live","live-streaming","media-server","nginx","nginx-http-flv","nginx-rtmp","rtmp","vhost","virtual-hosts"],"created_at":"2024-09-24T19:55:43.530Z","updated_at":"2025-05-14T00:06:54.415Z","avatar_url":"https://github.com/winshining.png","language":"C","funding_links":["https://www.paypal.me/ShingWong"],"categories":["Third Party Modules"],"sub_categories":["C Modules"],"readme":"# nginx-http-flv-module\n\n![nginx-http-flv-module workflow](https://github.com/winshining/nginx-http-flv-module/actions/workflows/nginx-http-flv-module.yml/badge.svg?branch=master)\n\n一款基于 [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) 的流媒体服务器。\n\n[English README](https://github.com/winshining/nginx-http-flv-module/blob/master/README.md)。\n\n如果您喜欢这个模块，可以通过赞赏来支持我的工作，非常感谢！\n\n![reward_qrcode_winshining](https://gitee.com/winshining/nginx-http-flv-module/raw/master/qrcode/reward_qrcode_winshining.png)\n\n### 感谢\n\n* Igor Sysoev，[NGINX](http://nginx.org) 的作者。\n\n* Roman Arutyunyan，[nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) 的作者。\n\n* 贡献者，详情见 [AUTHORS](https://github.com/winshining/nginx-http-flv-module/blob/master/AUTHORS)。\n\n## 功能\n\n* [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) 提供的所有功能。\n\n* nginx-http-flv-module 的其他功能与 [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) 的对比：\n\n|           功能           | nginx-http-flv-module | nginx-rtmp-module |                  备注                    |\n| :----------------------: | :-------------------: | :---------------: | :--------------------------------------: |\n|     HTTP-FLV (播放)      |           √           |         x         |     支持 HTTPS-FLV 和 chunked 回复       |\n|         GOP 缓存         |           √           |         x         |                                          |\n|         虚拟主机         |           √           |         x         |                                          |\n|   省略 `listen` 配置项   |           √           |       见备注      |        配置中必须有一个 `listen`         |\n| RTMP/HTTP-FLV 纯音频支持 |           √           |       见备注      |`wait_video` 或 `wait_key` 开启后无法工作 |\n|       HLS 单轨支持       |           √           |         x         |                                          |\n|     `reuseport` 支持     |           √           |         x         |                                          |\n|     定时打印访问记录     |           √           |         x         |                                          |\n|   JSON 风格的数据信息    |           √           |         x         |                                          |\n|      录制的数据信息      |           √           |         x         |                                          |\n|        大小端无关        |           √           |       见备注      |        `big-endian` 分支部分支持         |\n\n## 兼容性\n\n[NGINX](http://nginx.org) 的版本**应该**大于或者等于 1.2.6，与其他版本的兼容性未知。\n\n## 支持的系统\n\n* Linux（推荐）/ FreeBSD / MacOS / Windows（受限）。\n\n## 支持的播放器\n\n* [VLC](http://www.videolan.org) (RTMP \u0026 HTTP-FLV) / [OBS](https://obsproject.com) (RTMP \u0026 HTTP-FLV) / [JW Player](https://www.jwplayer.com) (RTMP) / [flv.js](https://github.com/Bilibili/flv.js) (HTTP-FLV).\n\n### 注意\n\n* 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 播放器的插件将不再可用。\n\n* [flv.js](https://github.com/Bilibili/flv.js) 只能运行在支持 [Media Source Extensions](https://www.w3.org/TR/media-source) 的浏览器上。\n\n## 依赖\n\n* 在类 Unix 系统上，需要 GNU make，用于调用编译器来编译软件。\n\n* 在类 Unix 系统上，需要 GCC。或者在 Windows 上，需要 MSVC，用于编译软件。\n\n* 在类 Unix 系统上，需要 GDB，用于调试软件（可选）。\n\n* [FFmpeg](http://ffmpeg.org) 或者 [OBS](https://obsproject.com)，用于发布媒体流。\n\n* [VLC](http://www.videolan.org)（推荐）或者 [flv.js](https://github.com/Bilibili/flv.js)（推荐），用于播放媒体流。\n\n* 如果 NGINX 要支持正则表达式，需要 [PCRE库](http://www.pcre.org)。\n\n* 如果 NGINX 要支持加密访问，需要 [OpenSSL库](https://www.openssl.org)。\n\n* 如果 NGINX 要支持压缩，需要 [zlib库](http://www.zlib.net)。\n\n## 创建\n\n### 注意\n\nnginx-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) 一起编译。\n\n### 在 Windows 上\n\n编译步骤请参考 [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`。\n\n#### 注意\n\n如果使用没有完整支持 x64 的编译器来编译此模块，例如 VS2010，请务必使用默认设置（目标机器类型 x86）。\n\n### 在类 Unix 系统上\n\n下载 [NGINX](http://nginx.org) 和 nginx-http-flv-module。\n\n将它们解压到某一路径。\n\n打开 NGINX 的源代码路径并执行：\n\n#### 将模块编译进 [NGINX](http://nginx.org)\n\n    ./configure --add-module=/path/to/nginx-http-flv-module\n    make\n    make install\n\n或者\n\n#### 将模块编译为动态模块\n\n    ./configure --add-dynamic-module=/path/to/nginx-http-flv-module\n    make\n    make install\n\n#### 注意\n\n如果将模块编译为动态模块，那么 [NGINX](http://nginx.org) 的版本号**必须**大于或者等于 1.9.11。\n\n## 使用方法\n\n关于 [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) 用法的详情，请参考 [README.md](https://github.com/arut/nginx-rtmp-module/blob/master/README.md)。\n\n### 发布\n\n为了简单起见，不用转码：\n\n    ffmpeg -re -i MEDIA_FILE_NAME -c copy -f flv rtmp://example.com[:port]/appname/streamname\n\n#### 注意\n\n一些旧版本的 [FFmpeg](http://ffmpeg.org) 不支持选项 `-c copy`，可以使用选项 `-vcodec copy -acodec copy` 替代。\n\n`appname` 用于匹配 rtmp 配置块中的 application 块（更多详情见下文）。\n\n`streamname` 可以随意指定，但是**不能**省略。\n\n**RTMP 默认端口**为 **1935**，如果要使用其他端口，必须指定 `:port`。\n\n### 播放\n\n#### HTTP-FLV 方式\n\n    http://example.com[:port]/dir?[port=xxx\u0026]app=appname\u0026stream=streamname\n\n#### 注意\n\n* 如果使用 [ffplay](http://www.ffmpeg.org/ffplay.html) 命令行方式播放流，那么**必须**为上述的 url 加上引号，否则 url 中的参数会被丢弃（有些不太智能的 shell 会把 \"\u0026\" 解释为\"后台运行\"）。\n\n* 如果使用 [flv.js](https://github.com/Bilibili/flv.js) 播放流，那么请保证发布的流被正确编码，因为 [flv.js](https://github.com/Bilibili/flv.js) **只支持 H.264 编码的视频和 AAC/MP3 编码的音频**。\n\n参数 `dir` 用于匹配 http 配置块中的 location 块（更多详情见下文）。\n\n**HTTP 默认端口**为 **80**, 如果使用了其他端口，必须指定 `:port`。\n\n**RTMP 默认端口**为 **1935**，如果使用了其他端口，必须指定 `port=xxx`。\n\n参数 `app` 的值（appname）用来匹配 application 块，但是如果请求的 `app` 出现在多个 server 块中，并且这些 server 块有相同的地址和端口配置，那么还需要用匹配主机名的 `server_name` 配置项来区分请求的是哪个 application 块，否则，将匹配第一个 application 块。\n\n参数 `stream` 的值（streamname）用来匹配发布的流的名称。\n\n#### 例子\n\n假设在 `http` 配置块中的 `listen` 配置项是：\n\n    http {\n        ...\n        server {\n            listen 8080; #不是默认的 80 端口\n            ...\n\n            location /live {\n                flv_live on;\n            }\n        }\n    }\n\n在 `rtmp` 配置块中的 `listen` 配置项是：\n\n    rtmp {\n        ...\n        server {\n            listen 1985; #不是默认的 1935 端口\n            ...\n\n            application myapp {\n                live on;\n            }\n        }\n    }\n\n并且发布的流的名称是 `mystream`，那么基于 HTTP 的播放 url 是：\n\n    http://example.com:8080/live?port=1985\u0026app=myapp\u0026stream=mystream\n\n#### 注意\n\n由于一些播放器不支持 HTTP 块传输, 这种情况下最好在指定了 `flv_live on;` 的 location 中指定 `chunked_transfer_encoding off`，否则播放会失败。\n\n#### RTMP 方式\n\n    rtmp://example.com[:port]/appname/streamname\n\n#### HLS 方式\n\n    http://example.com[:port]/dir/streamname.m3u8\n\n#### DASH 方式\n\n    http://example.com[:port]/dir/streamname.mpd\n\n## 示例图片\n\n### RTMP ([JW Player](https://www.jwplayer.com)) \u0026 HTTP-FLV ([VLC](http://www.videolan.org))\n\n![RTMP \u0026 HTTP-FLV](samples/jwplayer_vlc.png)\n\n### HTTP-FLV ([flv.js](https://github.com/Bilibili/flv.js))\n\n![HTTP-FLV](samples/flv.js.png)\n\n## nginx.conf 实例\n\n### 注意\n\n配置项 `rtmp_auto_push`，`rtmp_auto_push_reconnect` 和 `rtmp_socket_dir` 在 Windows 上不起作用，除了 Windows 10 17063 以及后续版本之外，因为多进程模式的 `relay` 需要 Unix domain socket 的支持，详情请参考 [Unix domain socket on Windows 10](https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows)。\n\n最好将配置项 `worker_processes` 设置为 1，因为在多进程模式下，`ngx_rtmp_stat_module` 可能不会从指定的 worker 进程获取统计数据，因为 HTTP 请求是被随机分配给 worker 进程的。`ngx_rtmp_control_module` 也有同样的问题。这个问题可以通过这个补丁 [per-worker-listener](https://github.com/arut/nginx-patches/blob/master/per-worker-listener) 优化。\n\n另外，`vhost` 功能在单进程模式下没有问题，但是在多进程模式下还不能完全正确运行，等待修复。例如，下面的配置在多进程模式下是没有问题的：\n\n    rtmp {\n        ...\n        server {\n            listen 1935;\n            server_name domain_name;\n\n            application myapp {\n                ...\n            }\n        }\n    }\n\n而使用下面的配置，当 publisher 在第二个 `server` 上发布媒体流，播放请求以该配置（不管端口是不是 1935）访问非 publisher 的 worker 进程时是有问题的：\n\n    rtmp {\n        ...\n        server {\n            listen 1935;\n            server_name 1st_domain_name;\n\n            application myapp {\n                ...\n            }\n        }\n\n        server {\n            listen 1945;\n            server_name 2nd_domain_name;\n\n            application myapp {\n                ...\n            }\n        }\n    }\n\n如果 [NGINX](http://nginx.org) 是以多进程模式运行并且平台支持 socket 选项 `SO_REUSEPORT`，那么在配置项 `listen` 后添加选项 `reuseport` 可以解决惊群问题。\n\n    rtmp {\n        ...\n\n        server {\n            listen 1935 reuseport;\n            ...\n        }\n    }\n\n### 配置实例\n\n    worker_processes  1; #运行在 Windows 上时，设置为 1，因为 Windows 不支持 Unix domain socket\n    #worker_processes  auto; #1.3.8 和 1.2.5 以及之后的版本\n\n    #worker_cpu_affinity  0001 0010 0100 1000; #只能用于 FreeBSD 和 Linux\n    #worker_cpu_affinity  auto; #1.9.10 以及之后的版本\n\n    error_log logs/error.log error;\n\n    #如果此模块被编译为动态模块并且要使用与 RTMP 相关的功\n    #能时，必须指定下面的配置项并且它必须位于 events 配置\n    #项之前，否则 NGINX 启动时不会加载此模块或者加载失败\n\n    #load_module modules/ngx_http_flv_live_module.so;\n\n    events {\n        worker_connections  4096;\n    }\n\n    http {\n        include       mime.types;\n        default_type  application/octet-stream;\n\n        keepalive_timeout  65;\n\n        server {\n            listen       80;\n\n            location / {\n                root   /var/www;\n                index  index.html index.htm;\n            }\n\n            error_page   500 502 503 504  /50x.html;\n            location = /50x.html {\n                root   html;\n            }\n\n            location /live {\n                flv_live on; #打开 HTTP 播放 FLV 直播流功能\n                chunked_transfer_encoding on; #支持 'Transfer-Encoding: chunked' 方式回复\n\n                add_header 'Access-Control-Allow-Origin' '*'; #添加额外的 HTTP 头\n                add_header 'Access-Control-Allow-Credentials' 'true'; #添加额外的 HTTP 头\n            }\n\n            location /hls {\n                types {\n                    application/vnd.apple.mpegurl m3u8;\n                    video/mp2t ts;\n                }\n\n                root /tmp;\n                add_header 'Cache-Control' 'no-cache';\n            }\n\n            location /dash {\n                root /tmp;\n                add_header 'Cache-Control' 'no-cache';\n            }\n\n            location /stat {\n                #推流播放和录制统计数据的配置\n\n                rtmp_stat all;\n                rtmp_stat_stylesheet stat.xsl;\n            }\n\n            location /stat.xsl {\n                root /var/www/rtmp; #指定 stat.xsl 的位置\n            }\n\n            #如果需要 JSON 风格的 stat, 不用指定 stat.xsl\n            #但是需要指定一个新的配置项 rtmp_stat_format\n\n            #location /stat {\n            #    rtmp_stat all;\n            #    rtmp_stat_format json;\n            #}\n\n            location /control {\n                rtmp_control all; #rtmp 控制模块的配置\n            }\n        }\n    }\n\n    rtmp_auto_push on;\n    rtmp_auto_push_reconnect 1s;\n    rtmp_socket_dir /tmp;\n\n    rtmp {\n        out_queue           4096;\n        out_cork            8;\n        max_streams         128;\n        timeout             15s;\n        drop_idle_publisher 15s;\n\n        log_interval 5s; #log 模块在 access.log 中记录日志的间隔时间，对调试非常有用\n        log_size     1m; #log 模块用来记录日志的缓冲区大小\n\n        server {\n            listen 1935;\n            server_name www.test.*; #用于虚拟主机名后缀通配\n\n            application myapp {\n                live on;\n                gop_cache on; #打开 GOP 缓存，减少首屏等待时间\n            }\n\n            application hls {\n                live on;\n                hls on;\n                hls_path /tmp/hls;\n            }\n\n            application dash {\n                live on;\n                dash on;\n                dash_path /tmp/dash;\n            }\n        }\n\n        server {\n            listen 1935;\n            server_name *.test.com; #用于虚拟主机名前缀通配\n\n            application myapp {\n                live on;\n                gop_cache on; #打开 GOP 缓存，减少首屏等待时间\n            }\n        }\n\n        server {\n            listen 1935;\n            server_name www.test.com; #用于虚拟主机名完全匹配\n\n            application myapp {\n                live on;\n                gop_cache on; #打开 GOP 缓存，减少首屏等待时间\n            }\n        }\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinshining%2Fnginx-http-flv-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinshining%2Fnginx-http-flv-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinshining%2Fnginx-http-flv-module/lists"}