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

How to do PHP streaming.


First of all, this is my first post here. :d

I've been trying to get a fake php file to stream .flv for sometime now. All the rest of the post make it sound so easy, but why am I have such trouble?

I embed the player like so with the embed tag and send the flashvars that I'm suppose to, streamscript=path/to/mystreamer.php, so maybe it's my php script.

$file = 'director/html/blabla/'.$_GET["file"];

$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;

header("Content-Type: video/x-flv");
header('Content-Length: ' . filesize($file));


if($pos > 0) {
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}


$fh = fopen($file,"rb");
fseek($fh, $pos);
fpassthru($fh);
fclose($fh);

As you can see I pretty much copied the stream.php file provided by JeroenW's example. I don't see what I'm missing. But one thing I would like to know is how does GET['file'] know which file I'm trying to access? What's the value of that argument? Should I also send the 'file=url' flashvar aswell as the 'streamscript' flashvar?

I really don't know what I'm doing as I'm new to flash video and what not. So I'm pretty stumped as to what to do... What to do? :s

61 Community Answers

JW Player

User  
0 rated :

Sam,

file and pos are generated by some voodoo magic.

file from the flashvar file=myvideofile.flv or whatever...

pos in bytes is generated by the player which looks at the keyframe metadata array in the FLV file and finds the nearest keyframe corresponding to the position of the slider.

So a streamscript scrubbing request looks like this: *stream.php?file=myvideofile.flv&pos=123456*

Usually people have trouble with stream.php because of the $file variable.

That path is a *filesystem path*, not a webserver path. As such it has to start with the *filesystem root* "/", either real or virtual.

You are starting with a relative path from who knows where.

Add these lines just below the $file variable and call stream.php from your browser so you can see what filesystem path you are requesting the video file from, then adjust the $file path accordingly.
bc.. print "<pre>\n";
print "File Path: " . $file . "\n";
print "</pre>\n";
exit;


JW Player

User  
0 rated :

I see. But I don't think that that's the problem. My server path is not what I said it was, I just didn't feel safe giving it out. The path goes something like this: '/home/content/*/*/*/**************/html'.$_GET['file'];

So it's not the problem. The video player just appears to load 0% and doesn't play anything.

Here's my full PHP script:

bc.. <?php
session_start();

if ($_SESSION['logged'] != true)
{
?>
<script type="text/javascript">
location.href = "*****blocked*****";
</script>
<?php
exit;
}
elseif (($_SESSION['logged'] == true) || (isset($_SESSION['manager_username']) && isset($_SESSION['manager_password'])))
{
$file = '*****Blocked*****'.$_GET["file"];

$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;

header("Content-Type: video/x-flv");
header('Content-Length: ' . filesize($file));


if($pos > 0) {
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}


$fh = fopen($file,"rb");
fseek($fh, $pos);
fpassthru($fh);
fclose($fh);
}
?>


My embed code:

bc.. <embed
width="640"
height="380"
flashvars="file=chart-room/videos/<?php echo $filename; ?>.flv&streamscript=http://*****blocked*****.com/video.php&backcolor=0x333333&frontcolor=0xBBCCDD&lightcolor=0xCCDDEE&autostart=true&type=flv"
allowfullscreen="true"
quality="high"
name="video"
id="video"
style=""
src="http://*****blocked*****.com/flvplayer.swf"
type="application/x-shockwave-flash"/>


I don't see what could be going wrong here...

JW Player

User  
0 rated :

OK, now you have revealed the real problem: *session_start();*

