mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-16 21:18:00 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
479798a1d2 | ||
|
|
75cde97ae9 | ||
|
|
8f1a4f3af9 | ||
|
|
7adf83cb3a | ||
|
|
d292bbf6bd | ||
|
|
15af093b27 | ||
|
|
e9c6795d7d | ||
|
|
977d3f6bda | ||
|
|
e57360bcfc | ||
|
|
8586775116 |
@@ -10,15 +10,20 @@ services:
|
|||||||
- "80:80"
|
- "80:80"
|
||||||
- "443:443"
|
- "443:443"
|
||||||
environment:
|
environment:
|
||||||
- TITLE=
|
|
||||||
- AUTOUPDATE=false
|
- AUTOUPDATE=false
|
||||||
- MAXUPLOADSIZE=
|
- MAX_UPLOAD_SIZE=
|
||||||
- MASTERDELETECODE=
|
- TITLE=
|
||||||
- BLOATING=
|
- PNG_COMPRESSION=
|
||||||
- UPLOADCODE=
|
- JPEG_COMPRESSION=
|
||||||
- UPLOADPATH=
|
- MASTER_DELETE_CODE=
|
||||||
- IMAGECHANGECODE=
|
- MASTER_DELETE_IP=
|
||||||
- LOGUPLOADER=
|
- UPLOAD_FORM_LOCATION=
|
||||||
- MAXRESIZEDIMAGES=
|
- LOW_PROFILE=
|
||||||
- DOMAIN=
|
- UPLOAD_CODE=
|
||||||
- SHOWERRORS=
|
- IMAGE_CHANGE_CODE=
|
||||||
|
- LOG_UPLOADER=
|
||||||
|
- MAX_RESIZED_IMAGES=
|
||||||
|
- ALLOW_BLOATING=
|
||||||
|
- FORCE_DOMAIN=
|
||||||
|
- SHOW_ERRORS=
|
||||||
|
- FFMPEG_BINARY=
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
spl_autoload_register('autoload');
|
spl_autoload_register('autoload');
|
||||||
|
|
||||||
|
if(!defined('FFMPEG_BINARY') || !FFMPEG_BINARY )
|
||||||
|
define('FFMPEG_BINARY',ROOT.DS.'bin'.DS.'ffmpeg');
|
||||||
|
|
||||||
function autoload($className)
|
function autoload($className)
|
||||||
{
|
{
|
||||||
if (file_exists(ROOT . DS . 'models' . DS . strtolower($className) . '.php'))
|
if (file_exists(ROOT . DS . 'models' . DS . strtolower($className) . '.php'))
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ define('SHOW_ERRORS', false);
|
|||||||
//remove comments to use
|
//remove comments to use
|
||||||
|
|
||||||
/* BACKBLAZE B2 */
|
/* BACKBLAZE B2 */
|
||||||
|
//========
|
||||||
/* You can find your info here: https://secure.backblaze.com/b2_buckets.htm */
|
/* You can find your info here: https://secure.backblaze.com/b2_buckets.htm */
|
||||||
//define('BACKBLAZE',true); //true=>use backblaze false=>don't
|
//define('BACKBLAZE',true); //true=>use backblaze false=>don't
|
||||||
//define('BACKBLAZE_ID','');
|
//define('BACKBLAZE_ID','');
|
||||||
@@ -88,10 +89,21 @@ define('SHOW_ERRORS', false);
|
|||||||
//define('BACKBLAZE_AUTOUPLOAD', true); //if true, will upload images to backblaze when they are uploaded to pictshare
|
//define('BACKBLAZE_AUTOUPLOAD', true); //if true, will upload images to backblaze when they are uploaded to pictshare
|
||||||
//define('BACKBLAZE_AUTODELETE', true); //if true, will delete images from backblaze if they are deleted from pictshare
|
//define('BACKBLAZE_AUTODELETE', true); //if true, will delete images from backblaze if they are deleted from pictshare
|
||||||
|
|
||||||
|
|
||||||
|
//Backup Folder
|
||||||
|
//========
|
||||||
//If you have a NAS or some cifs or nfs mounted drive, you can specify this here as a folder
|
//If you have a NAS or some cifs or nfs mounted drive, you can specify this here as a folder
|
||||||
//if a requested hash is not found locally, its looked up on this location. This allows for mounted external spaces
|
//if a requested hash is not found locally, its looked up on this location. This allows for mounted external spaces
|
||||||
//or just backups on a second drive.
|
//or just backups on a second drive.
|
||||||
//Also new hashes will be uploaded there (just the originals, not resizes)
|
//Also new hashes will be uploaded/copied there (just the originals, not resizes)
|
||||||
//value should be a path **without tailing slash**!
|
//value should be a path **without tailing slash**!
|
||||||
|
|
||||||
define('ALT_FOLDER','/mnt');
|
//define('ALT_FOLDER','/mnt');
|
||||||
|
|
||||||
|
//FFMPEG
|
||||||
|
//========
|
||||||
|
//If you are using PictShare on some other machine than x64 linux (eg raspberry pi or windows) the builtin ffmpeg binary won't work
|
||||||
|
//this is why you can define an alternative path to the ffmpeg binary here.
|
||||||
|
|
||||||
|
//define('FFMPEG_BINARY','/usr/bin/ffmpeg');
|
||||||
|
|
||||||
|
|||||||
@@ -509,7 +509,7 @@ class PictshareModel extends Model
|
|||||||
unlink($tempfile);
|
unlink($tempfile);
|
||||||
|
|
||||||
//re-render new mp4 by calling the re-encode script
|
//re-render new mp4 by calling the re-encode script
|
||||||
if($type=='mp4' && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
|
if($type=='mp4')
|
||||||
{
|
{
|
||||||
system("nohup php ".ROOT.DS.'tools'.DS.'re-encode_mp4.php force '.$hash." > /dev/null 2> /dev/null &");
|
system("nohup php ".ROOT.DS.'tools'.DS.'re-encode_mp4.php force '.$hash." > /dev/null 2> /dev/null &");
|
||||||
}
|
}
|
||||||
@@ -700,7 +700,7 @@ class PictshareModel extends Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($hashes)>1)
|
if(is_array($hashes) && count($hashes)>1)
|
||||||
{
|
{
|
||||||
$albumlink = DOMAINPATH.PATH.implode('/',$hashes);
|
$albumlink = DOMAINPATH.PATH.implode('/',$hashes);
|
||||||
$o.='<hr/><h1>Album link</h1><a href="'.$albumlink.'" >'.$albumlink.'</a>';
|
$o.='<hr/><h1>Album link</h1><a href="'.$albumlink.'" >'.$albumlink.'</a>';
|
||||||
@@ -895,7 +895,7 @@ class PictshareModel extends Model
|
|||||||
{
|
{
|
||||||
$file = escapeshellarg($filename);
|
$file = escapeshellarg($filename);
|
||||||
$tmp = ROOT.DS.'tmp'.DS.md5(time()+rand(1,10000)).'.'.rand(1,10000).'.log';
|
$tmp = ROOT.DS.'tmp'.DS.md5(time()+rand(1,10000)).'.'.rand(1,10000).'.log';
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(FFMPEG_BINARY);
|
||||||
|
|
||||||
$cmd = "$bin -i $file > $tmp 2>> $tmp";
|
$cmd = "$bin -i $file > $tmp 2>> $tmp";
|
||||||
|
|
||||||
@@ -921,7 +921,7 @@ class PictshareModel extends Model
|
|||||||
$file = ROOT.DS.'upload'.DS.$data['hash'].DS.$data['hash'];
|
$file = ROOT.DS.'upload'.DS.$data['hash'].DS.$data['hash'];
|
||||||
$file = escapeshellarg($file);
|
$file = escapeshellarg($file);
|
||||||
$tmp = '/dev/null';
|
$tmp = '/dev/null';
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(FFMPEG_BINARY);
|
||||||
|
|
||||||
$size = $data['size'];
|
$size = $data['size'];
|
||||||
|
|
||||||
@@ -949,7 +949,7 @@ class PictshareModel extends Model
|
|||||||
|
|
||||||
function gifToMP4($gifpath,$target)
|
function gifToMP4($gifpath,$target)
|
||||||
{
|
{
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(FFMPEG_BINARY);
|
||||||
$file = escapeshellarg($gifpath);
|
$file = escapeshellarg($gifpath);
|
||||||
|
|
||||||
if(!file_exists($target)) //simple caching.. have to think of something better
|
if(!file_exists($target)) //simple caching.. have to think of something better
|
||||||
@@ -964,7 +964,7 @@ class PictshareModel extends Model
|
|||||||
|
|
||||||
function saveAsMP4($source,$target)
|
function saveAsMP4($source,$target)
|
||||||
{
|
{
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(FFMPEG_BINARY);
|
||||||
$source = escapeshellarg($source);
|
$source = escapeshellarg($source);
|
||||||
$target = escapeshellarg($target);
|
$target = escapeshellarg($target);
|
||||||
$h265 = "$bin -y -i $source -an -c:v libx264 -qp 0 -f mp4 $target";
|
$h265 = "$bin -y -i $source -an -c:v libx264 -qp 0 -f mp4 $target";
|
||||||
@@ -973,7 +973,7 @@ class PictshareModel extends Model
|
|||||||
|
|
||||||
function saveAsOGG($source,$target)
|
function saveAsOGG($source,$target)
|
||||||
{
|
{
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(FFMPEG_BINARY);
|
||||||
$source = escapeshellarg($source);
|
$source = escapeshellarg($source);
|
||||||
$target = escapeshellarg($target);
|
$target = escapeshellarg($target);
|
||||||
$h265 = "$bin -y -i $source -vcodec libtheora -acodec libvorbis -qp 0 -f ogg $target";
|
$h265 = "$bin -y -i $source -vcodec libtheora -acodec libvorbis -qp 0 -f ogg $target";
|
||||||
@@ -983,7 +983,7 @@ class PictshareModel extends Model
|
|||||||
function saveAsWebm($source,$target)
|
function saveAsWebm($source,$target)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(FFMPEG_BINARY);
|
||||||
$source = escapeshellarg($source);
|
$source = escapeshellarg($source);
|
||||||
$target = escapeshellarg($target);
|
$target = escapeshellarg($target);
|
||||||
$webm = "$bin -y -i $source -vcodec libvpx -acodec libvorbis -aq 5 -ac 2 -qmax 25 -f webm $target";
|
$webm = "$bin -y -i $source -vcodec libvpx -acodec libvorbis -aq 5 -ac 2 -qmax 25 -f webm $target";
|
||||||
@@ -992,7 +992,7 @@ class PictshareModel extends Model
|
|||||||
|
|
||||||
function saveFirstFrameOfMP4($path,$target)
|
function saveFirstFrameOfMP4($path,$target)
|
||||||
{
|
{
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(FFMPEG_BINARY);
|
||||||
$file = escapeshellarg($path);
|
$file = escapeshellarg($path);
|
||||||
$cmd = "$bin -y -i $file -vframes 1 -f image2 $target";
|
$cmd = "$bin -y -i $file -vframes 1 -f image2 $target";
|
||||||
|
|
||||||
@@ -1003,7 +1003,7 @@ class PictshareModel extends Model
|
|||||||
function getSizeOfMP4($video)
|
function getSizeOfMP4($video)
|
||||||
{
|
{
|
||||||
$video = escapeshellarg($video);
|
$video = escapeshellarg($video);
|
||||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
$bin = escapeshellcmd(FFMPEG_BINARY);
|
||||||
$command = $bin . ' -i ' . $video . ' -vstats 2>&1';
|
$command = $bin . ' -i ' . $video . ' -vstats 2>&1';
|
||||||
$output = shell_exec($command);
|
$output = shell_exec($command);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
* usage: php re-encode_mp4.php [noogg] [nowebm] [noskip]
|
* usage: php re-encode_mp4.php [noogg] [nowebm] [noskip]
|
||||||
*
|
*
|
||||||
* Params:
|
* Params:
|
||||||
* noskip => Won't skip existing videos (re-renders them)
|
* altfolder => Will check the altfolder (if exists) for falsly encoded files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -31,13 +31,34 @@ foreach($argv as $arg)
|
|||||||
$localfiles[] = $arg;
|
$localfiles[] = $arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_array('noskip',$argv) || in_array('force',$argv))
|
if(in_array('altfolder',$argv) && defined('ALT_FOLDER') && ALT_FOLDER && is_dir(ALT_FOLDER) )
|
||||||
{
|
{
|
||||||
echo "Won't skip existing files\n\n";
|
echo "[i] Checking only the alt folder\n";
|
||||||
$allowskipping = false;
|
$dir = ALT_FOLDER.DS;
|
||||||
|
$dh = opendir($dir);
|
||||||
|
while (false !== ($filename = readdir($dh))) {
|
||||||
|
$img = $dir.$filename;
|
||||||
|
$hash = $filename;
|
||||||
|
echo "\r[$filename] ";
|
||||||
|
if(!file_exists($img)) continue;
|
||||||
|
$type = strtolower(pathinfo($img, PATHINFO_EXTENSION));
|
||||||
|
$type = $pm->isTypeAllowed($type);
|
||||||
|
if($type=='mp4')
|
||||||
|
{
|
||||||
|
echo "\n [i] $filename is ..\t";
|
||||||
|
$valid = checkFileForValidMP4($img);
|
||||||
|
$tmp = ROOT.DS.'tmp'.DS.$hash;
|
||||||
|
$cmd = FFMPEG_BINARY." -loglevel panic -y -i $img -vcodec libx264 -an -profile:v baseline -level 3.0 -pix_fmt yuv420p -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" $tmp && cp $tmp $img";
|
||||||
|
echo ($valid?'Valid'."\n":'Not valid => Converting..');
|
||||||
|
if(!$valid)
|
||||||
|
{
|
||||||
|
system($cmd);
|
||||||
|
echo " done\n";
|
||||||
|
unlink($tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
$allowskipping = true;
|
|
||||||
|
|
||||||
//making sure ffmpeg is executable
|
//making sure ffmpeg is executable
|
||||||
system("chmod +x ".ROOT.DS.'bin'.DS.'ffmpeg');
|
system("chmod +x ".ROOT.DS.'bin'.DS.'ffmpeg');
|
||||||
@@ -59,19 +80,52 @@ if(count($localfiles)==0) exit('No MP4 files found'."\n");
|
|||||||
|
|
||||||
echo "[i] Got ".count($localfiles)." files\n";
|
echo "[i] Got ".count($localfiles)." files\n";
|
||||||
|
|
||||||
|
|
||||||
|
//TESTING
|
||||||
|
echo "[i] Checking hashes for wrongly encoded ones\n";
|
||||||
|
foreach($localfiles as $akey => $hash)
|
||||||
|
{
|
||||||
|
$mp4 = $dir.$hash.DS.$hash;
|
||||||
|
if(checkFileForValidMP4($mp4))
|
||||||
|
{
|
||||||
|
echo " [i] Skipping $hash because it's already correctly encoded\n";
|
||||||
|
unset($localfiles[$akey]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo "[i] Starting to convert\n";
|
echo "[i] Starting to convert\n";
|
||||||
foreach($localfiles as $hash)
|
foreach($localfiles as $hash)
|
||||||
{
|
{
|
||||||
$img = $dir.$hash.DS.$hash;
|
$mp4 = $dir.$hash.DS.$hash;
|
||||||
$tmp = ROOT.DS.'tmp'.DS.$hash;
|
$tmp = ROOT.DS.'tmp'.DS.$hash;
|
||||||
if(file_exists($tmp) && $allowskipping==true)
|
$cmd = FFMPEG_BINARY." -loglevel panic -y -i $mp4 -vcodec libx264 -an -profile:v baseline -level 3.0 -pix_fmt yuv420p -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" $tmp && cp $tmp $mp4";
|
||||||
echo "Skipping $hash\n";
|
echo " [i] Converting '$hash'";
|
||||||
else
|
|
||||||
{
|
|
||||||
$cmd = ROOT.DS.'bin'.DS."ffmpeg -loglevel panic -y -i $img -vcodec libx264 -an -profile:v baseline -level 3.0 -pix_fmt yuv420p -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" $tmp && cp $tmp $img";
|
|
||||||
echo " [i] Converting $hash";
|
|
||||||
system($cmd);
|
system($cmd);
|
||||||
|
if(defined('ALT_FOLDER') && ALT_FOLDER && is_dir(ALT_FOLDER))
|
||||||
|
copy($mp4,ALT_FOLDER.DS.$hash);
|
||||||
echo "\tdone\n";
|
echo "\tdone\n";
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkFileForValidMP4($file)
|
||||||
|
{
|
||||||
|
$hash = md5($file);
|
||||||
|
$cmd = FFMPEG_BINARY." -i $file -hide_banner 2> ".ROOT.DS.'tmp'.DS.$hash.'.txt';
|
||||||
|
system($cmd);
|
||||||
|
$results = file(ROOT.DS.'tmp'.DS.$hash.'.txt');
|
||||||
|
foreach($results as $l)
|
||||||
|
{
|
||||||
|
$elements = explode(':',trim($l));
|
||||||
|
$key=trim(array_shift($elements));
|
||||||
|
$value = trim(implode(':',$elements));
|
||||||
|
if($key=='encoder')
|
||||||
|
{
|
||||||
|
if(startsWith(strtolower($value),'lav'))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unlink(ROOT.DS.'tmp'.DS.$hash.'.txt');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -65,7 +65,7 @@ foreach($localfiles as $hash)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo " [OGG] User wants OGG. Will do.. ";
|
echo " [OGG] User wants OGG. Will do.. ";
|
||||||
$cmd = "../bin/ffmpeg -y -i $img -loglevel panic -vcodec libtheora -an $tmp && cp $tmp $ogg";
|
$cmd = FFMPEG_BINARY." -y -i $img -loglevel panic -vcodec libtheora -an $tmp && cp $tmp $ogg";
|
||||||
system($cmd);
|
system($cmd);
|
||||||
echo "done\n";
|
echo "done\n";
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ foreach($localfiles as $hash)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo " [WEBM] User wants WEBM. Will do.. ";
|
echo " [WEBM] User wants WEBM. Will do.. ";
|
||||||
$cmd = "../bin/ffmpeg -y -i $img -loglevel panic -c:v libvpx -crf 10 -b:v 1M $tmp && cp $tmp $webm";
|
$cmd = FFMPEG_BINARY." -y -i $img -loglevel panic -c:v libvpx -crf 10 -b:v 1M $tmp && cp $tmp $webm";
|
||||||
system($cmd);
|
system($cmd);
|
||||||
echo "done\n";
|
echo "done\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user