1

I am trying to stream mp4 video via PHP. My application loads video from where it is stored in blocks and serves the appropriate parts. Uses these headers:

header("Content-Type: $contenttype");
header("Content-Length: $filesize");
header('Accept-Ranges: bytes');

It can also serve partial content when requested using the following additional headers and outputing the correct bytes:

header('HTTP/1.1 206 Partial Content');
header("Content-Range: bytes $start-$end/$filesize");

Streaming works great in Chrome and via VLC, however will not work on iPad. The test mp4 file is confirmed working on ipad.

Anybody have any luck with this? Any advice would be greatly appreciated!

tenth_man
  • 11
  • 2
  • Check out the script at http://stackoverflow.com/questions/5924061/using-php-to-output-an-mp4-video and what you have to take care of at http://stackoverflow.com/questions/24042894/php-ipad-does-not-play-mp4-videos-delivered-by-php-but-if-accessed-directly-it – Avatar Jun 07 '14 at 15:32

2 Answers2

1

Happened to see this after years, I'll leave my answer anyways.

Since Apple Inc. uses H.264 encoding as default for videos, if you use codecs other than H.264 you might find your video playing smoothly on native apps, but not in browser like Safari.

In this case you likely should re-encode your video using ffmepg before streaming through php code. Your PHP code looks good to me.

Remember to add --faststart flag to move the fastmoov to the beginning of your video so it starts playing at once.

Jason
  • 64
  • 1
  • 3
0

Yes, its easy to do. No need to set those headers manually. Let the server do it automatically.

Heres a working script -

ob_start();

if( isset($_SERVER['HTTP_RANGE']) )
      $opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE']; 

$opts['http']['method']= "HEAD"; 
$conh=stream_context_create($opts); 
$opts['http']['method']= "GET";
$cong= stream_context_create($opts);
$out[]= file_get_contents($real_file_location_path_or_url,false,$conh); 
$out[]= $http_response_header; 
ob_end_clean(); 
array_map("header",$http_response_header); 
readfile($real_file_location_path_or_url,false,$cong); 
Andy
  • 49,085
  • 60
  • 166
  • 233
Tech Consultant
  • 374
  • 1
  • 7