# MP4 (H264) migrating from lighttpd to nginx

**URL:** <https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210>\
**Category:** NGINX\
**Created:** [January 30, 2012, 4:10am UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210 "2012-01-30T04:10:10Z")\
**Posts on this page:** 9\
**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:** [January 30, 2012, 4:10am UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/1 "2012-01-30T04:10:10Z")

</div>

It is great that MP4 module came out. So we decided to migrate our video  
streaming servers to nginx. In fact those are our last non-nginx  
webservers (not counting IIS).

However we have some troubles. In our Flash player, MP4 video starts  
play only after it is completelly loaded. I thought there is problem  
with player, so I tried open-source flowplayer and it was the same.

So I thought that there is problem with nginx HTTP response. I compared  
it completelly to lighttpd response, and made them exactly same. I even  
changed the nginx server name to “lighttpd” (source recompilation was  
needed), added headers like “X-Mod-H264-Streaming”, but still no luck.

When serving video through lighttpd, it starts play immediately.  
When serving through nginx, it starts play only after it is fully  
loaded.

However requests for partial files like video.mp4?start=32.33 works well  
with nginx. I think there is problem with initial request (the one  
without “start” parameter).

I’m stuck. Any ideas what else should be checked?  
Any advice would be appreciated. Thanks.

Ondrej

–  
Ondrej JOMBIK  
Platon Technologies s.r.o., Hlavna 3, Sala SK-92701  
+421 903 PLATON - removed\_email\_address@domain.invalid - [http://platon.org](http://platon.org)

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 30, 2012, 7:36am UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/2 "2012-01-30T07:36:35Z")

</div>

I am no expert in streaming, but I read from the  
ngx\_http\_mp4\_module[http://nginx.org/en/docs/http/ngx\_http\_mp4\_module.html](http://nginx.org/en/docs/http/ngx_http_mp4_module.html)page  
a special request of ‘start=0’ would transfer metadata.  
Maybe without it, the file would simply be considered as a normal file  
and  
then served completely before being able to be read ?

## My 2 cents…

_B. R._

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 30, 2012, 8:08am UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/3 "2012-01-30T08:08:40Z")

</div>

Thanks B.R., you are exactly right, after appending “?start=0” video  
starts to play immediatelly.

I also discovered that our MP4 files are encoded with index at the end  
of file. lighttpd was silently moving this index (moov) to the  
beginning.

That raises question for some nginx performance guru:

What is better: recode all the MP4 files (thousands of thousands) and  
move index to the beginning or simply use “?start=0” parameter?

I feel that recoding may save us some memory during future request  
processing, because with “?start=0” nginx must at least see the end of  
file and fetch the index.

Any opinion would be welcome. I have no problem to recode/reindex milion  
files, but it has to have some meaning first 😉

Thanks

Ondrej

On Mon, 30 Jan 2012, B.R. wrote:

> > So I thought that there is problem with nginx HTTP response. I compared  
> > without “start” parameter).
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\__ **\*\*** _  
> > 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)[http://mailman.nginx.org/mailman/listinfo/nginx](http://mailman.nginx.org/mailman/listinfo/nginx)

> >

–  
Ondrej JOMBIK  
Platon Technologies s.r.o., Hlavna 3, Sala SK-92701  
+421 903 PLATON - [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) - [http://platon.org](http://platon.org)

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 30, 2012, 8:31am UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/4 "2012-01-30T08:31:33Z")

</div>

Hello!

On Mon, Jan 30, 2012 at 04:09:33AM +0100, Ondrej Jombik wrote:

> changed the nginx server name to “lighttpd” (source recompilation was  
> I’m stuck. Any ideas what else should be checked?  
> Any advice would be appreciated. Thanks.

On initial request nginx returns original file, and if moov atom  
with metadata goes after mdat (one with media data) you’ll see  
“video starts after loading” problem. Recoding files to place  
moov atom first will solve it.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 30, 2012, 8:51am UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/5 "2012-01-30T08:51:58Z")

</div>

I suggest using “qt-faststart” which is a simple command line tool which  
does this.

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 30, 2012, 9:01am UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/6 "2012-01-30T09:01:16Z")

