在提取内容并使用PHP进行base64编码后无法返回视频


Failed get back video after extract content and base64 encode it using PHP

我试图回到我的视频(mp4)后,我得到的内容,然后我base64编码它,但我的视频仍然没有播放。我已经尝试了下面的图像代码,它的工作原理。为什么它不能用于视频?

<?php
    $con=file_get_contents("kecak.mp4"); //kecak.mp4 work to play with <video> </video> tag
    $en=base64_encode($con);
    $binary_data='data:'.$mime.';base64,'. $en ;
?>
<video width="320" height="240" controls="controls">
    <source src="<?php echo $binary_data ?>" type="video/mp4" /> 
    Your browser does not support the video tag.
</video>

我相信base64_encode有长度限制。当输入太长时,它不会输出任何东西。我没有你的视频或细节来测试它,但我认为chunk_split可以帮助你:http://nl.php.net/manual/en/function.chunk-split.php.

   // works for me
    $img_str = base64_encode(file_get_contents($filename)); // encode file
    header("Access-Control-Allow-Origin: *"); // allow all CORS // dev only
    header("Content-Type: text/plain"); // resp file header
    echo($img_str);  // echo base64 string