Binary data of videos retrieved from MYSQL
I'd like to play it on <Video>
, is it possible?
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];
}
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.
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?
}
}
© 2024 OneMinuteCode. All rights reserved.