非常教程

Nginx参考手册

ngx_http_mp4_module

ngx_http_mp4_module

  • 示例配置
  • 指令
  • mp4
  • mp4_buffer_size
  • mp4_max_buffer_size
  • mp4_limit_rate
  • mp4_limit_rate_after

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

伪流与兼容的Flash播放器结盟。播放器以查询字符串参数中指定的开始时间(简单命名为start并以秒为单位指定)向服务器发送HTTP请求,并且服务器响应该流,使其起始位置与请求的时间相对应,例如:

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

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

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

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

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

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

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

如果匹配的请求不包含startend参数,则不会有开销,并且文件仅作为静态资源发送。有些玩家也支持字节范围请求,因此不需要这个模块。

该模块不是默认生成的,它应该使用--with-http_mp4_module配置参数启用。

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

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

示例配置

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

指令

句法:

MP4;

默认:

语境:

位置

打开周围位置的模块处理。

句法:

mp4_buffer_size大小;

默认:

mp4_buffer_size 512K;

语境:

http,服务器,位置

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

句法:

mp4_max_buffer_size大小;

默认:

mp4_max_buffer_size 10M;

语境:

http,服务器,位置

在元数据处理期间,可能需要更大的缓冲区。其大小不能超过指定的大小size,否则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 开启| 关闭| factor;

默认:

mp4_limit_rate关闭;

语境:

http,服务器,位置

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

该指令可作为我们商业订阅的一部分。

句法:

mp4_limit_rate_after时间;

默认:

mp4_limit_rate_after 60s;

语境:

http,服务器,位置

设置媒体数据的初始数量(在播放时间内测量),然后将响应进一步传输到客户端将受到速率限制。

该指令可作为我们商业订阅的一部分。

ngx_http_mp4_module
Nginx

Nginx是一款轻量级的 Web 服务器/反向代理服务器及电子邮件代理服务器,可在 BSD-like 协议下发行。其特点是占有内存少,并发能力强。

主页 https://nginx.org/
源码 http://hg.nginx.org/nginx
发布版本 1.13.6

Nginx目录

1.指南 | Guides
2.核心 | Core
3.ngx_google_perftools_module
4.ngx_http_access_module
5.ngx_http_addition_module
6.ngx_http_api_module
7.ngx_http_auth_basic_module
8.ngx_http_auth_jwt_module
9.ngx_http_auth_request_module
10.ngx_http_autoindex_module
11.ngx_http_browser_module
12.ngx_http_charset_module
13.ngx_http_core_module
14.ngx_http_dav_module
15.ngx_http_empty_gif_module
16.ngx_http_f4f_module
17.ngx_http_fastcgi_module
18.ngx_http_flv_module
19.ngx_http_geoip_module
20.ngx_http_geo_module
21.ngx_http_gunzip_module
22.ngx_http_gzip_module
23.ngx_http_gzip_static_module
24.ngx_http_headers_module
25.ngx_http_hls_module
26.ngx_http_image_filter_module
27.ngx_http_index_module
28.ngx_http_js_module
29.ngx_http_keyval_module
30.ngx_http_limit_conn_module
31.ngx_http_limit_req_module
32.ngx_http_log_module
33.ngx_http_map_module
34.ngx_http_memcached_module
35.ngx_http_mirror_module
36.ngx_http_mp4_module
37.ngx_http_perl_module
38.ngx_http_proxy_module
39.ngx_http_random_index_module
40.ngx_http_realip_module
41.ngx_http_referer_module
42.ngx_http_rewrite_module
43.ngx_http_scgi_module
44.ngx_http_secure_link_module
45.ngx_http_session_log_module
46.ngx_http_slice_module
47.ngx_http_spdy_module
48.ngx_http_split_clients_module
49.ngx_http_ssi_module
50.ngx_http_ssl_module
51.ngx_http_status_module
52.ngx_http_stub_status_module
53.ngx_http_sub_module
54.ngx_http_upstream_conf_module
55.ngx_http_upstream_hc_module
56.ngx_http_upstream_module
57.ngx_http_userid_module
58.ngx_http_uwsgi_module
59.ngx_http_v2_module
60.ngx_http_xslt_module
61.ngx_mail_auth_http_module
62.ngx_mail_core_module
63.ngx_mail_imap_module
64.ngx_mail_pop3_module
65.ngx_mail_proxy_module
66.ngx_mail_smtp_module
67.ngx_mail_ssl_module
68.ngx_stream_access_module
69.ngx_stream_core_module
70.ngx_stream_geoip_module
71.ngx_stream_geo_module
72.ngx_stream_js_module
73.ngx_stream_limit_conn_module
74.ngx_stream_log_module
75.ngx_stream_map_module
76.ngx_stream_proxy_module
77.ngx_stream_realip_module
78.ngx_stream_return_module
79.ngx_stream_split_clients_module
80.ngx_stream_ssl_module
81.ngx_stream_ssl_preread_module
82.ngx_stream_upstream_hc_module
83.ngx_stream_upstream_module