See this thread: [url=http://www.jeroenwijering.com/?thread=6393#msg29916]AJAX problem while video is playing[/url]

Also, Internet Explorer has been known to choke on content-length, so maybe you shouldn't send it.

And depending on the size of your video file, it may be better to send it in chunks so it will start playing immediately and not hit PHP's memory limit. Default is 8MB, you may have set it higher in php.ini. See the other stream.php postings on these forums. 8192 or 16384 byte chunks work better.

JW Player

User  
0 rated :

I got rid of the session statements entirely and it still does not work.

bc.. $file = 'home/content/*/*/*/**************/html/'.$_GET["file"];

$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;

header("Content-Type: video/x-flv");
header('Content-Length: ' . filesize($file));


if($pos > 0) {
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}


$fh = fopen($file,"rb");
fseek($fh, $pos);
fpassthru($fh);
fclose($fh);



So I guess it's not the sessions entirely.

JW Player

User  
0 rated :

Sam,

Have you checked your server logs to see what kind of request is being received by your server? That might help a lot in determining where the process is failing.

And when you printed the $file variable, was it the correct path to your video file?

Maybe the missing root "/" before home/...?

Possibly your video file is larger than your server's php memory limit.

The code you are using now requires that the entire video file be read into memory before it is served. This delays the start of the video on the user's computer and limits file size to whatever has been allocated to php.

Better file streaming code:
bc.. $fh = fopen($file,"rb");

fseek($fh, $pos);

while (!feof($fh))
{
print(fread($fh, 8192));
}

fclose($fh);


or try 16384 if you have a fat pipe.

And flashvars="streamscript=URL-to-streamer.php&file=video.flv"

That's all I can think of. :)

JW Player

User  
0 rated :

Okay first of all, It's working now. It was the '/' before 'home/' *smack*!

And I'm not able to see my server logs, I don't think, I'm on a shared hosting service.

Also when you mean 'If you have a fat pipe' what do you mean? I mean, me as in the client me or the server me? If the client me, then I would want people with dial-up to be able to view my videos, they don't have a fat pipe.

Also when I click on the track it does move to a new position. Why wouldn't that be working.

bc.. $file = '/home/content/****/html/'.$_GET["file"];

$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;

header("Content-Type: video/x-flv");
header('Content-Length: ' . filesize($file));


if($pos > 0) {
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}


$fh = fopen($file,"rb");
fseek($fh, $pos);
while (!feof($fh))
{
print(fread($fh, 8192));
}
fclose($fh);



I even tried it without starting any sessions.

JW Player

User  
0 rated :

Sam,

Yes, the "fat"/"skinny" pipe is all the way to the client, so dial-up is "skinny". Probably best to use 8192 bytes per chunk if you expect a substantial portion of your users to be on dial-up.

This part of your post, I don't understand.
bc.. Also when I click on the track it does move to a new position. Why wouldn't that be working.


Do you still have some problem? Is scrubbing working, or are you still having problems with re-positioning?

Scrubbing only makes requests to the server for the portion of the file that has not been downloaded yet. That is what I mean by, "scrubbing ahead of the download". Once the video file has been downloaded, scrubbing takes place locally from the browser's cache and/or memory.

JW Player

User  
0 rated :

Umm. What's scrubbing? But yeah I do have some problem, sadly... :(

When I click on the bar at the bottom of the video (That is what I meant when I said "track") it doesn't move to a new frame.

But please explain in detail on what scrubbing is.

JW Player

User  
0 rated :

Scrubbing is moving the slider to select a new position in the video file.

When using fake or real streaming, you can scrub ahead of the already downloaded point and request a partial file starting at some point into the video.

If the video is only partially downloaded, you can scrub within the downloaded portion or within the not-yet-downloaded position.

When you scrub ahead of the already downloaded point, the player makes a request to the server to start sending a partial file starting at the nearest keyframe.

In order to be able to scrub, either locally on a downloaded file, or remotely on the server, the media file must have keyframes that were created during the initial encoding of the video file and the video file must have an array of metadata containing information about those keyframes (time and position in bytes). The player reads that metadata when the file starts downloading, then it can use that metadata to request a partial file beginning on a keyframe.

The array of keyframe metadata can be created and injected into the video file by several available tools, such as FLVMDI or flvtool2.

If you can't scrub, your video file doesn't have the keyframe metadata array and/or keyframes.

There is a tool, FLVCheck, available at Adobe Labs that will check the metadata array in a video file.

JW Player

User  
0 rated :

My flv has the keyframe metadata I'm sure as it was made with Camtasia Studios, it's my fake php file that doesn't. How do I inject the metadata into the php file?

JW Player

User  
0 rated :

Sam,

I wouldn't be so sure about the metadata.

_If you can't scrub, it's because your video file doesn't have keyframes and/or metadata._

The metadata array only resides in the FLV video file. You don't need to inject anything into the php streamer.

JW Player

User  
0 rated :

I see, thanks for clearing that up. So it's my flv then. My php streamer is fine. I would have thought that Camtasia Studios would have injected keyframe metadata in the flv file...

Do you know if you can inject keyframe metadata with camtasia studios? Why is that if I play the flv directly I don't have this problem and only when I use a fake streamer do I have the problem?

JW Player

User  
0 rated :

Sam,

What program are you using to play the FLV directly?

The best way to find out if the video file has keyframes and metadata is to use the Adobe Labs FLVCheck.

You can inject metadata with FLVMDI.

If you use this command line, you also get a metadata XML file that you can examine with any text editor to see the spacing of the keyframes and other data about the file.
*FLVMDI /x /k video.flv*
Then you will know for sure if the video file is OK or not and can move on to troubleshooting other things if you still can't scrub from the JW Player.

JW Player

User  
0 rated :

It can't be my flv because when I play the flv directly (file=path/to/file.flv) it works fine, on the other hand when I stream it through a fake php stream (file=path/to/file.flv&streamscript=path/to/script.php) I'm not able to scrub (I'm using the word scrub, fancy that :D).

JW Player

User  
0 rated :

Well, I guess you could put some logging in the streamer, do some scrubbing, and then look at the log to see what is happening. Put this code just above the two header(...) lines.
bc.. $filename = 'streamscript.log';

// check to see if $filename exists, if not, create it.
touch($filename) or die("Unable to create: " . $filename);

// log file format
$datetime = "[" . date('d/M/Y:h:i:s O') . "]";
$somecontent = $_SERVER[REMOTE_ADDR] . " " . $datetime . " " . $file . " " . $pos . "\n";

// open $filename for append.
$handle = fopen($filename, 'a') or die("Could not open file: " . $filename . "\n");

// Write $somecontent to the open file.
fwrite($handle, $somecontent) or die("Could not write to file: " . $filename . "\n");

fclose($handle);


Here's what it looks like when I scrub a good video file.
192.168.0.1 [31/Jul/2007:09:25:27 -0700] E:/My Movies/Ferrari 275GTB.flv 0
192.168.0.1 [31/Jul/2007:09:25:41 -0700] E:/My Movies/Ferrari 275GTB.flv 781223
192.168.0.1 [31/Jul/2007:09:25:46 -0700] E:/My Movies/Ferrari 275GTB.flv 15241963
192.168.0.1 [31/Jul/2007:09:25:52 -0700] E:/My Movies/Ferrari 275GTB.flv 6714360
192.168.0.1 [31/Jul/2007:09:25:56 -0700] E:/My Movies/Ferrari 275GTB.flv 1814747
192.168.0.1 [31/Jul/2007:09:25:58 -0700] E:/My Movies/Ferrari 275GTB.flv 15826926
192.168.0.1 [31/Jul/2007:09:26:01 -0700] E:/My Movies/Ferrari 275GTB.flv 10536202
192.168.0.1 [31/Jul/2007:09:26:03 -0700] E:/My Movies/Ferrari 275GTB.flv 5941497
192.168.0.1 [31/Jul/2007:09:26:06 -0700] E:/My Movies/Ferrari 275GTB.flv 2058523
192.168.0.1 [31/Jul/2007:09:26:08 -0700] E:/My Movies/Ferrari 275GTB.flv 14049824
192.168.0.1 [31/Jul/2007:09:26:11 -0700] E:/My Movies/Ferrari 275GTB.flv 8767542

There's the initial load at position 0, then subsequent requests as I scrub.

JW Player

User  
0 rated :

I did the log file test. My results were only the initial load at position 0.

While I was doing this test I noticed that I can only scrub when the movie is paused, hopefully that information would be of some help.

JW Player

User  
0 rated :

Sam,

OK, if you are getting the initial request at position 0, then we know there is only one thing that can be wrong.

*The video doesn't have keyframes and/or a metadata array.*

Make sure that you have the latest v3.99 player dated 08-01-07.

Download the file that I used above and test it. I'm sure it's OK. You can see how it scrubbed OK in the log that I posted.

[url=http://willswonders.myip.org:8085/downloads/Ferrari 275GTB.flv]File[/url]

Post back with your results.

JW Player

User  
0 rated :

Well, the flv you had me use works. Though, I don't understand why my videos would work without the fake php streaming.

Another weird thing is: I deleted the .log file that I had on my server, then running the flv you had my download didn't create a log file... Hmm...

JW Player

User  
0 rated :

This line, of the code that I posted above, should create a new log file if it doesn't already exist. Do you have it in your PHP stream script?
bc.. // check to see if $filename exists, if not, create it.
touch($filename) or die("Unable to create: " . $filename);



For your videos, make a batch file and re-encode them.

Here's what I gave Lee who was having a similar problem in this thread: [url=http://www.jeroenwijering.com/?thread=6617]Spinner at ending still a problem[/url]

*re-encode.bat*
bc.. ffmpeg-9757.exe -sameq -i video1.flv video1_new.flv
flvmdi.exe /x /k video1_new.flv
ffmpeg-9757.exe -sameq -i video2.flv video2_new.flv
flvmdi.exe /x /k video2_new.flv
ffmpeg-9757.exe -sameq -i video3.flv video3_new.flv
flvmdi.exe /x /k video3_new.flv
...
ffmpeg-9757.exe -sameq -i video100.flv video100_new.flv
flvmdi.exe /x /k video100_new.flv



Latest ffmpeg Windows binaries are here: [url=http://ffdshow.faireal.net/mirror/ffmpeg/]ffmpeg Windows binaries[/url]

JW Player

User  
0 rated :

Yeah I got the full on script.

bc.. $filename = '/home/content/****/html/logscript.log';

// check to see if $filename exists, if not, create it.
touch($filename) or die("Unable to create: " . $filename);

// log file format
$datetime = "[" . date('d/M/Y:h:i:s O') . "]";
$somecontent = $_SERVER[REMOTE_ADDR] . " " . $datetime . " " . $file . " " . $pos . "\n";

// open $filename for append.
$handle = fopen($filename, 'a') or die("Could not open file: " . $filename . "\n");

// Write $somecontent to the open file.
fwrite($handle, $somecontent) or die("Could not write to file: " . $filename . "\n");

fclose($handle);


As for my videos, I don't know how to make batch file and what not, I'm not really a desktop guy playing around with the command line and what not (although I have played with the command, not much though). I'm not really familiar with this stuff. Could you point me in the right direction to learn?

JW Player

User  
0 rated :

When the movie is paused and i click the bar to a new position, the player displays the new picture frame (next position) but when unpaused i'm back to original position before pausing.. do you know how can that be fixed ?

JW Player

User  
0 rated :

To re-encode your video files:

1) Download ffmpeg and unzip it to the directory where the video files are. I like to add the version to the filename so I can keep track of upgrades.

2) Download flvmdi and unzip it to the directory where the video files are.

2) Start Wordpad and create a new text document.

3) Copy and Paste the first two lines of the batch file code from my post.

