久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP:iPad 不能播放由 PHP 提供的 MP4 視頻,但如果直

PHP: iPad does not play MP4 videos delivered by PHP, but if accessed directly it does(PHP:iPad 不能播放由 PHP 提供的 MP4 視頻,但如果直接訪問它可以)
本文介紹了PHP:iPad 不能播放由 PHP 提供的 MP4 視頻,但如果直接訪問它可以的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經嘗試為這個問題尋找解決方案好幾天了,我嘗試了所有可以在 stackoverflow 和其他平臺上找到的建議.仍然沒有解決方案.

我正在通過 HTML5 視頻標簽嵌入視頻:

 

我嘗試通過 PHP 提供 MP4 視頻文件,而不是直接鏈接它.直接鏈接mp4文件即可播放文件!

測試:

  1. 視頻文件::

    、.


    **2.第二個問題**

    在生產環境中,我總是使用 PHP 來檢查引用者.正如我發現的,iPad 不會發送推薦人信息.這也會阻止流式傳輸,您還會看到無法播放符號(帶刪除線的播放圖標).


    **3.第三個問題**

    我不知道為什么,但 iPad 只接受來自這個腳本的視頻流http://ideone.com/NPSlw5

    我希望這些信息能幫助其他人解決問題.


    更新:三個月后,在生產環境中,我的一些用戶仍然報告播放問題.Safari 似乎還有另一個問題.我建議他們使用 Chrome for iPad,這就解決了.



    PS:幾天的研究和麻煩只是為了播放一個視頻文件,順便說一下,它可以在所有其他設備上運行.這再次向我證明,Apple 的成功只是因為出色的營銷,而不是因為出色的軟件.

    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 solution.

    I am embedding a video via HTML5 video tag:

     <video poster="thumb.png" controls="controls" preload="none" width="640" height="480">
        <source src="provider.php?secure=12345" type="video/mp4">
     </video>
    

    I try to deliver the MP4 video file by PHP instead of linking it directly. Linking the mp4 file directly works and plays the file!

    Testing:

    1. the video file: https://github.com/q2apro/videotest-ipad/raw/master/video.mp4 (plays on iPad)
    2. the video file loaded by PHP with same headers: https://github.com/q2apro/videotest-ipad/blob/master/test-headers.php (not playing on iPad) - Sourcecode
    3. the video file loaded by PHP with Byte Ranges: https://github.com/q2apro/videotest-ipad/blob/master/test-byterange.php (not playing on iPad) - Sourcecode
    4. the video file loaded by PHP with Byte Ranges (another script): https://github.com/q2apro/videotest-ipad/blob/master/test-byterange-2.php (not playing on iPad, alert "The operation could not be completed") - Sourcecode

    Notes:

    • all links above are directly accessing/playing the video file without embed tag
    • video works on all browsers in Windows (but not in Safari/Chrome on iPad, probably not iPhone either)

    My Setup:

    • testing device: iPad iOS 6 (I don't have a mac, cannot debug)
    • iPad with Safari and Chrome (tried both browsers)
    • my server is shared-hosting from domainfactory
    • tool for debugging: Firefox 29 Web Developer Console / WIN7

    The .htaccess in the test folder sets the MIME type and Accept-Ranges:

    AddType video/mp4 .mp4 
    
    <IfModule mod_headers.c>
       Header set Accept-Ranges "bytes"
    </IfModule>
    


    Even though I created the same header (compare test URLs 1. and 2.), the iPad is not playing the file through the PHP request.

    Instead I always get this strikedthrough play button:

    The headers of 1. (direct mp4 call):

    The headers of 2. The same headers as above, but set up by PHP (mp4 delivered by PHP):

    --

    I have also tried reading the entire video file and sending it to the browser using PHP's fread(), fpassthru() and file_get_contents() but the iPad is always showing the cannot-play-icon.

    --

    My hosted server does not supply Connection keep-alive, could this be a problem? Is the iPad interpreting .php different from .mp4?

    Can somebody help me out of pain? I am totally stuck.



    PS: What I tried to consider:

    • Byte range requests (206 partial content) 01 02 03
    • correct video encoding 04
    • used other encoded videos while testing
    • disabled zlib.output_compression in php scripts



    UPDATE: Debug Console

    I finally got a MAC of a friend, connected the iPad, opened the Debug Console in Safari on the Mac, loaded the page on the iPad and checked the error messages appearing on the Mac (btw, how more complicated could apple force us to develop...). For all test scripts this error appears:

    Failed to load resource: Plug-in handled load
    

    解決方案

    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".

    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

    <?php
    // disable zlib so that progress bar of player shows up correctly
    if(ini_get('zlib.output_compression')) {
        ini_set('zlib.output_compression', 'Off'); 
    }
    
    $folder = '.'; 
    $filename = 'video.mp4';
    $path = $folder.'/'.$filename;
    
    // from: http://licson.net/post/stream-videos-php/
    if (file_exists($path)) {
        // Clears the cache and prevent unwanted output
        ob_clean();
    
        $mime = "video/mp4"; // The MIME type of the file, this should be replaced with your own.
        $size = filesize($path); // The size of the file
    
        // Send the content type header
        header('Content-type: ' . $mime);
    
        // Check if it's a HTTP range request
        if(isset($_SERVER['HTTP_RANGE'])){
            // Parse the range header to get the byte offset
            $ranges = array_map(
                'intval', // Parse the parts into integer
                explode(
                    '-', // The range separator
                    substr($_SERVER['HTTP_RANGE'], 6) // Skip the `bytes=` part of the header
                )
            );
    
            // If the last range param is empty, it means the EOF (End of File)
            if(!$ranges[1]){
                $ranges[1] = $size - 1;
            }
    
            // Send the appropriate headers
            header('HTTP/1.1 206 Partial Content');
            header('Accept-Ranges: bytes');
            header('Content-Length: ' . ($ranges[1] - $ranges[0])); // The size of the range
    
            // Send the ranges we offered
            header(
                sprintf(
                    'Content-Range: bytes %d-%d/%d', // The header format
                    $ranges[0], // The start range
                    $ranges[1], // The end range
                    $size // Total size of the file
                )
            );
    
            // It's time to output the file
            $f = fopen($path, 'rb'); // Open the file in binary mode
            $chunkSize = 8192; // The size of each chunk to output
    
            // Seek to the requested start range
            fseek($f, $ranges[0]);
    
            // Start outputting the data
            while(true){
                // Check if we have outputted all the data requested
                if(ftell($f) >= $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.

    這篇關于PHP:iPad 不能播放由 PHP 提供的 MP4 視頻,但如果直接訪問它可以的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

    【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 日本网站免费观看 | 天堂中文av| 最新国产精品精品视频 | 亚洲精品一区二区三区在线观看 | 亚洲一区二区精品视频在线观看 | 做a的各种视频 | 国产亚洲精品综合一区 | 国产精品一区二区在线 | 久久免费视频在线 | www日本高清视频 | 亚洲另类春色偷拍在线观看 | 请别相信他免费喜剧电影在线观看 | 黄色片网站国产 | 91文字幕巨乱亚洲香蕉 | 一本一道久久a久久精品综合 | 亚洲va欧美va天堂v国产综合 | 午夜在线| 日韩在线中文字幕 | 狠狠干网站 | www.日本在线播放 | 狠狠草视频 | 91大神xh98xh系列全部 | 欧美视频在线播放 | 久久99久久久久 | 日韩在线中文字幕 | 久久精品中文字幕 | 国产精品久久久久久238 | 91精品国产一区 | 在线观看中文字幕 | www狠狠干 | 午夜一级做a爰片久久毛片 精品综合 | 欧美国产日韩在线观看成人 | av日韩一区 | 亚洲国产一区在线 | 91在线网站 | 日韩一区二区在线视频 | 亚洲精品视频在线观看视频 | 中文字幕日本一区二区 | 999热精品| 日韩av在线中文字幕 | 一区二区三区视频在线 |