|
|
@ -93,6 +93,14 @@ class FfmpegService |
|
|
if (!$this->checkFileSize($pathFile)) { |
|
|
if (!$this->checkFileSize($pathFile)) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
if (filemtime($pathFile) > strtotime("2021-07-19 00:00:00")) { |
|
|
|
|
|
$mtime = date("Y-m-d H:i:s", filemtime($pathFile)); |
|
|
|
|
|
dump("$pathFile modify at $mtime is after 2021-07-19 00:00:00 skip"); |
|
|
|
|
|
return; |
|
|
|
|
|
} else { |
|
|
|
|
|
$mtime = date("Y-m-d H:i:s", filemtime($pathFile)); |
|
|
|
|
|
dump("$pathFile modify at $mtime is after 2021-07-19 00:00:00"); |
|
|
|
|
|
} |
|
|
$fileInfo = pathinfo($pathFile); |
|
|
$fileInfo = pathinfo($pathFile); |
|
|
if (ends_with($fileInfo["filename"], "-x265")) { |
|
|
if (ends_with($fileInfo["filename"], "-x265")) { |
|
|
return; |
|
|
return; |
|
|
@ -107,9 +115,9 @@ class FfmpegService |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
dump("targetFile", [$targetFile]); |
|
|
dump("targetFile", [$targetFile]); |
|
|
$result = shell_exec("ffmpeg -i '". $pathFile ."' -c:v libx265 -vtag hvc1 '" . $targetFile . "' && echo 'ok'"); |
|
|
|
|
|
|
|
|
$result = shell_exec("ffmpeg -threads 4 -i '". $pathFile ."' -c:v libx265 -vtag hvc1 '" . $targetFile . "' && echo 'ok'"); |
|
|
echo $result; |
|
|
echo $result; |
|
|
if ($result == "ok") { |
|
|
|
|
|
|
|
|
if (trim($result) == "ok") { |
|
|
echo "compress work done remove the file \n"; |
|
|
echo "compress work done remove the file \n"; |
|
|
$oldFileSize = filesize($pathFile); |
|
|
$oldFileSize = filesize($pathFile); |
|
|
$newFileSize = filesize($targetFile); |
|
|
$newFileSize = filesize($targetFile); |
|
|
@ -118,6 +126,7 @@ class FfmpegService |
|
|
echo "old file size is smaller than new one, old is " . file_size($oldFileSize) . " and new is " . file_size($newFileSize) . ", now remove new one"; |
|
|
echo "old file size is smaller than new one, old is " . file_size($oldFileSize) . " and new is " . file_size($newFileSize) . ", now remove new one"; |
|
|
unlink($targetFile); |
|
|
unlink($targetFile); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
Redis::sadd("unneed", $fileInfo["filename"]); |
|
|
echo "new file size is smaller than old one, new is " . file_size($newFileSize) . " and old is " . file_size($oldFileSize) . ", now remove old one"; |
|
|
echo "new file size is smaller than old one, new is " . file_size($newFileSize) . " and old is " . file_size($oldFileSize) . ", now remove old one"; |
|
|
unlink($pathFile); |
|
|
unlink($pathFile); |
|
|
rename($targetFile, $pathFile); |
|
|
rename($targetFile, $pathFile); |
|
|
@ -208,7 +217,7 @@ class FfmpegService |
|
|
|
|
|
|
|
|
public function checkFileSize($file, $size = 1): bool |
|
|
public function checkFileSize($file, $size = 1): bool |
|
|
{ |
|
|
{ |
|
|
if (is_file($file) && filesize($file) > 100 * 1024 * 1024) { |
|
|
|
|
|
|
|
|
if (is_file($file) && filesize($file) > 50 * 1024 * 1024) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
$fileSize = FileUtils::humanFilesize(filesize($file)); |
|
|
$fileSize = FileUtils::humanFilesize(filesize($file)); |
|
|
|