4) Edit the first line to match the version of ffmpeg that you have and edit the video file name (twice) to match the first of your video files.

5) Edit the second line to match the first of your video files.

6) Save the file as "re-encode.bat" in the directory where your video files are. Be sure to save it as text.

7) In Windows Explorer, navigate to the directory where your video files are. Double-click on "re-encode.bat" It should run and re-encode the video file. You should end up with two new files "videofilename_new.flv" and "videofilename_new.xml" (The filename will be whatever you entered in the re-encode.bat file.)

8) If that worked, copy and paste the first two lines of "re-encode.bat" as many times as you need and edit the video file names. Save as text and double-click on it to re-encode all of your video files.

If this doesn't work and you get stuck, post your re-encode.bat file and I'll have a look at it.

JW Player

User  
0 rated :

@Sorin,

Your video file might not have many keyframes, so when you go to play it after scrubbing, it jumps to the nearest keyframe which happens to be the place where you paused.

Or, possibly, it doesn't have any keyframes or metadata.

Can you post a link to the video file so I can check it?

JW Player

User  
0 rated :

I don't think that I would have to go through all that trouble really. You see, in Camtasia Studios I was able to re-export the project as an flv with more keyframes. This works.

But the one other thing that I would like to know is: why when I fake stream (that is fake a flv with php file) the player states that it loaded a hundred percent but when I attempt to scrub to the end I'm not able to? I'm only allowed to scrub to an area that is downloaded, which is fine, it's just that the players shows that the downloaded area is 100% not, say, 25%.

