How to web optimize your MP4 videos
Posted: 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:
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!
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:
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).#!/bin/bash
FILE=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | sed q)
MP4Box -inter 0.5 "$FILE"
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!