1

I have one problem. I would like to order from (zip) files play video in such a way to get out connection so you can include it in HTML5 badge. As I gave an example. But this not working.

<?php $video = fopen('zip://video.zip#video.mp4', 'r'); ?>
<video>
    <source src='<? echo $video; ?>' type='video/mp4' /> 
</video>

1 Answers1

2

$video in the above code is just a server-side file handle you could use to read the file from the zip. It's not directly usable for the browser.

You'll need to handle reading the file and returning it in a separate HTTP request. Usually you'd use a second script for this. (Or if your video is relatively small, you might be able to use data urls, but it's not something I'd try to do.) Additionally, if you want to allow for byte range requests, you'd have to handle that yourself in your video serving logic.

Here's a fairly simple scenario:

My videos.zip file contains a couple of different videos, and I want to retrieve a specific one and show it on a page called video.php

First I have my viewer, say video.php, [edit: containing the video tag and with a URL to my second script as the source. Since I might want to serve the other file at some point, I set it up to accept a filename in the v query parameter.]

..some html/php..
<video>
   <source src='zipserve.php?v=itsrainintoast.mp4' type='video/mp4' /> 
</video>
..more html/php..

Then, in zipserve.php I have something like this:

$filename = $_GET['v']; //You probably want to check that this exists first, btw.
$fp = fopen('zip://videos.zip#'.$filename, 'r');
if($fp)
{
   header('content-type: video/mp4');
   //Note: you should probably also output an appropriate content-length header.
   while(!feof($fp))
   {
      echo fread($fp, 8196);
   }
   fclose($fp);
}
else
{
   echo 'Some error message here.';
}

--Addendum-- It should also be noted that this'll require the zip php extension to be enabled.

A more complete example of a video fetching script with range handling and the like can be found in the question at mp4 from PHP - Not playing in HTML5 Video tag but you'd need to tweak it to allow reading from the zip file.

Community
  • 1
  • 1
EPB
  • 3,939
  • 1
  • 24
  • 26
  • but thic cone not working for me show just black square and not play as well as on page "mp4 from PHP - Not playing in HTML5 Video tag" also not work. but zip:// workin becuse is tested – Toni Ojsteršek Sep 10 '13 at 06:17
  • If you're using Firefox, right-click the black box and pick play. It won't play automatically and I've not added any controls to click on to tell it to. – EPB Sep 10 '13 at 06:26
  • As an additional note, It may also take a while to start if the video is long and the index is at the end of the file, as it'll have to download the entire file to begin playing. When I made a typo I didn't get the black box, so you should be on the right track. – EPB Sep 10 '13 at 06:33
  • soory yes now working on desktop browsers... can you figure out why not on mobile phone.. ?? please – Toni Ojsteršek Sep 10 '13 at 06:33
  • Unfortunately, that is quite the obstacle you face there. Did you notice how the question I linked to had multiple versions of the video in different formats? That's because different platforms support different types of video files. Chances are having the formats listed in that question would allow your video to play on most mobile devices. But that means you have to use a video converter to create the different video files. – EPB Sep 10 '13 at 06:47
  • http://camendesign.com/code/video_for_everybody This website may be able to help. It's video plays on my phone at least. – EPB Sep 10 '13 at 06:51