I hope I'm making my self clear on this one. In other words the progress bar says I've downloaded 100% when I haven't.

JW Player

User  
0 rated :

The whole point of fake streaming is to be able to scrub ( make a request for a portion of a file and start playing it ) past the downloaded point. Once the file is downloaded, you might as well scrub locally and save the bandwidth ( which fake streaming doesn't do ).

If you can't scrub past the downloaded point, your fake streaming still isn't working either because the video file is bad or the streamer is bad.

Timeline:
0%|========25%===========40%---------------------75%----------|100%

Lets say the video file is 10MB and you have already downloaded 40% which = 4MB already downloaded.

Scrubbing to 75% should result in a request for the file with a "pos=7548293" (the exact number will depend on the location of the keyframe).

Scrubbing to 25% should result in a request for the file with a "pos=2529412".

Scrubbing to 40% should result in a request for the file with a "pos=4123382".

Scrubbing to 80% should result in a request for the file with a "pos=8349432".

JW Player

User  
0 rated :

@Sam,

Does Cantasia Studios also inject the keyframe metadata array, or do you have to use flvmdi to do that?

If you are using flvmdi, also use the /x switch so you get a metadata file in XML format that you can look at (with any text editor) to see if you have keyframes and time and byte position data.

JW Player

User  
0 rated :

http://www.funcafe.ro/test_video

i injected the movie with flvmdi /k /x /l the result can be seen here - http://www.funcafe.ro/test_video/376.xml

thanks for your answer


PS: i also can't figure out why when playing the movie without streaming, the quality is good, when streaming it gets pixelated (that can be seen better in fullscreen, hit the button). some times this appears because of pausing/unpausing the movie. any ideas ? 8)

JW Player

User  
0 rated :

bc.. i injected the movie with flvmdi /k /x /l the result can be seen here - http://www.funcafe.ro/test_video/376.xml



That's a lot of keyframes. I usually make one every 3-5 seconds. Every keyframe makes the video file MUCH larger. I don't see any point in being able to scrub to less than 3-5 seconds. Also degrades the quality of the video (as I'll explain below) and makes the user experience poor because the video doesn't load and play in that "magical 5-second window" when you have his/her attention.

As for the pixelation; your video looked good to me. No video file that you can transmit on copper will ever look good fullscreen. Jeroen explained in a post how the automatic smoothing ( which takes CPU cycles - _AND FULLSCREEN IS A REAL CPU HOG ALSO_ ) will back off if it can't keep up with the framerate. So unless you expect your users to have 8-core CPUs with high-end graphics cards, don't expect too much quality in fullscreen. I really can't see why anyone would EVER think they could blow up a 320x240 video to 1280x1024 and expect anything but a pixelated mess.

Anyway, your scrubbing is working! That's something to cheer about. :)

JW Player

User  
0 rated :

Interesting post while I was gone.

But I realize that I never wanted to be able to scrub in the first place. I only wanted to fake stream the file with php so as to be able to authenticate if the user is logged in or not. I never wanted to the user to be able to scrub ahead of the already downloaded part of the video. This is nice and all but I don't think that it would be necessary for the users I intend to attract. I think the standard progression download method would be fine.

How do I change this? Would this require me to change something in my streamscript?

JW Player

User  
0 rated :

bc.. But I realize that I never wanted to be able to scrub in the first place.


Just comment out the $pos variable in the PHP file and scrubbing will be broken, real good.

Or set $pos = 0;

Your call.

If you don't want your users to scrub very much in the downloaded video, use far less keyframes when you encode. That will have the added benefit of making the video file smaller and the download faster. OR, increase the size of the video to 640x480 for better fullscreen. With few keyframes, the size shouldn't be to large.

JW Player

User  
0 rated :

I commented out this line:

//$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;

and added this line:

$pos = 0;

This doesn't change the fact that the progress bar loads 100%.

Here, let me explain it again only a bit different.

0%=====================100%

this is what the progress looks like within the first few seconds.

0%====25%_______________100%

this is what I would like the progress bar to look like.

You see I can't scrub beyond the already downloaded video. Let say the already downloaded video is 25% of the whole duration. My player still displays 100% downloaded even though in reality it's 25%.

You can see how this is a problem for my users. They would think that the video has downloaded 100%, when it has only downloaded 25%.

How could I get the player to display the right percent of the duration of the video that's being downloaded?

JW Player

User  
0 rated :

Well, the video file that you downloaded has the filesize in it, so the player should be able to calculate the % downloaded. Are you sure that you are using the latest player dated 08-01-07? My progress bar works correctly, showing the amount downloaded in light gray and the amount played in black.

JW Player

User  
0 rated :

i understand what you said.. and the problem for that movie is solved.. i have a larger movie 32 minutes where my first problem still stands. here are some screenshots:
http://www.funcafe.ro/test_video/_scr/scr001.jpg
http://www.funcafe.ro/test_video/_scr/scr002.jpg
http://www.funcafe.ro/test_video/_scr/scr003.jpg

if you need, i cand upload the video, it has about 130mb.. or the xml ?

JW Player

User  
0 rated :

very awkward, if i load the movie through swfobject the sreaming while in pause works just fine after unpause. if i load the flv the old style way, always returns to previous position.

is that possible ? is there an explanation.. 8)

JW Player

User  
0 rated :

@Sorin - as Will already mentions - it might be worthwhile to download the player again, theres been some bugs that JeroenW has quickly fixed outside of the ususal update cycle without changing version number, so it still v.3.99!

JW Player

User  
0 rated :

i had the latest version (checked already) but as i said in my last message, after loading the player through swfobject, it works fine.

JW Player

User  
0 rated :

@Sorin - glad you have it working! :)

