Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Serving Up a file (mp4, flv, etc.) using PHP


I hope someone can offer some assistance.

I'm trying to serve up a video file (mp4 or flv) from a PHP script. Please not that I do NOT necessarily want to "stream" the file (using pseudo-streaming, etc.)
I've researched the posts in this forum for the last three days and have tried several solutions to no avail. I've made a few notes below and hopefully have described what I'm looking for with enough detail. Please feel free to use the URLs below for testing.

Here's the test scenario:

- We have a "media server" located at http://media1.waywardmediagroup.com
- There is an mp4 file on there. You can access it with http://media1.waywardmediagroup.com/mediatest.mp4
- Using that URL, It can be access from a browser, QuickTime Player, VLC, etc.
- Also, when I use that URL in the JWPlayer (see below), it works just fine
- NOTE: The JWPlayer and the Media are on separate servers

*** THIS WORKS ***
<script type="text/javascript" src="/tools/jwplayer/jwplayer.js"></script>
<div id="mediaspace">Loading the player ...</div>
<script type="text/javascript">
jwplayer("mediaspace").setup({
height: 263,
width: 478,
file: 'http://media1.waywardmediagroup.com/mediatest.mp4',
image: "/tools/preview.jpg",
provider: "video",
skin: "tools/jwskins/fs33aqua/fs33aqua.xml",
players: [
{ type: "flash", src: "/tools/jwplayer/player.swf" },
{ type: "html5" }
]
});
</script>

*** THIS DOES NOT WORK ***
<script type="text/javascript" src="/tools/jwplayer/jwplayer.js"></script>
<div id="mediaspace">Loading the player ...</div>
<script type="text/javascript">
jwplayer("mediaspace").setup({
height: 263,
width: 478,
file: 'http://media1.waywardmediagroup.com/media.php?file=movie.mp4',
image: "/tools/preview.jpg",
provider: "video",
skin: "tools/jwskins/fs33aqua/fs33aqua.xml",
players: [
{ type: "flash", src: "/tools/jwplayer/player.swf" },
{ type: "html5" }
]
});
</script>

