mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-12 03:06:22 +00:00
added controls and better mp4 stream
This commit is contained in:
65
inc/core.php
65
inc/core.php
@@ -225,7 +225,7 @@ function renderImage($data)
|
||||
if($data['ogg'])
|
||||
serveFile($oggpath, $hash.'.ogg','video/ogg');
|
||||
else
|
||||
serveFile($mp4path, $hash.'.mp4','video/mp4');
|
||||
serveMp4($mp4path, $hash.'.mp4','video/mp4');
|
||||
}
|
||||
else if($data['preview'])
|
||||
{
|
||||
@@ -274,7 +274,7 @@ function renderImage($data)
|
||||
|
||||
if($data['raw'])
|
||||
{
|
||||
serveFile($cachepath, $hash,'video/mp4');
|
||||
serveMP4($cachepath, $hash,'video/mp4');
|
||||
}
|
||||
else if($data['preview'])
|
||||
{
|
||||
@@ -354,11 +354,13 @@ function serveFile($filename, $filename_output = false, $mime = 'application/oct
|
||||
header('Accept-Ranges: bytes', true);
|
||||
header('Content-Type: ' . $mime, true);
|
||||
|
||||
/*
|
||||
if($filename_output)
|
||||
{
|
||||
header('Content-Disposition: attachment; filename="' . $filename_output . '"');
|
||||
}
|
||||
|
||||
*/
|
||||
header("Content-Disposition: inline;");
|
||||
// Content-Range header for byte offsets
|
||||
if (isset($_SERVER['HTTP_RANGE']) && preg_match('%bytes=(\d+)-(\d+)?%i', $_SERVER['HTTP_RANGE'], $match))
|
||||
{
|
||||
@@ -404,6 +406,63 @@ function serveFile($filename, $filename_output = false, $mime = 'application/oct
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//via gist: https://gist.github.com/codler/3906826
|
||||
function serveMP4($path,$hash,$null)
|
||||
{
|
||||
if ($fp = fopen($path, "rb")) {
|
||||
$size = filesize($path);
|
||||
$length = $size;
|
||||
$start = 0;
|
||||
$end = $size - 1;
|
||||
header('Content-type: video/mp4');
|
||||
header("Accept-Ranges: 0-$length");
|
||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
$c_start = $start;
|
||||
$c_end = $end;
|
||||
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
if (strpos($range, ',') !== false) {
|
||||
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
||||
header("Content-Range: bytes $start-$end/$size");
|
||||
exit;
|
||||
}
|
||||
if ($range == '-') {
|
||||
$c_start = $size - substr($range, 1);
|
||||
} else {
|
||||
$range = explode('-', $range);
|
||||
$c_start = $range[0];
|
||||
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
|
||||
}
|
||||
$c_end = ($c_end > $end) ? $end : $c_end;
|
||||
if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
|
||||
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
||||
header("Content-Range: bytes $start-$end/$size");
|
||||
exit;
|
||||
}
|
||||
$start = $c_start;
|
||||
$end = $c_end;
|
||||
$length = $end - $start + 1;
|
||||
fseek($fp, $start);
|
||||
header('HTTP/1.1 206 Partial Content');
|
||||
}
|
||||
header("Content-Range: bytes $start-$end/$size");
|
||||
header("Content-Length: ".$length);
|
||||
$buffer = 1024 * 8;
|
||||
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
|
||||
if ($p + $buffer > $end) {
|
||||
$buffer = $end - $p + 1;
|
||||
}
|
||||
set_time_limit(0);
|
||||
echo fread($fp, $buffer);
|
||||
flush();
|
||||
}
|
||||
fclose($fp);
|
||||
exit();
|
||||
} else {
|
||||
die('file not found');
|
||||
}
|
||||
}
|
||||
|
||||
function cidr_match($ip, $range)
|
||||
{
|
||||
list ($subnet, $bits) = explode('/', $range);
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<body id="body">
|
||||
|
||||
<div id="container">
|
||||
<video id="video" poster="<?php echo DOMAINPATH.PATH.'preview/'.$hash; ?>" preload="auto" autoplay="autoplay" muted="muted" loop="loop" webkit-playsinline>
|
||||
<video id="video" poster="<?php echo DOMAINPATH.PATH.'preview/'.$hash; ?>" preload="auto" autoplay="autoplay" muted="muted" loop="loop" controls="controls" webkit-playsinline>
|
||||
<source src="<?php echo DOMAINPATH.PATH.'raw/mp4/'.$hash; ?>" type="video/mp4">
|
||||
<!--<source src="<?php echo DOMAINPATH.PATH.'raw/webm/'.$hash; ?>" type="video/webm">
|
||||
<source src="<?php echo DOMAINPATH.PATH.'raw/ogg/'.$hash; ?>" type="video/ogg">-->
|
||||
|
||||
Reference in New Issue
Block a user