it must be some strange coincidence then, you tell about in the latest posting (happens all the time).
the embedding method should not be able to influence the inner functionality of the players, both the old ufo and swfobject are just different methods of writing the object/embed code, and they mainly differ in how they are handled and in sensetivity to other scripts, but shouldnt influence the players them selves as such...

JW Player

User  
0 rated :

@Will

I'm sure I have the latest player because when I right click the player it says 3.99 which is the most recent update right?

JW Player

User  
0 rated :

@Sam - actually there has been three versions of the v.3.99 (one was only up for some hours) there was this bug that JeroenW fixed outside of the regular update cycle -
i think the newest: is 1st of august 14.57hr
so it might be worthwhile to download again just to make absolutely and completely sure ;)

JW Player

User  
0 rated :

Ooooh. Okay, so I downloaded it again and uploaded it to my website. It didn't change. :( It still says 100% loaded when it hasn't.

JW Player

User  
0 rated :

@Sam

did you notice this comment from Will a few postings up?
_"My progress bar works correctly, showing the amount downloaded in light gray and the amount played in black."_

so is your progressbar actually working and you just whished it worked differently - or is something else wrong?

JW Player

User  
0 rated :

@andersen

The progress bar is working just not the way I want it to. The progress bar does not show the amount downloaded, it always displays as 100% not 25% when 25% is actually the amount downloaded.

