<video>displaying binary data with tag

Asked 2 years ago, Updated 2 years ago, 37 views


Binary data of videos retrieved from MYSQL I'd like to play it on <Video>, is it possible?

javascript php html

2022-09-29 22:45

3 Answers

I think it's possible.
I think we need to consider various server restrictions, but if the server side is php, it would be like this.

<video><source src="hoge.php" type="video/mp4"></source></video>

Is this how hoge.php works?

$sql="SELECT* FROM`data`";
if($result=mysqli_query($link,$sql))}
    $row=mysqli_fetch_array($result,MYSQLI_NUM);
// video /mp4
    header("Content-type:video/mp4");
    echo [2];
}


2022-09-29 22:45

Divide CGI into video-based MIME-type binary and HTML-sprouting

You can return the former URL to the src attribute of the video tag by the latter.


2022-09-29 22:45

How do you like this?

function display_video(){
    $video='play.mp4';
    try{
        $db = new PDO($dbconnect, $db_user, $db_password);
    } catch(PDOException$e){
        echo'Connection failed: '.$e->getMessage();
    }

    if(($result=$db->query('SELECT video FROM videos WHERE'name'=''.$video.'')!==false)
    {
        echo'<div content="Content-Type:video/mp4">
                  <video width="600" height="480" controls="controlls" poster="image" preload="metadata">
                  <source src="data:video/mp4;base64, '.base64_encode($result->fetch(PDO::FETCH_COLUMN)))"/>
              </video>
          </div>';
    }
    else 
    {
        // What to do in case of failure?
    }
}


2022-09-29 22:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.