# HG changeset patch # User Ruslan Ermilov # Date 1316077153 0 # Node ID d889195c8db4c647c91b4424f46546c346f30579 # Parent dc1fa52222b45848adfccd212d2f921f52079318 Added ngx_http_mp4_module documentation. diff --git a/docs/GNUmakefile b/docs/GNUmakefile --- a/docs/GNUmakefile +++ b/docs/GNUmakefile @@ -58,7 +58,8 @@ docs/xslt/changes.xslt: docs/xsls/chang html: \ docs/html/ngx_core_module.html \ - docs/html/http/ngx_http_core_module.html + docs/html/http/ngx_http_core_module.html \ + docs/html/http/ngx_http_mp4_module.html docs/html/%.html: \ docs/xml/%.xml \ diff --git a/docs/xml/http/ngx_http_mp4_module.xml b/docs/xml/http/ngx_http_mp4_module.xml new file mode 100644 --- /dev/null +++ b/docs/xml/http/ngx_http_mp4_module.xml @@ -0,0 +1,156 @@ + + + + + + +
+ + +The module ngx_http_mp4_module provides pseudo-streaming +server-side support for H.264/AAC files typically having filename extensions +.mp4, .m4v, +and .m4a. + + + +Pseudo-streaming works in alliance with conformant Flash players. +A player sends an HTTP request to the server with a start time +argument in the request URI’s query string (named simply +start +and specified in seconds), and the server responds with a stream +so that its start position corresponds to the requested time, +for example: + +http://example.com/elephants_dream.mp4?start=238.88 + +This allows for a random seeking at any time, or starting playback +in the middle of a timeline. + + + +To support seeking, H.264-based formats store the metadata +in the so-called “moov atom.” +It is a part of the file that holds the index information for the +whole file. + + + +To start playback, a player first needs to read metadata. +This is done by sending a special request with the +start=0 +argument. Many encoding software will insert the metadata at +the end of the file. This is bad for pseudo-streaming: +the metadata needs to be located at the beginning of the file, +or else the entire file will have to be downloaded before it +starts playing. If a file is well-formed (with metadata at the +beginning of a file), nginx just sends back the contents of a file. +Otherwise, it has to read the file and prepare a new stream so that +metadata comes before media data. +This involves some CPU, memory, and disk I/O overhead, +so it is a good idea to + +prepare an original file for pseudo-streaming, +rather than having nginx do this on every such request. + + + +For a matching request with a non-zero +start +argument, nginx will read metadata from the file, prepare the +stream starting from the requested offset, and send it to a client. +This has the same overhead as described above. + + + +If a matching request does not include the +start +argument, there is no overhead, and the file is just sent as a static resource. +Some players also support byte-range requests, and thus do not require +this module at all. + + + +This module is not built by default, it should be enabled with the +--with-http_mp4_module +configuration parameter. + +If you were using the third-party mp4 module, be sure to disable it. + + + + +A similar pseudo-streaming support for FLV files is provided by the module +ngx_http_flv_module. + + +
+ + +
+ + + +location /video/ { + mp4; + mp4_buffer_size 1m; + mp4_max_buffer_size 5m; +} + + + +
+ + +
+ + +mp4 + +location + + +Turns on module processing in a surrounding location. + + + + + + +mp4_buffer_size size +mp4_buffer_size 512K +http +server +location + + +Sets the initial size of a memory buffer used to process MP4 files. + + + + + + +mp4_max_buffer_size size +mp4_max_buffer_size 10M +http +server +location + + +During metadata processing, a larger buffer may become necessary. +Its size cannot exceed the specified size, +or else nginx will return the server error +, +and log the following: + +"/some/movie/file.mp4" mp4 moov atom is too large: +12583268, you may want to increase mp4_max_buffer_size + + + + + +
+ +