Nginx中文文档
DocsHome
  • 贡献导引
  • 介绍
    • 安装 nginx
    • 从源码构建 nginx
    • 初学者指南
    • 管理指南
    • 控制 nginx
    • 连接处理方式
    • 设置哈希
    • 调试日志
    • 记录日志到 syslog
    • 配置文件度量单位
    • 命令行参数
    • Windows 下的 nginx
    • QUIC 和 HTTP/3 支持
    • nginx 如何处理请求
    • 服务器名称
    • 使用 nginx 作为 HTTP 负载均衡器
    • 配置 HTTPS 服务器
    • nginx 如何处理 TCP/UDP 会话
    • 关于 nginScript
  • 其他
    • Linux 软件包
  • How-To
    • 在 Win32 平台上使用 Visual C 构建 nginx
    • 设置 Amazon EC2 的 Nginx Plus 环境
    • 使用 DTrace pid 提供程序调试 nginx
    • 转换重写规则
    • WebSocket 代理
  • 开发
    • 贡献指南
    • 开发指南
  • 模块参考
  • 核心功能
    • HTTP
      • ngx_http_core_module
      • ngx_http_access_module
      • ngx_http_addition_module
      • ngx_http_api_module
      • ngx_http_auth_basic_module
      • ngx_http_auth_jwt_module
      • ngx_http_auth_request_module
      • ngx_http_autoindex_module
      • ngx_http_browser_module
      • ngx_http_charset_module
      • ngx_http_dav_module
      • ngx_http_empty_gif_module
      • ngx_http_f4f_module
      • ngx_http_fastcgi_module
      • ngx_http_flv_module
      • ngx_http_geo_module
      • ngx_http_geoip_module
      • ngx_http_grpc_module
      • ngx_http_gunzip_module
      • ngx_http_gzip_module
      • ngx_http_gzip_static_module
      • ngx_http_headers_module
      • ngx_http_hls_module
      • ngx_http_image_filter_module
      • ngx_http_index_module
      • ngx_http_js_module
      • ngx_http_keyval_module
      • ngx_http_limit_conn_module
      • ngx_http_limit_req_module
      • ngx_http_log_module
      • ngx_http_map_module
      • ngx_http_memcached_module
      • ngx_http_mirror_module
      • ngx_http_mp4_module
      • ngx_http_perl_module
      • ngx_http_proxy_module
      • ngx_http_random_index_module
      • ngx_http_realip_module
      • ngx_http_referer_module
      • ngx_http_rewrite_module
      • ngx_http_scgi_module
      • ngx_http_secure_link_module
      • ngx_http_session_log_module
      • ngx_http_slice_module
      • ngx_http_spdy_module(过时)
      • ngx_http_split_clients_module
      • ngx_http_ssi_module
      • ngx_http_ssl_module
      • ngx_http_status_module(过时)
      • ngx_http_stub_status_module
      • ngx_http_sub_module
      • ngx_http_upstream_module
      • ngx_http_upstream_conf_module
      • ngx_http_upstream_hc_module
      • ngx_http_userid_module
      • ngx_http_uwsgi_module
      • ngx_http_v2_module
      • ngx_http_xslt_module
    • Mail
      • ngx_mail_core_module
      • ngx_mail_auth_http_module
      • ngx_mail_proxy_module
      • ngx_mail_ssl_module
      • ngx_mail_imap_module
      • ngx_mail_pop3_module
      • ngx_mail_smtp_module
    • Stream
      • ngx_stream_core_module
      • ngx_stream_access_module
      • ngx_stream_geo_module
      • ngx_stream_geoip_module
      • ngx_stream_js_module
      • ngx_stream_keyval_module
      • ngx_stream_limit_conn_module
      • ngx_stream_log_module
      • ngx_stream_map_module
      • ngx_stream_proxy_module
      • ngx_stream_realip_module
      • ngx_stream_return_module
      • ngx_stream_split_clients_module
      • ngx_stream_ssl_module
      • ngx_stream_ssl_preread_module
      • ngx_stream_upstream_module
      • ngx_stream_upstream_hc_module
      • ngx_stream_zone_sync_module
    • 其他
      • ngx_google_perftools_module
由 GitBook 提供支持
在本页
  • 示例配置
  • 指令
  • mp4
  • mp4_buffer_size
  • mp4_max_buffer_size
  • mp4_limit_rate
  • mp4_limit_rate_after
  • 原文档
  1. 核心功能
  2. HTTP

