Php stream video from url

Don't know if you will be able to do this in PHP the way you described.

Let's say we have this HTML:

<video width="320" height="240" controls>
    <source src="playmymovie.php?url=http://domain/video-path/video.mp4" type="video/mp4">
    Your browser does not support the video tag.
</video>

So now we have to make a PHP page that handles this ( See Using php to output an mp4 video ):

<?php
$vid_url = isset($_GET['url'])?$_GET['url']:"";
if(empty($vid_url)){
    // trigger 404
    header("HTTP/1.0 404 Not Found");
} else {
    // Get Video

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $vid_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $out = curl_exec($ch);
    curl_close($ch);

    // Set header for mp4
    header('Content-type: video/mp4');
    header('Content-type: video/mpeg');
    header('Content-disposition: inline');
    header("Content-Transfer-Encoding:­ binary");
    header("Content-Length: ".filesize($out));

    // Pass video data
    echo $out;
}
exit();
?>

If it were me, I would test the URL first, make sure you get a 200 status, before trying to pass it back out. You could also trigger the correct status so the browser knows whats going on and can alert the user (or you).