Menu Sign In Contact FAQ
Welcome to our forums

Implementing an mp4 player on one's own server

The problem with most clients is that when clicking on a URL to say an mp4 file, you see absolutely nothing until the entire file is downloaded. (I don’t know why that is – it seems plain stupid software, because – with an .mp4, anyway; I believe a .mov is different – there is nothing to gain from waiting for the whole file). This is one example (50MB).

The more usual way to present a video is via a “player” interface, which is how Youtube and Vimeo etc do it. Then it starts to play right away. But that is very complicated to implement on one’s own server, mostly because one has to have loads of code in there detecting the client type (Iphone, Ipad, Firefox/windows, etc) and generating the right data based on that.

I looked into this a couple of years ago, and it was about 1 page of code, and I am not sure what server resources it needed (i.e. more than HTML). Is that feasible today, or are we now well into huge complexity to get anything that works?

Shoreham EGKA, United Kingdom

It will ‘just work’ with any modern browser subject to a few pre-requisites.

Check out this article here:-

Ok, the issue is indeed that your metadata is at the end:-

AtomicParsley winter-flight.mp4 -T
Atom ftyp @ 0 of size: 28, ends @ 28
Atom free @ 28 of size: 132, ends @ 160
Atom mdat @ 160 of size: 49039717 (^), ends @ 49039877
(^)denotes a 64-bit atom length
Atom moov @ 49039877 of size: 95005, ends @ 49134882

(moov needs to come before mdat)

Try re-encoding using handbrake with ‘Web Optimized’ selected, or ffmpeg with the -movflags faststart option.

Your webserver is configured fine:-

curl -I
HTTP/1.1 200 OK
Date: Thu, 05 Feb 2015 09:08:23 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8b DAV/2 PHP/5.3.5 Phusion_Passenger/3.0.12
Last-Modified: Wed, 04 Feb 2015 09:29:18 GMT
ETag: “2328060-2edbda6-50e3fd253f780”
Accept-Ranges: bytes
Content-Length: 49135014
Content-Type: video/mp4

Last Edited by stevelup at 05 Feb 09:16

Ok, I tested this:-

MP4Box -inter 0 winter-flight.mp4
Saving winter-flight.mp4: 0.500 secs Interleaving

The moov atom is now at the front:-

Atom ftyp @ 0 of size: 28, ends @ 28
Atom moov @ 28 of size: 87243, ends @ 87271
Atom mdat @ 87271 of size: 49039709, ends @ 49126980

And it plays instantly when you click the link:-

the issue is indeed that your metadata is at the end

Many thanks Steve!

I spoke to somebody about this recently (because I previously encountered the same issue with a .mov file (from a Canon compact camera) whose end was corrupted and the whole file was useless as a result) who said this is not possible with an mp4; there is no data at the end that’s required to play the file.

But clearly there is…

That file was produced by Handbrake, from a m2ts produced by Vegas.

So how does one avoid generating these perverted mp4 files? I can see the mp4faststart tool can be used to post-process them.

Shoreham EGKA, United Kingdom

Great – all I need is for somebody to translate that all into English

EHLE / Lelystad, Netherlands, Netherlands

In future, just tick the ‘web optimised’ button in Handbrake.

Don’t bother re-encoding the stuff you’ve already done though – use MP4Box as I did above. It only took 500ms to fix your winter flight file.

If you’ve got shell access to your web server, you could even run it on there to save re-uploading everything.

The default place for metadata is always at the end of the file, so yes – the person you spoke to was wrong. Your corrupted file is almost certainly recoverable by the way – e-mail me if you need assistance.

Many thanks again Steve!

That corrupted file is long gone. It was showing some avionics issue, but I did it later with another movie done with a phone. I posted a link in Usenet and various people had a go at it.

It is still very interesting that this works. It definitely did not used to work… Apple’s Quicktime player was better than most in this respect. When I try the fixed file now, at home I get a “web version of VLC” and at work I get a “web version of Quicktime” – both on winXP / Firefox. Evidently I have been rather “random” in the way I configured video playback But both work as they should i.e. the play starts right away. I wonder what client side software would not work with that file?

Chrome does not work though. It does nothing. I just see this

despite having added the “VLC” app.

Shoreham EGKA, United Kingdom

Chrome works fine here. You should’t need any kind of app:-

Firefox prompted me to ‘Activate QuickTime’ and then also just worked:-

I’m on a Mac though so YMMV!

35 Posts
Sign in to add your message

Back to Top