ngx_http_mp4_module

上一页ngx_http_mirror_module下一页ngx_http_perl_module

最后更新于5年前

ngx_http_mp4_module 模块为 MP4 文件提供伪流服务端支持。这些文件的扩展名通常为 .mp4、.m4v 或 .m4a。

伪流与兼容的 Flash 播放器可以很好地配合工作。播放器在查询字符串参数中指定的开始时间向服务器发送 HTTP 请求(简单地以 start 命名并以秒为单位),服务器以流响应方式使其起始位置与请求的时间相对应,例如:

http://example.com/elephants_dream.mp4?start=238.88

这将允许随时执行随机查找,或者在时间线中间开始回放。

为了支持搜索,基于 H.264 的格式将元数据存储在所谓的 moov atom 中。它是保存整个文件索引信息文件的一部分。

要开始播放,播放器首先需要读取元数据。通过发送一个有 start=0 参数的特殊请求来完成的。许多编码软件在文件的末尾插入元数据。这对于伪流播来说很糟糕,因为播放器必须在开始播放之前下载整个文件。如果元数据位于文件的开头,那么 nginx 就可以简单地开始发回文件内容。如果元数据位于文件末尾,nginx 必须读取整个文件并准备一个新流,以便元数据位于媒体数据之前。这涉及到一些 CPU、内存和磁盘 I/O 开销,所以最好事先,而不是让 nginx 在每个这样的请求上都这样处理。

该模块还支持设置播放结束点的 HTTP 请求(1.5.13)的 end 参数。end 参数可以与 start 参数一起指定或单独指定:

http://example.com/elephants_dream.mp4?start=238.88&end=555.55

对于有非零 start 或 end 参数的匹配请求,nginx 将从文件中读取元数据,准备有所需时间范围的流并将其发送到客户端 这与上面描述的开销相同。

如果匹配请求不包含 start 和 end 参数,则不会有开销,并且文件仅作为静态资源发送。有些播放器也支持 byte-range 请求,因此不需要这个模块。

该模块不是默认构建的,可以使用 --with-http_mp4_module 配置参数启用。

如果以前使用过第三方 mp4 模块,则应该禁用它。

示例配置

location /video/ {
    mp4;
    mp4_buffer_size       1m;
    mp4_max_buffer_size   5m;
    mp4_limit_rate        on;
    mp4_limit_rate_after  30s;
}

指令

mp4

-

说明

语法

mp4;

默认

——

上下文

location

启用对 location 模块处理。

mp4_buffer_size

-

说明

语法

mp4_buffer_size size;

默认

mp4_buffer_size 512K;

上下文

http、server、location

设置用于处理 MP4 文件的缓冲区的初始大小。

mp4_max_buffer_size

-

说明

语法

mp4_max_buffer_size time;

默认

mp4_max_buffer_size 10M;

上下文

http、server、location

在元数据处理期间,可能需要更大的缓冲区。它的大小不能超过指定的大小,否则 nginx 将返回 500(内部服务器错误)错误状态码,并记录以下消息:

"/some/movie/file.mp4" mp4 moov atom is too large:
12583268, you may want to increase mp4_max_buffer_size

mp4_limit_rate

-

说明

语法

mp4_limit_rate on | off | factor;

默认

p4_limit_rate off;

上下文

http、server、location

限制对客户响应的传输速率。速率限制基于所提供 MP4 文件的平均比特率。要计算速率,比特率将乘以指定的 factor。特殊值 on 对应于因子 1.1 。特殊值 off 禁用速率限制。限制是根据请求设置的,所以如果客户端同时打开两个连接,总体速率将是指定限制的两倍。

mp4_limit_rate_after

-

说明

语法

mp4_limit_rate_after time;

默认

mp4_limit_rate_after 60s;

上下文

http、server、location

设置媒体数据的初始数量(在回放时计算),之后进一步传输到客户端的响应将受到速率限制。

原文档

模块提供了对 FLV 文件的类伪流式的支持。

该指令可作为我们的一部分。

该指令可作为我们的一部分。

ngx_http_flv_module
商业订阅
商业订阅
http://nginx.org/en/docs/http/ngx_http_mp4_module.html
准备一个用于伪流传输的原始文件
指令
mp4
mp4_buffer_size
mp4_max_buffer_size
mp4_limit_rate
mp4_limit_rate_after