mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-16 13:08:01 +00:00
rewrote mp4 and gif2mp4 functions to maintain the same naming structure as the rest of the resized images and stuff
This commit is contained in:
31
inc/core.php
31
inc/core.php
@@ -152,21 +152,25 @@ function renderImage($data)
|
||||
case 'gif':
|
||||
if($data['mp4'])
|
||||
{
|
||||
$mp4path = $path.'.mp4';
|
||||
$mp4path = $cachepath;
|
||||
|
||||
if(!file_exists($mp4path)) //if mp4 does not exist, create it
|
||||
$pm->gifToMP4($path,$mp4path);
|
||||
|
||||
if($data['raw'])
|
||||
{
|
||||
serveFile($mp4path, 'gif/raw/'.$hash,'video/mp4');
|
||||
serveFile($mp4path, $hash.'.mp4','video/mp4');
|
||||
}
|
||||
else if($data['preview'])
|
||||
{
|
||||
$file = $mp4path.'.jpg';
|
||||
$file = $mp4path;
|
||||
if(!file_exists($file))
|
||||
$pm->saveFirstFrameOfMP4($mp4path);
|
||||
$pm->saveFirstFrameOfMP4($mp4path,$path);
|
||||
header ("Content-type: image/jpeg");
|
||||
readfile($file);
|
||||
}
|
||||
else
|
||||
renderMP4($pm->gifToMP4($path),$data);
|
||||
renderMP4($mp4path,$data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -176,26 +180,25 @@ function renderImage($data)
|
||||
|
||||
break;
|
||||
case 'mp4':
|
||||
if(!$cached)
|
||||
if(!$cached && !$data['preview'])
|
||||
{
|
||||
$pm->resizeMP4($data,$cachepath);
|
||||
$path = $cachepath;
|
||||
}
|
||||
|
||||
if(filesize($path)==0) //if there was an error and the file is 0 bytes, use the original
|
||||
$path = ROOT.DS.'upload'.DS.$hash.DS.$hash;
|
||||
if(file_exists($cachepath) && filesize($cachepath)==0) //if there was an error and the file is 0 bytes, use the original
|
||||
$cachepath = ROOT.DS.'upload'.DS.$hash.DS.$hash;
|
||||
|
||||
if($data['raw'])
|
||||
{
|
||||
serveFile($path, '/raw/'.$hash,'video/mp4');
|
||||
serveFile($cachepath, $hash,'video/mp4');
|
||||
}
|
||||
else if($data['preview'])
|
||||
{
|
||||
$file = $path.'.jpg';
|
||||
if(!file_exists($file))
|
||||
$pm->saveFirstFrameOfMP4($path);
|
||||
if(!file_exists($cachepath))
|
||||
$pm->saveFirstFrameOfMP4($path,$cachepath);
|
||||
header ("Content-type: image/jpeg");
|
||||
readfile($file);
|
||||
readfile($cachepath);
|
||||
}
|
||||
else
|
||||
renderMP4($path,$data);
|
||||
@@ -232,11 +235,13 @@ function renderMP4($path,$data)
|
||||
{
|
||||
$pm = new PictshareModel;
|
||||
$hash = $data['hash'];
|
||||
$urldata = $pm->getURLInfo($path,true);
|
||||
if($data['size'])
|
||||
$hash = $data['size'].'/'.$hash;
|
||||
$info = $pm->getSizeOfMP4($path);
|
||||
$width = $info['width'];
|
||||
$height = $info['height'];
|
||||
$filesize = $urldata['humansize'];
|
||||
include (ROOT . DS . 'template_mp4.php');
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class PictshareModel extends Model
|
||||
return array('status'=>'ok');
|
||||
}
|
||||
|
||||
function getURLInfo($url)
|
||||
function getURLInfo($url,$ispath=false)
|
||||
{
|
||||
$url = rawurldecode($url);
|
||||
$data = $this->urlToData($url);
|
||||
@@ -21,8 +21,10 @@ class PictshareModel extends Model
|
||||
$path = ROOT.DS.'upload'.DS.$hash.DS.$file;
|
||||
if(file_exists($path))
|
||||
{
|
||||
$type = $this->getTypeOfHash($hash);
|
||||
$byte = filesize($path);
|
||||
$type = $this->getType($path);
|
||||
if($ispath)
|
||||
$byte = filesize($url);
|
||||
else $byte = filesize($path);
|
||||
if($type=='mp4')
|
||||
{
|
||||
$info = $this->getSizeOfMP4($path);
|
||||
@@ -191,8 +193,7 @@ class PictshareModel extends Model
|
||||
{
|
||||
ksort($data);
|
||||
unset($data['raw']);
|
||||
unset($data['preview']);
|
||||
unset($data['raw']);
|
||||
//unset($data['preview']);
|
||||
$name = false;
|
||||
foreach($data as $key=>$val)
|
||||
{
|
||||
@@ -317,6 +318,11 @@ class PictshareModel extends Model
|
||||
}
|
||||
}
|
||||
|
||||
function getType($url)
|
||||
{
|
||||
return $this->isTypeAllowed($this->getTypeOfFile($url));
|
||||
}
|
||||
|
||||
function uploadImageFromURL($url)
|
||||
{
|
||||
$type = $this->getTypeOfFile($url);
|
||||
@@ -346,12 +352,6 @@ class PictshareModel extends Model
|
||||
mkdir(ROOT.DS.'upload'.DS.$hash);
|
||||
$file = ROOT.DS.'upload'.DS.$hash.DS.$hash;
|
||||
|
||||
|
||||
if($type=='mp4')
|
||||
{
|
||||
$this->saveFirstFrameOfMP4($file);
|
||||
}
|
||||
|
||||
file_put_contents($file, file_get_contents($url));
|
||||
|
||||
//remove all exif data from jpeg
|
||||
@@ -681,27 +681,26 @@ class PictshareModel extends Model
|
||||
//if(!$maxheight)
|
||||
$maxheight = 'trunc(ow/a/2)*2';
|
||||
|
||||
$cmd = "$bin -i $file -y -vf scale=\"$maxwidth:$maxheight\" -c:v libx264 $cachepath";
|
||||
$cmd = "$bin -i $file -y -vf scale=\"$maxwidth:$maxheight\" -c:v libx264 -f mp4 $cachepath";
|
||||
|
||||
system($cmd);
|
||||
|
||||
return $cachepath;
|
||||
}
|
||||
|
||||
function gifToMP4($gifpath)
|
||||
function gifToMP4($gifpath,$target)
|
||||
{
|
||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
||||
$file = escapeshellarg($gifpath);
|
||||
$mp4file = $gifpath.'.mp4';
|
||||
|
||||
if(!file_exists($mp4file)) //simple caching.. have to think of something better
|
||||
if(!file_exists($target)) //simple caching.. have to think of something better
|
||||
{
|
||||
$cmd = "$bin -f gif -y -i $file -c:v libx264 $file.mp4";
|
||||
$cmd = "$bin -f gif -y -i $file -c:v libx264 -f mp4 $target";
|
||||
system($cmd);
|
||||
}
|
||||
|
||||
|
||||
return $mp4file;
|
||||
return $target;
|
||||
}
|
||||
|
||||
function saveAsMP4($source,$target)
|
||||
@@ -709,18 +708,16 @@ class PictshareModel extends Model
|
||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
||||
$source = escapeshellarg($source);
|
||||
$target = escapeshellarg($target);
|
||||
$cmd = "$bin -y -i $source -c:v libx264 $target";
|
||||
$cmd = "$bin -y -i $source -c:v libx264 -f mp4 $target";
|
||||
|
||||
system($cmd);
|
||||
}
|
||||
|
||||
function saveFirstFrameOfMP4($path)
|
||||
function saveFirstFrameOfMP4($path,$target)
|
||||
{
|
||||
//$path = ROOT.DS.'upload'.DS.$hash.DS.$hash;
|
||||
$jpgpath = $path.'.jpg';
|
||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
||||
$file = escapeshellarg($path);
|
||||
$cmd = "$bin -y -i $file -vframes 1 -f image2 $jpgpath";
|
||||
$cmd = "$bin -y -i $file -vframes 1 -f image2 $target";
|
||||
|
||||
system($cmd);
|
||||
}
|
||||
@@ -788,4 +785,9 @@ class PictshareModel extends Model
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function getMP4PathOfGif($gifpath)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,15 @@
|
||||
<meta id="viewport" name="viewport" content="width=<?php echo $width ?>, user-scalable=yes" />
|
||||
|
||||
<style type="text/css">
|
||||
#content, #video {
|
||||
/*#content, #video {
|
||||
width: <?php echo $width ?>px;
|
||||
height: <?php echo $height ?>px;
|
||||
}*/
|
||||
|
||||
video {
|
||||
width:100%;
|
||||
max-width:<?php echo $width ?>px;
|
||||
height:auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -40,6 +46,7 @@
|
||||
<video id="video" poster="<?php echo DOMAINPATH.'preview/'.$hash; ?>" preload="auto" autoplay="autoplay" muted="muted" loop="loop" webkit-playsinline>
|
||||
<source src="<?php echo DOMAINPATH.'raw/'.$hash; ?>" type="video/mp4">
|
||||
</video>
|
||||
<small><?php echo $filesize; ?></small>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user