Skip to content Skip to sidebar Skip to footer

Streaming An Mp4 Through A Php File Progressively

I'm working on a more secure streaming method for our video player. Because each file requires special token authentication and also only allows each token to be loaded once, I'm r

Solution 1:

In addition to what dlopez said, I recommend to use 3rd-party solution for progressive download with seeking capabilities (AKA pseudo-streaming). You may take a look at the PD solutions listed in Wikipedia: https://en.wikipedia.org/wiki/Progressive_download

Most of them can also prevent video hotlinking protection as well.

Solution 2:

I think that you have a conceptual failure. You are treating the mp4 file like if it were a "raw data file". I try to explain myself.

Imagine that you have a text file, and you want to get the chars from position X. You can open the file, point the cursor to the correct position and then read byte by byte your text. This will work fine.

But now image that you want to do the same but with a text processor file. Would you expect the same results? No, because you have a lot of metadata in the file that prevents you from doing that.

Your problem is basically the same. You need to take in consideration the format of the file, managing the file with libraries designed for it, or doing by yourself.

The other option will be to work with raw data files, but in the case of video files, these are going to be really big files.

I hope that I helped you.

Solution 3:

I ran into a similar problem. Using stream_get_content($fp, $start) instead of fseek fixed the issue. I was able to get the video to stream fine on all browsers, and seeking (or skipping) throughout the video worked without a problem.

Solution 4:

Fully Functional Code

$file = "z.mp4";
$length= filesize($file);
$offset = 0;
$f = fopen($file, 'r');
stream_get_contents($f, $offset);
$pos = 0;
while($pos < $length){
     $chunk = min($length-$pos, 1024*8);
     echo fread($f, $chunk);
     flush();
     ob_flush();
     $pos += $chunk;
}

Solution 5:

You can't use fseek(5654) if you are using file path with http://example.com...... You should use c:/file/abc.mp4 instead. It may solve your problem...

Post a Comment for "Streaming An Mp4 Through A Php File Progressively"