PHP: iPad does not play MP4 videos delivered by PHP, but if accessed directly it does

前端 未结 3 1727
花落未央
花落未央 2020-11-30 10:31

I am trying to find a solution for this problem for some days already, I tried all advices I could find here on stackoverflow and other platforms. And still, there is no sol

3条回答
  •  广开言路
    2020-11-30 11:02

    Wow, that was tough!


    1. First major Problem

    It turned out to be no encoding problem but a problem with the mp4 container header set during the video conversion process - iPad has obviously a problem with MP4 videos that are prepared for progressive streaming.

    First I discovered that in a conversation here. After converting a video I always used the tool MP4 Fast Start to prepare the video file for progressive stream. This was necessary to stream the video file to the Flash Player in pieces (progressively), so it did not load the entire file (and the user had to wait).

    With Handbrake there is a similar setting, that is called Web Optimized. It does the same:

    Web Optimized
    Also known as "Fast Start"
    This places the container header at the start of the file, optimizing it for streaming across the web.
    

    If you enable this and convert your video, the iPad will not play the video file! Instead you get the error "The operation could not be completed".

    ipad strikedthrough play button

    Check out and test it yourself: video test resources.


    2. Second Problem

    In production environment I always used PHP to check the referer. As I found out, the iPad does not send the referer information. This also prevents the streaming and you will also see the cannot-play-symbol (striked-through play icon).


    3. Third Problem

    I could not find out why, but the iPad only accepts the video streaming from this script http://ideone.com/NPSlw5

    = $ranges[1]){
                    break;
                }
    
                // Output the data
                echo fread($f, $chunkSize);
    
                // Flush the buffer immediately
                @ob_flush();
                flush();
            }
        }
        else {
            // It's not a range request, output the file anyway
            header('Content-Length: ' . $size);
    
            // Read the file
            @readfile($path);
    
            // and flush the buffer
            @ob_flush();
            flush();
        }
    
    }
    die();
    
    ?>
    


    I hope this information will help others to cope with the problem.


    Update: Three months later in production environment, some of my users still reported playback issues. There seems to be another problem with Safari. I advised them to use Chrome for iPad, this fixed it.



    PS: A couple of days of research and hassle only to play a video file that, by the way, runs on all other devices. This again proves to me that Apple got successful just because of great marketing, not because of great software.

提交回复
热议问题