</div>

On Mon, Jan 30, 2012 at 08:08:13AM +0100, Ondrej Jombik wrote:

> move index to the beginning or simply use “?start=0” parameter?
> 
> I feel that recoding may save us some memory during future request  
> processing, because with “?start=0” nginx must at least see the end of  
> file and fetch the index.
> 
> Any opinion would be welcome. I have no problem to recode/reindex milion  
> files, but it has to have some meaning first 😉

From perfomance point of view it’s better to move the index to the  
beginning.  
However, you do not need to recode the files, but just to move the  
index.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 30, 2012, 10:24am UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/7 "2012-01-30T10:24:15Z")

</div>

On Sun, 29 Jan 2012 23:51:19 -0800, Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I suggest using “qt-faststart” which is a simple command line tool  
> which does this.

A sort of qt-faststart howto:  
[http://www.stoimen.com/blog/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/](http://www.stoimen.com/blog/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/)

M.

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 30, 2012, 12:42pm UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/8 "2012-01-30T12:42:29Z")

</div>

Hi again,

I am glad a little Googling + some basic reading made me able to answer  
your expert question! :oP

I am still no expert, but from what I read on the link I gave you, there  
is  
a link to how to prepare files to be served in streaming.  
It was mentioned that if a file is not prepared as it should be  
(metadata  
at the start of files), the consequence was the calculation of this  
missing  
metadata CPU & I/O overhead, including extra harddisk use… which is  
bad  
for performance! They even not mention the cache faults…  
It is said that the metadata must be the first thing read in a file  
which  
is read sequentially from the beginning. So, if your metadata is at the  
end… I let you finish that ^^

Nginx, like lighttpd, is able to do that on its own but that kills  
performance, so the better the files are prepared, the less you will use  
resources on your server.  
However, as Igor mentioned, it is only about moving metadata, not  
encoding  
the whole files again, which is a simpler task to do.

## If you wish to process your files and that you have a lot of them, maybe it is not worth it to do so with a unique and long shot. Maybe you could make your files served through some checking server-sided script, which will serve the data from the current file and concurrently regenerate a new well-made file for future requests? That’s maybe not the best solution but that would allow to start converting regularly served files first. Of course it would be a temporary one…

_B. R._

---

<div class="post-metadata">

**Author:** ![Ondrej\_Jombik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a698b9/32.png) [@Ondrej\_Jombik](https://www.ruby-forum.com/u/Ondrej_Jombik)\
**Post date:** [January 30, 2012, 5:10pm UTC](https://www.ruby-forum.com/t/mp4-h264-migrating-from-lighttpd-to-nginx/216210/9 "2012-01-30T17:10:07Z")

</div>

Sometimes it happens that you are working under light, and that light is  
so bright, so you are unable to see obvious things. This happened to me.

Yes, now my initial question looks a bit strange, but thanks to asking  
I have at least two options how to deal with the issue.

According to Igor, moving index to the beginning of the file should be  
better from the performance point of view. Since we are migrating not  
only from lighttpd to nginx, but also to new storage, I will put this  
“recoding” into migration batch and we will have nice MP4 files at the  
end.

Thanks again and… nginx mp4 module rocks! 🙂

Ondrej

On Mon, 30 Jan 2012, B.R. wrote:

> for performance! They even not mention the cache faults…  
> If you wish to process your files and that you have a lot of them, maybe it  
> On Mon, Jan 30, 2012 at 04:23, Mark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > On Sun, 29 Jan 2012 23:51:19 -0800, Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > > I suggest using “qt-faststart” which is a simple command line tool  
> > > which does this.
> > 
> > A sort of qt-faststart howto:

[http://www.stoimen.com/blog/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/](http://www.stoimen.com/blog/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/)

–  
Ondrej JOMBIK  
Platon Technologies s.r.o., Hlavna 3, Sala SK-92701  
+421 903 PLATON - [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) - [http://platon.org](http://platon.org)
