How to web optimize your MP4 videos

Write tutorials here
There are more tutorials here
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Level 4
Level 4
Posts: 209
Joined: Thu Jun 17, 2010 12:41 am

How to web optimize your MP4 videos

Postby Mozenrath » Wed Feb 23, 2011 1:25 am

So you've edited your video in a wonderful program called Avidemux. You've got everything just the way you like it, so you export the video as an h.264 mp4 so that you can stream it on your website. Wait, why isn't it streaming? Why does the flash player have to download the whole file just to play it!? I'll tell you why:

As handy a program as Avidemux is, for some reason they do not provide an option to place the mp4 metadata at the beginning of the file instead of at the end. Because Avidemux places the metadata at the end of the file, whatever flash player you use(JW PLayer, Flowplayer, etc) has to download the whole file just to get the metadata that allows it to properly read the video.

Some of you might say "Why don't you just use mencoder to remake the file afterwards with streaming enabled?" Well it's bad practice to encode a video twice because of the use of lossy video codecs. Plus that's just extra work for something that should be simple. I got sick of using Metadatamover through Windows in Virtualbox, so I set out to find my own solution.

In my opinion, the best solution is to use a Nautilus script to automatically move the metadata to the front of the video file. Note that I have only ever tried this on h.264 encoded video in an MP4 container file. I don't know if this will work for any other codec or video container.

This script relies on MP4Box, which is part of the gpac software package. Gpac is in the LM software repositories so all you have to do is install it through Synaptic.

Here is the script:

MP4Box -inter 0.5 "$FILE"

It's as simple as that. Save it as "Web Optimize MP4" without quotes in directory ~/.gnome2/nautilus-scripts, and mark it as executable(Right-Click>Properties>Permissions>Allow executing file as program).

Now all you have to do is right-click on your mp4 file, go to Scripts and click on Web Optimize MP4. Your mp4 video will be made stream-able in just seconds without having to re-encode the entire video.

I think this is the best solution because while Nautilus only runs on Linux, MP4Box is multi-platform, so you can easily use it on Windows or Mac if you wanted to.

Th-th-th-that's all, folks!

Level 14
Level 14
Posts: 5015
Joined: Sun Jan 10, 2010 8:54 am
Location: Salem, Oregon

Re: How to web optimize your MP4 videos

Postby tdockery97 » Wed Feb 23, 2011 1:48 am

I don't do video encoding at all, but I just had to comment that this is an absolutely priceless tutorial. It never ceases to amaze me how much a short little script can do.

Level 1
Level 1
Posts: 1
Joined: Thu Feb 28, 2013 9:40 am

Re: How to web optimize your MP4 videos

Postby jpmiranda » Thu Feb 28, 2013 10:48 am

Thank you very much for your post.
It's OK on Linux Mint 11, in which run Gnome2 and Nautilus.

Actually I've been using Mint Maya in other PC, which comes with Mate and Caja (as Gnome and Nautilus) and I tried to adapt your script creating a folder called "caja-scripts" into ".mate2" and changing the script as follows:

MP4Box -inter 0.5 "$FILE"

When doing right-click on the mp4 file there's no appear anything called "Scripts" to click on.
Of course, gpac (and MP4Box) is installed in the system.

Have you any idea how to adapt your useful script on a newer mint distro?

Again thanks.

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 4 guests