Drupal 7, MediaFront, MPEG-4 moov atoms, and buffering

In this article, I'll address why some MPEG files buffer/load completely before playing and then give you several solutions to resolve this issue. For some background, it's well documented that MPEG-4 files could buffer completely before playing from a website. If you have a very small video, this might not be an issue. With video times of 15, 30, or even 60 mins+, it can be a real issue for many site builders. Even my 4 min videos were driving me nuts...

Btw, I've been using Media and MediaFront to stream videos on a few client projects. It's a great combination and suggest you try these modules out on your next video project!

After experiencing the buffering problem, I searched the MediaFront queue and found a related issue, Buffer/Load Time for Mp3s is very, very long. In scanning the comments, travist replied with a comment about video metadata needing to be at the beginning of the file.

After a bit of research, I found out this issue is related to moov (movie) atoms which are pieces of metadata stored within the video file. When these atoms are at the end of the file, the entire video file must load before playing. The metadata contains all sorts of information about the file. If the player doesn't get the metadata when the file first loads, it has to wait until it sees the data before it can start to play. To understand all the low-level details, read this excellent article, Understanding the MPEG-4 movie atom.

The Solution

The easiest solution is to determine if your encoding software has an option to store the moov atoms at the beginning of the file. For me, I was converting WMV files to MPEG-4 and using Handbrake. During my conversions, I did not use the "Web optimized" option. But, when I checked this option, the moov atoms were correctly located at the beginning of the file. I'll show you how to determine where your moov atoms are located in a moment.

That's great but what if you've converted 100's of video files to MPEG-4 already?

How do you like your parsley?

One thing I love about Open Source is how we come up with our names... Just know that AtomicParsley will soon become your best friend when you need to check where your moov atoms are located. And, I know that checking my moov on Friday night is where the action is at!

Download AtomicParsley. There are binaries for Windows, Mac, and Linux as well as source code. And yes, the Linux binaries work on .deb or .rpm distributions. You can also access the man page.

To check the location of your moov atoms,

# In a shell or terminal.
$ AtomicParsley <your_mpeg_file> -T 

will display all atoms in your video file. You want to ensure your "Atom moov" lines are ABOVE your "Atom mdat" line. "Atom mdat" represents the video data. The best way to see this in action to view the AtomicParsley home page. Look at the AtomicParsley output.

So, now you're like me...your "Atom moov" lines are at the end of the AtomicParsley output, what's next?

A French lesson from Ecole Nationale Supérieure des Télécommunications

Our friends at Telecom ParisTech have developed a wonderful Open Source solution! GPAC, more specifically MP4Box, is the project you are looking to use.

You'll need to download/install GPAC to gain access to MP4Box. For Ubuntu, a simple

# In a shell or terminal.
$ apt-get install gpac 

works just fine. On .rpm distributions, download the latest rpmfusion-free-release-stable rpm.

# In a shell or terminal.
$ rpm -Uvh rpmfusion-free-release-stable.rpm
$ yum install gpac 

An alternative for Mac and Windows users is QT Index Swapper which is an Adobe Air application. Unfortunately, Adobe decided not to support Air for Linux desktop environments anymore.

Last, ffmpeg also includes a utility called qt-faststart that you could use as well. Read the comments at the beginning of the file for more information.

Lets move some moovs

There are two MP4Box options when preparing your file for web-based video streaming. Both of these commands will overwrite your original file. Make a backup! Also, you can use the -new option to create a new file once your conversion is complete. And, you can batch process so regardless of how many files you have, it's a simple process.

# In a shell or terminal.
$ MP4Box -inter <time in ms> <your_mpeg_file>
$ MP4Box -isma <your_mpeg_file> 

The -inter option is used to interleave media data in chunks of the desired duration and places the moov atoms at the beginning of the file. The -isma option is used to convert the video file to ISMA 1.0 specification. I tried both options above and both moved the metadata to the beginning of the file. During the conversion process, I noticed that the -isma option also performed the same processing as the -inter option. So, I decided to use the -isma option for my needs. If in doubt, read the MP4Box documentation and see which option makes sense for you.

Once you're done, MEPG videos streamed from your website will play in a few seconds after loading!

Comments, questions, errors, typos? Do you use something different? Let me know!

Add new comment

Enter your email address. This will not be displayed when your comment is posted.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.