# Using Nginx to stream h.264 video

**URL:** <https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970>\
**Category:** NGINX\
**Created:** [March 17, 2012, 6:53pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970 "2012-03-17T18:53:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 17, 2012, 6:53pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/1 "2012-03-17T18:53:45Z")

</div>

Hi,

I’m currently trying to setup Nginx to stream an mp4 video file.

Currently I have read through:

[http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Nginx-Version2](http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Nginx-Version2)

[http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Testing-Version2](http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Testing-Version2)

but wasn’t quite sure how to integrate these with Nginx itself.

I have a few questions regarding this:

Is this the mp4 module that I need to be able to stream or is there an  
embedded solution?

Currently I’m running CentOS 6.2 as the server OS and have install Nginx  
from the EPEL repo… does this contain the module or do I need to get  
the source code and compile it in?

If I need the source code where can I find it as I checked on the site  
but got lost?

Once I have everything correctly up and running how do integrate or  
rather embed a video into an html page? - are there any guides on this?

Sorry if these questions are quite obvious but I am totally new to Nginx  
and I’m still trying to understand the documentation.

Regards,

Kaya

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 17, 2012, 7:42pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/2 "2012-03-17T19:42:44Z")

</div>

On Sat, 2012-03-17 at 17:53 +0000, Kaya Saman wrote:

> Is this the mp4 module that I need to be able to stream or is there an  
> embedded solution?

> **[Module ngx\_http\_mp4\_module](http://nginx.org/en/docs/http/ngx_http_mp4_module.html)**

> Currently I’m running CentOS 6.2 as the server OS and have install Nginx  
> from the EPEL repo… does this contain the module or do I need to get  
> the source code and compile it in?

I would uninstall this and install from the official repositories  
instead (they are newer):

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Regards,  
Cliff

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 17, 2012, 8:17pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/3 "2012-03-17T20:17:36Z")

</div>

On 03/17/2012 06:41 PM, Cliff W. wrote:

> On Sat, 2012-03-17 at 17:53 +0000, Kaya Saman wrote:
> 
> > Is this the mp4 module that I need to be able to stream or is there an  
> > embedded solution?  
> > [Module ngx\_http\_mp4\_module](http://nginx.org/en/docs/http/ngx_http_mp4_module.html)

Thanks. The links states:

" This module is not built by default, it should be enabled with the  
|–with-http\_mp4\_module| configuration parameter. "

So does this mean that from the **official** repo stated below that  
Nginx isn’t built with this module???

If not then where do I find the source code to get it or can I grab the  
module from the repo, as in yum install mp4\_module?

> > Currently I’m running CentOS 6.2 as the server OS and have install Nginx  
> > from the EPEL repo… does this contain the module or do I need to get  
> > the source code and compile it in?  
> > I would uninstall this and install from the official repositories  
> > instead (they are newer):
> 
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/Install#Official_Red_Hat.2FCentOS_packages)
> 
> Regards,  
> Cliff

Regards,

Kaya

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 17, 2012, 8:54pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/4 "2012-03-17T20:54:16Z")

</div>

On Sat, 2012-03-17 at 19:16 +0000, Kaya Saman wrote:

> –with-http\_mp4\_module configuration parameter. "
> 
> So does this mean that from the **official** repo stated below that  
> Nginx isn’t built with this module???

It is. Here’s the output from “nginx -V” on one of my CentOS systems  
with the official nginx installed:

–prefix=/etc/nginx/  
–sbin-path=/usr/sbin/nginx  
–conf-path=/etc/nginx/nginx.conf  
–error-log-path=/var/log/nginx/error.log  
–http-log-path=/var/log/nginx/access.log  
–pid-path=/var/run/nginx.pid  
–lock-path=/var/run/nginx.lock  
–http-client-body-temp-path=/var/cache/nginx/client\_temp  
–http-proxy-temp-path=/var/cache/nginx/proxy\_temp  
–http-fastcgi-temp-path=/var/cache/nginx/fastcgi\_temp  
–http-uwsgi-temp-path=/var/cache/nginx/uwsgi\_temp  
–http-scgi-temp-path=/var/cache/nginx/scgi\_temp  
–user=nginx --group=nginx  
–with-http\_ssl\_module  
–with-http\_realip\_module  
–with-http\_addition\_module  
–with-http\_sub\_module  
–with-http\_dav\_module  
–with-http\_flv\_module  
–with-http\_mp4\_module

^^^^^^^^^^^^^^^^^^^^^^

–with-http\_gzip\_static\_module  
–with-http\_random\_index\_module  
–with-http\_secure\_link\_module  
–with-http\_stub\_status\_module  
–with-mail  
–with-mail\_ssl\_module  
–with-file-aio  
–with-ipv6  
–with-cc-opt=‘-O2 -g -march=i386 -mtune=i686’

> If not then where do I find the source code to get it or can I grab  
> the module from the repo, as in yum install mp4\_module?

