播放以BLOB文件形式存储在MariaDB中的视频

时间:2018-12-27 11:29:39

标签: php html database video blob

使用所附的脚本,我正在尝试播放视频,该视频作为BLOB文件存储在数据库中。变量$row['video']将视频包含为BLOB-Dataformat。在尝试以不同于mp4的其他数据格式播放视频之前,一切工作都很好。 我知道HTML5中的视频标记不允许* .avi等,因此我也尝试了<embed><object>。两者也仅适用于mp4。您有什么想法我在做什么错吗?跳到下面的“ README”以查找代码中出现问题的位置。

这是学校的作业,因此必须使用BLOB数据格式。

在此先感谢您的帮助。

  <?php
    $id = mysqli_real_escape_string($conn, $_GET['id']);    

    if($id)
    {
        $sql = "SELECT * FROM video WHERE id = '$id'";
        $result = $conn->query($sql);

        if ($result) 
        {
            $row = $result->fetch_assoc(); 

            if(checkFileFormat($row["videoformat"]) == "image")
            {
                //display photo
                echo '<img width="25%" height="25%" src="data:image/' . $row["videoformat"] . ';base64,'.base64_encode($row['video']).'"/>
                      <br>';
                echo $row["title"] . "<br><br>";

                echo '
                    <object width="368" height="119" data="data:' . checkFileFormat($row["videoformat"]) . '/' . $row["videoformat"] . ';base64,' . base64_encode($row['video']).'"></object>
                ';

            }
            else if(checkFileFormat($row["videoformat"]) == "video")
            {
                //display video        
/* 
************* README ************* 
base64 encode + video tag --> works for mp4-videos; I don't have any clue how to play for example avi-videos. I already tried via <object> and  <embed> both also does not work for me.
************* END README ************* 
*/
        //base64 encode + video tag *** does work for mp4
        echo '
            video: <br>
            <video width="320" height="240" controls>
                <source src="data:video/' . $row["videoformat"] . ';base64,' . base64_encode($row['video']).'" type="video/' . $row["videoformat"] .'">
            </video>
            <br><br>';

        //embed for avi file *** does not work
        echo '
            embed for avi: <br>
            <embed type="application/x-mplayer2" src="data:video/' . $row["videoformat"] . ';base64,' . base64_encode($row['video']).'">
            </embed>
            <br><br>
        ';

        //object for avi file *** does not work
        echo '
            object for avi: <br>
            <object type="video/x-msvideo" data="data:video/' . $row["videoformat"] . ';base64,' . base64_encode($row['video']).'">
                <param name="src" value="data:video/' . $row["videoformat"] . ';base64,' . base64_encode($row['video']).'">
                <param name="autoStart" value="0">
            </object>
            <br><br>
        ';

        //object for mp4 file *** does work
        echo '
            object for mp4: <br>
            <object type="video/mp4" data="data:video/' . $row["videoformat"] . ';base64,' . base64_encode($row['video']).'">
            </object>
            <br><br>
        ';

        //embed for mp4 file *** does work
        echo '
            embed for mp4: <br>
            <embed type="video/mp4" src="data:video/' . $row["videoformat"] . ';base64,' . base64_encode($row['video']).'">
            </embed>
            <br><br>
        ';


                echo "Title: " . $row["title"] . " | Duration: " . $row["duration"] . " | Format: " . $row["videoformat"];
            }
            else
            {
                echo "Error: file format not supported!";
            }
        }
        else    
        {
            trigger_error('Invalid query: ' . $conn->error);
        }
    }
    else
        echo "Error: missing id";

    ?>

0 个答案:

没有答案