NOTES:
- the media.php file is a simple PHP script which serves the file
- "?file=movie.mp4" is a dummy parameter that is being ignored by the php script (for now). However, the JWPlayer sees the ".mp4" and (hopefully) thinks everything is ok
- The HHTP headers returned by media.php are the same as when the file is accessed through it's URL (http://media1.waywardmediagroup.com/mediatest.mp4)
- Please note that I am NOT attempting to do pseudo-streaming hereI just want to deliver the contents of the file in the same manner as when it is accessed directly
- Also, you can play the video in quicktime and vlc using the php url (http://media1.waywardmediagroup.com/media.php)


*** THE PHP SCRIPT (media.php) ***
<?php
// Hard-Coded for the test
$file = 'mediatest.mp4';
if (file_exists($file))
{
header('Last-Modified: Thu, 23 Sep 2010 02:00:02 GMT');
header('ETag: "c0101-309f8-490e39ebcec80"');
header('Accept-Ranges: bytes');
header('Content-Length: ' . filesize($file));
header('Connection: close');
header('Content-Type: video/mp4');
header('X-Pad: avoid browser bug');
ob_clean();
flush();
readfile($file);
exit;
}
?>

*** HTTP Headers from accessing the file directly (http://media1.waywardmediagroup.com/mediatest.mp4) ***
Status: HTTP/1.1 200 OK
Date: Fri, 04 Feb 2011 17:51:36 GMT
Server: Apache/2.2.15 (Fedora)
Last-Modified: Thu, 23 Sep 2010 02:00:02 GMT
ETag: "c0101-309f8-490e39ebcec80"
Accept-Ranges: bytes
Content-Length: 199160
Connection: close
Content-Type: video/mp4
X-Pad: avoid browser bug

*** HTTP Headers from accessing the file through the php script (http://media1.waywardmediagroup.com/media.php) ***
Status: HTTP/1.1 200 OK
Date: Fri, 04 Feb 2011 17:53:46 GMT
Server: Apache/2.2.15 (Fedora)
X-Powered-By: PHP/5.3.3
Last-Modified: Thu, 23 Sep 2010 02:00:02 GMT
ETag: "c0101-309f8-490e39ebcec80"
Accept-Ranges: bytes
Content-Length: 199160
Connection: close
X-Pad: avoid browser bug
Content-Type: video/mp4



23 Community Answers

JW Player

User  
1 rated :

From what I have seen on this board and else where, try using encodeURI() to encode your URI. I think the ? in string is causing the issue.

Ethan Feldman

JW Player Support Agent  
0 rated :

If you set the provider flashvar to video, and url encode the string, it should work.

JW Player

User  
0 rated :

Hi Ethan,

Thought I'd use this thread since it is somewhat about quasi streaming.

With your help I've been using the xmoov.php method to acomplish what I want using FLV files.

After I render the file to FLV then I use the FLV MetaData Injector from the Manitu Group that you recommended so I can jump directly to a start point in the video. It workd great. Thanks to you coaching. Here is a link to a sample of what I do ...
http://www.rinewmedia.com/jtownrecord/Council-2011/tc.1.18.11.Flash.htm The source is not blocked so you can check out how we have things setup.

Now to the next quest... what I'm wanting to do is have the same thing with a mp4 file so my clips will also play on the IPAD if someone should have one.

I've used Handbrake to make the mp4 file but can't get the feature that allows me to jump to start points to work with them.

Don't know if the metadata is messed up on conversion or if the Xmoov.php only works with flv files. If so do you have any ideas how I can reproduce what I have now with mp4 files?

That would be great because I think Handbrake allows me to compress the file better than the .flv files that I'm using now and it will allow me to run on the IPAD with the new Player version 5.4.

Thanks

JW Player

User  
0 rated :

Sorry a line above should say "It works Great" not it "workd" just a typo.

Ethan Feldman

JW Player Support Agent  
0 rated :

@Sav – HTML5 does not support pseudo streaming like this. The basic <video> tag only support progressive download. Because of this limitation, this is not possible.

More information – http://www.longtailvideo.com/support/blog/15095/jw-player-53-html5-and-you

JW Player

User  
0 rated :

Bummer. Oh well maybe Apple will give in and allow Flash... but I won't hold my breath. Thanks pal. (Video pun intended)

Ethan Feldman

JW Player Support Agent  
0 rated :

I agree, it would make things easier, but like you, I am not holding my breath, either ;)

JW Player

User  
0 rated :

Not sure if this is a similar problem as above. I'm trying to play a file from our hosting provider and the flash version works fine, the HTML5 version gives the following error:

The video could not be loaded, either because the server or network failed or because the format is not supported: http://wambase.wamnet.com/cgi-bin/cs/mvsrch_front?process_control=fetch_rep&Asset_Key=VDD000902125&rep_type=Preview&session_id=ses02151111638231648.id

This is simple proof of concept, my html is below:

<div id="container">Loading the player ...</div>
<script type="text/javascript">
jwplayer("container").setup({
provider: "video",
file:"http://wambase.wamnet.com/cgi-bin/cs/mvsrch_front?process_control=fetch_rep&Asset_Key=VDD000902125&rep_type=Preview&session_id=ses02151111638231648.id",
players: [
{ type: "html5" },
{ type: "flash", src: "/jwplayer/player.swf" }

]
});
</script>

Any help is appreciated.

Ethan Feldman

JW Player Support Agent  
0 rated :

Can you provide a link?

JW Player

User  
0 rated :

This link forces flash:

http://genprodweb01.jwt.com/jwplayer/test1.html

This link forces HTML5:

http://genprodweb01.jwt.com/jwplayer/test2.html

Ethan Feldman

JW Player Support Agent  
0 rated :

I can’t get the MP4 to play in Flash, how did you encode it?

JW Player

User  
0 rated :

Should be h.264, but like I said, the files are at a hosting provider.

I've tested the flash on IE/Firefox (PC) and Firefox/Safari (MAC) and it plays fine for me.

Thanks for your help.

Ethan Feldman

JW Player Support Agent  
0 rated :

Okay, it is working.

Since the file is H.264, this file is only going to work on certain browsers in HTML5 mode. Firefox does not support H.264 files in HTML5 mode, which is why you get that error.

JW Player

User  
0 rated :

Okay, that makes sense. I was actually more concerned about the links on iPad.

Ethan Feldman

JW Player Support Agent  
0 rated :

Does it work on the iPad? Please note, Apple devices are very picky when it comes to encoding.

JW Player

User  
0 rated :

I've got it to work using another open source HTML5 player, but I'd rather stick with this one.

When I load the page on the iPad, I simply get an all black box, no play image appears on the player.

Ethan Feldman

JW Player Support Agent  
0 rated :

If you directly link to the mp4 file instead of doing the php redirect, does it work?

JW Player

User  
0 rated :

If I download the file and access it directly, it does work on the iPad. Unfortunately, we can't access the files directly at our hosting provider.

This is the link to the file:

http://wambase.wamnet.com/cgi-bin/cs/mvsrch_front?process_control=fetch_rep&Asset_Key=VDD000902125&rep_type=Preview&session_id=ses02151111908244406.id

This is a test linking to the downloaded file:

genprodweb01.jwt.com/jwplayer/test3.html

Ethan Feldman

JW Player Support Agent  
1 rated :

Works for me on our office iPad! :)

JW Player

User  
0 rated :

Yep, test3.html works great because the file is downloaded to the server. test2.html is the problem child with the file being served up from our provider.

Ethan Feldman

JW Player Support Agent  
1 rated :

Chances are, the php re-direct is not supported in HTML5 mode.

Can you try the version of jwplayer.js on trunk?

http://developer.longtailvideo.com/player/trunk/fl5/js/bin-debug/jwplayer.js

JW Player

User  
0 rated :

jackpot!

Looks like this version of jwplayer did the trick! Thank you for all your help and I will let you know if I have any further issues.

Ethan Feldman

JW Player Support Agent  
0 rated :

Great! Np!

This question has received the maximum number of answers.