且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过PHP在iPhone / iPad上显示视频

更新时间:2023-01-01 18:49:31

您的问题可能有多种原因。

1)您无法创建正确的视频。尝试使用这样的字符串:

Your problem may be from several reason.
1) You can't create a right video. Try to use a string like this:

c:\utils\ffmpeg\bin\ffmpeg -i MVI_7386.MOV -acodec aac -ac 2 -strict experimental -b:a 160k -s 640x480 -vcodec libx264 -preset slow -profile:v baseline -level 30 -maxrate 10000000 -bufsize 10000000 -b:v 1200k -pix_fmt yuv420p -f mp4 -threads 2 -async 1 -vsync 1 -y video.ipad.mp4

2)我用过这个答案,通过php发送视频的小改动。这是我的video.php文件:

2) I used this answer with small changes for send video via php. Here is my video.php file:

<?php
$path = './video.ipad.mp4';
if (file_exists($path)) {
  $size=filesize($path);
  $fm=@fopen($path,'rb');
  if(!$fm) {
    // You can also redirect here
    header ("HTTP/1.1 404 Not Found");
    die();
  }
  $begin=0;
  $end=$size;
  if(isset($_SERVER['HTTP_RANGE'])) {
    if(preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i',   
      $_SERVER['HTTP_RANGE'],$matches)){
      $begin=intval($matches[1]);
      if(!empty($matches[2])) {
        $end=intval($matches[2]);
      }
    }
  }
  if($begin>0||$end<$size) header('HTTP/1.1 206 Partial Content');
  else header('HTTP/1.1 200 OK');
  header("Content-Type: video/mp4");
  header('Content-Length:'.($end-$begin));
  header("Content-Range: bytes $begin-$end/$size");
  $cur=$begin;
  fseek($fm,$begin,0);
  while(!feof($fm)&&$cur<$end&&(connection_status()==0)) {
    print fread($fm,min(1024*16,$end-$cur));
    $cur+=1024*16;
    usleep(1000);
  }
  die();
}

而且html非常简单:

And the html is very simple:

<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>test</title>
</head>
<body>
    <video controls>
        <source src="./video.php" type="video/mp4">
    </video>
</body>
</html>

你可以看到我做了什么这里

You can see what I done here.

PS对不起视频。 :)我找不到一个。