The source code is available at [http://nginx.org](http://nginx.org)

More information on Nginx can be found at [http://wiki.nginx.org](http://wiki.nginx.org)  
(including links to the source).

Regards,  
Cliff

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 17, 2012, 9:02pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/5 "2012-03-17T21:02:19Z")

</div>

Thanks a lot Cliff I really appreciate the help!

However as per the documentation it claims  
{[http://nginx.org/en/docs/http/ngx\_http\_mp4\_module.html](http://nginx.org/en/docs/http/ngx_http_mp4_module.html)}:

"

location /video/ {  
mp4;  
mp4\_buffer\_size 1m;  
mp4\_max\_buffer\_size 5m;  
}

"

as the configuration for the module.

I added the above to the nginx.conf file and now nginx won’t start so  
I’m guessing that it’s been added to the wrong place??

Also I guess what I’m trying to find out more then anything else is if  
Nginx will be able to serve up information like YouTube? By embedding  
the video into an html page then streaming via web browser with  
sufficient plugin or straight to a player such as Mplayer or Xine?

Is there any guide or howto on how to do this as the documentation seems  
a little sparse!

Regards,

Kaya

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 17, 2012, 9:15pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/6 "2012-03-17T21:15:22Z")

</div>

Many thanks Cliff for your support!

Regards,

Kaya

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 17, 2012, 9:12pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/7 "2012-03-17T21:12:16Z")

</div>

On Sat, 2012-03-17 at 20:01 +0000, Kaya Saman wrote:

> I added the above to the nginx.conf file and now nginx won’t start so  
> I’m guessing that it’s been added to the wrong place??

Checking your logs is somewhat better than guessing 😉 On CentOS  
that’s probably /var/log/nginx/error.log.

> Also I guess what I’m trying to find out more then anything else is if  
> Nginx will be able to serve up information like YouTube? By embedding  
> the video into an html page then streaming via web browser with  
> sufficient plugin or straight to a player such as Mplayer or Xine?

I believe the mp4 module is designed for use with Flash. Someone else  
who has actually used it could probably offer a more informed opinion.

> Is there any guide or howto on how to do this as the documentation seems  
> a little sparse!

I suspect it’s sparse because there’s not much to it on the Nginx-side  
of things. If you are looking for a guide for the client-side as well,  
I can only suggest Google or hope that someone here can offer more  
assistance on that end.

Regards,  
Cliff

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 18, 2012, 1:40pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/8 "2012-03-18T13:40:24Z")

</div>

> Is there any guide or howto on how to do this as the documentation seems  
> a little sparse!

nginx and the mp4 module documentation is about the server side of  
things only.

If you need documentation and solutions for the client side, take a look  
at  
JWPlayer [1], but remember its off-topic on this list. Longtailvideo has  
forums and commercial support offerings, in case you need any support on  
JWPlayer.

[1] [Video technology & monetization platform for streamers, publishers & advertisers | JWX](http://www.longtailvideo.com/players/)

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 18, 2012, 6:00pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/9 "2012-03-18T18:00:18Z")

</div>

Nginx can’t write a website for you if that’s what you mean

It’s long hard work making a tube site, either pay someone or get  
learning 🙂

–  
Richard

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 18, 2012, 1:44pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/10 "2012-03-18T13:44:46Z")

</div>

On 03/18/2012 12:39 PM, Lukas T. wrote:

> [1] [Video technology & monetization platform for streamers, publishers & advertisers | JWX](http://www.longtailvideo.com/players/)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

Many thanks!

I actually discovered how to ‘server up’ video files using nginx:

```
 location /video/ {
     mp4;
     mp4_buffer_size 1m;
     mp4_max_buffer_size 5m;
 root /usr/share/nginx/html;
 }

```

by putting the above into conf.d/default.conf

Now it all works fine and am able to access the video via mplayer.

Quick question… is building an html page then embedding a video into  
it client side? I always considered that server side while my view of  
client side was always just the browser and URL…

Regards,

Kaya

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 18, 2012, 8:39pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/11 "2012-03-18T20:39:43Z")

</div>

The primary reason for the mp4 module is to allow seeking of the video  
before the whole file has been downloaded by flash - it’s all a nasty  
workaround for flash being \*\*\*\*

Mp4 can be used in some browsers with html5 video tag (and most mobile  
devices)  
Otherwise you will have to use one of the flash video players, like  
flowplayer or jwplayer

The nginx mp4 filter is only beneficial to the latter as it allows  
pseudo-streaming in flash  
Html5 will work fine without the mp4 module and indeed in other httpds,  
as it uses the http range header (e.g. to seek the video, it just  
“resumes” the download from a later point)

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 18, 2012, 9:07pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/12 "2012-03-18T21:07:49Z")

</div>

On 03/18/2012 07:39 PM, Richard K. wrote:

> The primary reason for the mp4 module is to allow seeking of the video before  
> the whole file has been downloaded by flash - it’s all a nasty workaround for  
> flash being \*\*\*\*
> 
> Mp4 can be used in some browsers with html5 video tag (and most mobile devices)  
> Otherwise you will have to use one of the flash video players, like flowplayer  
> or jwplayer
> 
> The nginx mp4 filter is only beneficial to the latter as it allows  
> pseudo-streaming in flash  
> Html5 will work fine without the mp4 module and indeed in other httpds, as it  
> uses the http range header (e.g. to seek the video, it just “resumes” the download  
> from a later point)

Thanks the HTML5 video tag worked 🙂

Regards,

Kaya

---

<div class="post-metadata">

**Author:** ![Kaya\_Saman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7993a0/32.png) [@Kaya\_Saman](https://www.ruby-forum.com/u/Kaya_Saman)\
**Post date:** [March 18, 2012, 7:03pm UTC](https://www.ruby-forum.com/t/using-nginx-to-stream-h-264-video/217970/13 "2012-03-18T19:03:49Z")

</div>

On 03/18/2012 04:59 PM, Richard K. wrote:

> Nginx can’t write a website for you if that’s what you mean

No no that’s not what I meant 🙂

A long time ago I played around with the Darwin Streaming Server from  
Apple and vaguely recall the mechanism used to call up the .mov files in  
an html page.

I was more referring to either a jscript or php snippet that would allow  
for the embed… just something quick and easy. No biggie though!

> It’s long hard work making a tube site, either pay someone or get learning 🙂

I personally don’t intend to, the only knowledge I need is what I kinda  
have already but would be nice to know the above (jscript or php)  
too…

Regards,

Kaya