Yes it is true that the progress bar works correctly, showing the amount downloaded in light gray and the amount played in black. Only my progress bar displays 100% downloaded when it should be 25%, for example.

JW Player

User  
0 rated :

@sam and andersen,

Recently, I've been looking at a lot of video files from users complaining about the progress bar and/or elapsed/remaining time and/or the video stalling near the end.

*_In every single case, once the video file was properly encoded, the progress bar was correct, the elapsed and remaining time was correct, and the video did not stall at the end._*

Here's the most recent example: [url=http://www.jeroenwijering.com/?thread=6606#msg32471]At end of video the spinner appears forever[/url]

You can download his original video file "34.flv" and try to play it. It always stalls at 3:16. Then play the _"new and improved"_ version from that post. Always plays through... :d

JW Player

User  
0 rated :

So is it that I'm missing metadata? What's metadata? Before I ask how to inject it, is it used only for JW flvplayer? Is it just an XML file? And finely how do inject it?

JW Player

User  
0 rated :

@Sam,

metadata is data about the file. "meta"

The metadata that we're talking about is an array of data about the FLV video file, including size, duration, keyframe position in bytes and seconds, etc.

Every Flash player needs the metadata if you want to be able to scrub videos.

You create and inject the metadata with flvmdi, like this:
bc.. FLVMDI /x /k /l video.flv



