mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-17 13:38:01 +00:00
added resizing for mp4 files
This commit is contained in:
13
inc/core.php
13
inc/core.php
@@ -150,13 +150,11 @@ function renderImage($data)
|
|||||||
imagepng($im);
|
imagepng($im);
|
||||||
break;
|
break;
|
||||||
case 'gif':
|
case 'gif':
|
||||||
|
|
||||||
if($data['mp4'])
|
if($data['mp4'])
|
||||||
{
|
{
|
||||||
header("Content-Type: video/mp4");
|
header("Content-Type: video/mp4");
|
||||||
readfile($pm->gifToMP4($path));
|
readfile($pm->gifToMP4($path));
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
header ("Content-type: image/gif");
|
header ("Content-type: image/gif");
|
||||||
@@ -165,7 +163,16 @@ function renderImage($data)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 'mp4':
|
case 'mp4':
|
||||||
header("Content-Type: video/mp4");
|
if(!$cached)
|
||||||
|
{
|
||||||
|
$path = $pm->resizeMP4($data,$cachepath);
|
||||||
|
}
|
||||||
|
header('Content-type: video/mp4');
|
||||||
|
//header('Content-type: video/mpeg');
|
||||||
|
header('Content-disposition: inline');
|
||||||
|
header("Content-Transfer-Encoding: binary");
|
||||||
|
header("Content-Length: ".filesize($path));
|
||||||
|
|
||||||
readfile($path);
|
readfile($path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -630,12 +630,50 @@ class PictshareModel extends Model
|
|||||||
return $ismp4;
|
return $ismp4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resizeMP4($data,$cachepath)
|
||||||
|
{
|
||||||
|
$file = ROOT.DS.'upload'.DS.$data['hash'].DS.$data['hash'];
|
||||||
|
$file = escapeshellarg($file);
|
||||||
|
$tmp = '/dev/null';
|
||||||
|
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
||||||
|
|
||||||
|
$size = $data['size'];
|
||||||
|
|
||||||
|
if(!$size) return $file;
|
||||||
|
|
||||||
|
if(!is_numeric($size))
|
||||||
|
$size = explode('x',$size);
|
||||||
|
|
||||||
|
if(is_array($size))
|
||||||
|
{
|
||||||
|
$maxwidth = $size[0];
|
||||||
|
$maxheight = $size[1];
|
||||||
|
}
|
||||||
|
else if($size)
|
||||||
|
{
|
||||||
|
$maxwidth = $size;
|
||||||
|
$maxheight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($maxwidth>1080)
|
||||||
|
$maxwidth = 1080;
|
||||||
|
|
||||||
|
//if(!$maxheight)
|
||||||
|
$maxheight = 'trunc(ow/a/2)*2';
|
||||||
|
|
||||||
|
$cmd = "$bin -i $file -y -vf scale=\"$maxwidth:$maxheight\" -c:v libx264 $cachepath";
|
||||||
|
|
||||||
|
system($cmd);
|
||||||
|
|
||||||
|
return $cachepath;
|
||||||
|
}
|
||||||
|
|
||||||
function gifToMP4($gifpath)
|
function gifToMP4($gifpath)
|
||||||
{
|
{
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
||||||
$file = escapeshellarg($gifpath);
|
$file = escapeshellarg($gifpath);
|
||||||
$mp4file = $gifpath.'.mp4';
|
$mp4file = $gifpath.'.mp4';
|
||||||
$cmd = "$bin -f gif -i $file $file.mp4";
|
$cmd = "$bin -f gif -y -i $file -c:v libx264 $file.mp4";
|
||||||
|
|
||||||
system($cmd);
|
system($cmd);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user