-1

I'm trying to play a video via php and html5, and hiding or protecting the url.

<?php
   $path = "http://myserver.com/myfiles/greetings.mp4";
   $filePointer = fopen($path, 'r');
   header('Content-Type: video/mp4');
   fpassthru($filePointer);
?>

It works not good, the video loads in the player, but the player not play the video until the video are fully 100% loaded, my video is a 40mb file size.

  • note: header("Content-Length: ".filesize($path)); // this not work correctly too //

This is my html code

<video width="400" controls>
  <source src="myvideo.php" type="video/mp4">
</video>

Sorry if my question is not perfect :(

Comment: In other words im, using fopen(); for transfer the video not direct, for protect or hide my original video source...

katlyn2
  • 3
  • 2
  • Possible duplicate of [Stream video through php server](https://stackoverflow.com/questions/30284117/stream-video-through-php-server) – CBroe Apr 10 '18 at 06:43
  • is your video encoded with the MOOV atom at the front (which allows the browser to start playing sooner) or is it at the end (default) which means it has to wait until it's read everything - see https://stackoverflow.com/questions/48156306/html-5-video-tag-range-header/48160722#48160722 – Offbeatmammal Apr 10 '18 at 07:09
  • My video is encoding in H256 mp4... – katlyn2 Apr 10 '18 at 07:14
  • Do you mean H265/HEVC? Same problem, MOOV atom needs to be at the start not the end of the file – Offbeatmammal Apr 10 '18 at 10:35
  • H256/AVC Is my current mp4 codec format, if this is the problem, what do you recommend?, what format not contains that problem? – katlyn2 Apr 10 '18 at 16:56
  • What is atom format?, atom is like webm? – katlyn2 Apr 10 '18 at 16:59

1 Answers1

0

Please add the preload="auto" on video tag in HTML so the browser should load the entire video when the page loads.

don't use the PHP fopen function to load the video using the direct URL to video tag like this.

<video width="400" controls>
  <source src="http://myserver.com/myfiles/greetings.mp4" type="video/mp4">
</video>

because the file opening takes time. if you want PHP file as well so use the PHP like this

<?php
   echo $path = "http://myserver.com/myfiles/greetings.mp4";
?>
<video width="400" preload="auto" controls>
  <source src="myvideo.php" type="video/mp4">
</video>
Samuel Liew
  • 68,352
  • 105
  • 140
  • 225
abrar
  • 460
  • 4
  • 8
  • Finally im find the solution, the problem are my encoding format, mp4 not allows load buffer via php, webm yes :P – katlyn2 Apr 10 '18 at 17:42