Only needs to be done once after you encode the video file.

JW Player

User  
0 rated :

Doesn't Camtasia Studios do all that for me? Why wouldn't Camtasia Studios inject metadata?

If I have to do this to every video, I might as well automate it. Could I do this with php, do you know?

But one thing I don't understand. Why is it that the progress bar works perfectly when I don't use a php streamer? Only when I stream my file through php does the progress bar not work.

Do you understand my issue though?

JW Player

User  
0 rated :

I don't have Camtasia Studios, so I can't answer questions about it.

I do know that when a video file stalls near then end, doesn't display the correct elapsed/remaining time, or doesn't diaplay the progress bar correctly, *_THE VIDEO FILE HAS BEEN INCORRECTLY ENCODED_*.

I know this because every video file that I have tested, that wasn't working correctly, did work correctly after I re-encoded it with ffmpeg or mencoder and injected the metadata with FLVMDI or flvtool2.

JW Player

User  
0 rated :

Sorry for the delay for a response.

So my question now is: could I insert metadata with PHP? Every time I upload a video on my server, have PHP insert metadata then save it to the servers hard disk.

How does youtube insert metadata automatically? And how come I don't have the problem I have when I don't use a fake php streamer?

JW Player

User  
0 rated :

*bc.. <code></code>
*

JW Player

User  
0 rated :

Ummm

JW Player

User  
0 rated :

I've a problem. I use script php to streaming. Before, i inject the metadata with flvmdi. When push the play and i left the flv plays to the final corretcly, but if I click on then progess bar an d play from there, the file dont stop in the end, it thinkink...
Whats its wrong? This is my stream.php: THANKS

$file = $_SERVER["SITE_HTMLROOT"] . './' . basename( $_GET["file"] );
$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;
$tam = filesize($file);
$dif = $tam - $pos;



//Creamos un fichero log
$filename = 'streamscript.log';
touch($filename) or die("Unable to create: " . $filename);
$datetime = "[" . date('d/M/Y:h:i:s O') . "]";
$somecontent = $_SERVER[REMOTE_ADDR] . " fecha " . $datetime . " fichero " . $file . " posicion " . $pos . " tamano ". $tam . " dif " . $dif . "\n";
$handle = fopen($filename, 'a') or die("Could not open file: " . $filename . "\n");
fwrite($handle, $somecontent) or die("Could not write to file: " . $filename . "\n");
fclose($handle);


//Formamos la cabecera del fichero
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Content-Type: video/x-flv");
header('Content-Length: ' . filesize($file));

//Empaquetamos

if($pos > 0)
{
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}

//Abrimos el fichero, y leemos desde pos hasta el final
$fh = fopen($file, "rb");
fseek($fh, $pos);
fpassthru($fh);
fclose($fh);

JW Player

User  
0 rated :

