How to web optimize your MP4 videos

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
Mozenrath

How to web optimize your MP4 videos

Post by Mozenrath »

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:
#!/bin/bash
FILE=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | sed q)
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!
User avatar
tdockery97
Level 14
Level 14
Posts: 5058
Joined: Sun Jan 10, 2010 8:54 am
Location: Mt. Angel, Oregon

Re: How to web optimize your MP4 videos

Post by tdockery97 »

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.
Mint Cinnamon 20.1
jpmiranda

Re: How to web optimize your MP4 videos

Post by jpmiranda »

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:

#!/bin/bash
FILE=$(echo "$CAJA_SCRIPT_SELECTED_FILE_PATHS" | sed q)
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.
jpmiranda

Re: How to web optimize your MP4 videos

Post by jpmiranda »

The right path for Caja is:
/home/user/.config/caja/scripts/scriptMP4optimize.sh
Post Reply

Return to “Tutorials”