From 498a928707e20d4697d2b32a9a7dcc6f444fe05d Mon Sep 17 00:00:00 2001 From: shixuesen Date: Mon, 20 Mar 2023 23:33:38 +0800 Subject: [PATCH] add sleep code --- app/Services/FfmpegService.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/Services/FfmpegService.php b/app/Services/FfmpegService.php index 0a66df3..505f171 100644 --- a/app/Services/FfmpegService.php +++ b/app/Services/FfmpegService.php @@ -127,10 +127,14 @@ class FfmpegService public function processVideo($pathFile) { - while (date("H") >= 22 || date("H") < 8) { - Log::info("now is " . date("Y-m-d H:i:s") . " sleep 5 minutes"); - sleep(5 * 60); + $slowFlag = false; + if (date("H") >= 22 || date("H") < 8) { + $slowFlag = true; } +// while () { +// Log::info("now is " . date("Y-m-d H:i:s") . " sleep 5 minutes"); +// sleep(5 * 60); +// } Log::info("current process pathFile " . $pathFile); try { $mime = mime_content_type($pathFile); @@ -189,11 +193,19 @@ class FfmpegService } dump("targetFile", [$targetFile]); Log::info("process target file : $targetFile"); - if (filesize($pathFile) > 10 * 1024 * 1024 * 1024 || $this->getDimension($pathFile)->getWidth() > 1920) { + if ($this->getDimension($pathFile)->getWidth() > 3840) { // $result = shell_exec("/Users/shixuesen/Downloads/ffmpeg -threads 16 -i ". escapeshellarg($pathFile) ." -preset ultrafast -crf 25 -c:v libx265 -x265-params pools=8 -vtag hvc1 " . escapeshellarg($targetFile) . " && echo 'ok'"); - $result = shell_exec("/Users/shixuesen/Downloads/ffmpeg -i ". escapeshellarg($pathFile) ." -c:v libx265 -x265-params pools=8 -vtag hvc1 -vf \"scale=4096:-1\" " . escapeshellarg($targetFile) . " && echo 'ok'"); + if ($slowFlag) { + $result = shell_exec("/Users/shixuesen/Downloads/ffmpeg -i ". escapeshellarg($pathFile) ." -c:v libx265 -x265-params pools=2 -vtag hvc1 -vf \"scale=4096:-1\" " . escapeshellarg($targetFile) . " && echo 'ok'"); + } else { + $result = shell_exec("/Users/shixuesen/Downloads/ffmpeg -i ". escapeshellarg($pathFile) ." -c:v libx265 -x265-params pools=8 -vtag hvc1 -vf \"scale=4096:-1\" " . escapeshellarg($targetFile) . " && echo 'ok'"); + } } else { - $result = shell_exec("/Users/shixuesen/Downloads/ffmpeg -threads 16 -i ". escapeshellarg($pathFile) ." -preset fast -c:v libx265 -x265-params pools=8 -vtag hvc1 " . escapeshellarg($targetFile) . " && echo 'ok'"); + if ($slowFlag) { + $result = shell_exec("/Users/shixuesen/Downloads/ffmpeg -threads 2 -i ". escapeshellarg($pathFile) ." -preset fast -c:v libx265 -x265-params pools=2 -vtag hvc1 " . escapeshellarg($targetFile) . " && echo 'ok'"); + } else { + $result = shell_exec("/Users/shixuesen/Downloads/ffmpeg -threads 8 -i ". escapeshellarg($pathFile) ." -preset fast -c:v libx265 -x265-params pools=8 -vtag hvc1 " . escapeshellarg($targetFile) . " && echo 'ok'"); + } } // echo $result; // return;