I had a problem with the stream php. The working solution is the content length of the file header. There is my stream.php



$file = $_SERVER["SITE_HTMLROOT"] . './archivos/' . basename( $_GET["file"] );
$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;
$tam = filesize($file);

//Formamos la cabecera del fichero
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Content-Type: video/x-flv");
header("Content-Length: " . (filesize($file) - $pos));

//Empaquetamos

if($pos > 0)
{
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}

//Abrimos el fichero, y leemos desde pos hasta el final

$fh = fopen($file, "rb");
fseek($fh, $pos);
fpassthru($fh);
fclose($fh);

JW Player

User  
0 rated :

i have some prob while doing with PHP streaming, its always telling only 0%

here is my code

$file = 'C:/xampp/htdocs/ref/video.flv';
header("Content-Type: video/x-flv");
header('Content-Length: ' . filesize($file));


$pos = 2346;


if($pos > 0) {
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}


$fh = fopen($file,"rb");
fseek($fh, $pos);
while (!feof($fh))
{
print(fread($fh, 8192));
}
fclose($fh);
---------------------------------------


<embed
width="600"
height="380"
flashvars="file=C:/xampp/htdocs/ref/video.flv&streamscript=http://localhost/ref/streaming.php&backcolor=0x333333&frontcolor=0xBBCCDD&lightcolor=0xCCDDEE&autostart=true&type=flv"
allowfullscreen="true"
quality="high"
name="video"
id="video"
style=""
src="mediaplayer.swf"
type="application/x-shockwave-flash"/>

pls help

JW Player

User  
0 rated :

* 've maked a mysql/php stream but i don't know why don't works with flv.
ex. I call it stream.php?id=12 it gives me a mp3 working in jw player as stream.php?id=12.mp3
ex. I call it stream.php?id=24 it gives me a flv but don' works in jw player as stream.php?id=12.flv or stream.php?id=12&type=flv *


Code is:

<?php
// Make a MySQL Connection
$downloadid = $_GET['id'];
mysql_connect("*********", "*********", "********") or die(mysql_error());
mysql_select_db("*******") or die(mysql_error());

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM download WHERE id='$downloadid'")
or die(mysql_error());
$row = mysql_fetch_array( $result );
$permalink = $row['link'];
$type = $row['extension'];

header("Location: $permalink$type");
?>

I want to stream flv's like mp3 but didn't work.
Can anybody help me? (Sorry for my Romanian English:D)

JW Player

User  
0 rated :

can anybody help me?

JW Player

User  
0 rated :

Thx streamBabie you're cool this script is working:D

JW Player

User  
0 rated :

somebody knows how to load flashvars in:

bc.. ob_start();
header("Expires: Mon, 20 Dec 1980 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

header("Content-Type: application/x-shockwave-flash");

@readfile("../players/1.00/mediaplayer.swf");
ob_end_flush();


JW Player

User  
0 rated :

hi everybody

help me out with this:

<?
header("Content-Type: application/x-shockwave-flash");
@readfile("swfs/test.swf");
?>

it just loads an empty movieplayer with no swf loaded a white page that when you right click on it it has the Macromedia contex menu

when i try to see if readfile is working:
<?
echo readfile('swfs/test.swf');
?>
it just gives out the file binery contents but still don't know why this code doesn work.

I think some thing is wronge with my server settings?

JW Player

User  
0 rated :

Is there a 123 step process for this please? How do we get our videos from the playlist to stream or scrub?

JW Player

User  
0 rated :

Read the tutorial *HTTP Video Streaming* linked from the top of this page.

JW Player

User  
0 rated :

Change:bc.. header("Location: $permalink$type");

to:bc.. print $permalink . $type; exit;

header("Location: " . $permalink . $type);
then call from your browser. If the URI looks good, change to:bc.. //print $permalink . $type; exit;

header("Location: " . $permalink . $type);
and call from the player:bc.. file: encodeURIComponent('stream.php?id=21'),
type: 'flv',
Adjust accordingly if you are not using swfobject v2.0.

This question has received the maximum number of answers.