Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MP4 video delivery via PHP fails in Google Chrome

I'm currently trying to deliver MP4 video for use in HTML5 video (using video-js) via a PHP script for controlling video access. After some research I was able to get this working, with the help of the stackoverflow article found here. If I navigate to the PHP script, I can view the video as if I were viewing it via its absolute path (for instance localhost/myvideo.mp4 rather than localhost/myscript.php) in Firefox, Safari and IE. My problem is with Google Chrome, which simply shows a blacked out screen with a small media player in the centre, and does nothing.

I did try using a quick rewrite such as localhost/avideo.mp4 which routes to the PHP script, but unfortunately this didn't change anything.

Here's my script:

if (is_file($uri)) {
    header('Content-Type: video/mp4');
    if (isset($_SERVER['HTTP_RANGE'])) {
        $this->rangeDownload($uri);
        exit;
    } else {
        header("Content-Length: ".filesize($uri));
        $this->readfile_chunked($uri);
        exit;
    }
} else {
    //error
}

The rangeDownload method has been taken directly from appendix A of this link as suggested in the aforementioned stackoverflow article.

like image 533
AaronDS Avatar asked Jul 11 '12 11:07

AaronDS


2 Answers

Maybe the problem is with the URL (more specifically, the extension). Normally, you would use Content-Disposition header, but I understand that this is not desirable when delivering content to mobiles.

Try using localhost/myscript.php/myvideo.mp4

It is important not to use the "Content-Disposition" HTTP header, since some phones refuse to accept content when using it. By including the filename on the URL, you will trick the phone to think it's a real file and to accept it.

Now, when you send the download URL to the customer, you don't normally know yet what device the customer has, so you don't know what file formats the device will support. Therefore, you can't include the filename on that URL, and once again, you will need an intermediate download page. Once more, we will use a URL like:

http://wap.mydomain.tld/get.php/123456abcdef

This time, when the customer connects to download the content, the get.php script will not create a temporary file, but point to another script which streams the file contents. Supposing the resultant content to download will be "image.jpg", the intermediate download page could point the customer to a URL like:

http://wap.mydomain.tld/download.php/123456abcdef/image.jpg

From ( http://mobiforge.com/developing/story/content-delivery-mobile-devices )

like image 138
Yasei No Umi Avatar answered Sep 18 '22 15:09

Yasei No Umi


I understand you're using video-js but I recommend using html5media (also check out the github page for more info). I had to make videos available on a website for work and I tried a few things including video-js but html5media was the only one that I could get working in all browsers.

A side note that might help others: One of the requirements was that we hosted all files so that we wouldn't be reliant on third-party servers to serve JavaScript files or flash players, I can't remember if with video-js this was easy but I know with html5media we were able to download flowplayer and have everything on our servers.

And to generate the 3 recommend video formats (mp4, WebM and Theora) I used Miro Video Converter

like image 24
Dean Avatar answered Sep 21 '22 15:09

Dean