|
|
@ -1,11 +1,14 @@ |
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
namespace App\Services; |
|
|
namespace App\Services; |
|
|
|
|
|
use App\EncodeRecord; |
|
|
use App\Utils\FileUtils; |
|
|
use App\Utils\FileUtils; |
|
|
use FFMpeg\Coordinate\Dimension; |
|
|
use FFMpeg\Coordinate\Dimension; |
|
|
use FFMpeg\FFProbe; |
|
|
use FFMpeg\FFProbe; |
|
|
|
|
|
use Illuminate\Support\Facades\App; |
|
|
use Illuminate\Support\Facades\Log; |
|
|
use Illuminate\Support\Facades\Log; |
|
|
use Illuminate\Support\Facades\Redis; |
|
|
use Illuminate\Support\Facades\Redis; |
|
|
|
|
|
use Illuminate\Support\Str; |
|
|
use Mhor\MediaInfo\MediaInfo; |
|
|
use Mhor\MediaInfo\MediaInfo; |
|
|
use Throwable; |
|
|
use Throwable; |
|
|
|
|
|
|
|
|
@ -19,6 +22,8 @@ class FfmpegService { |
|
|
|
|
|
|
|
|
private $needRemoveExistFiles = false; |
|
|
private $needRemoveExistFiles = false; |
|
|
|
|
|
|
|
|
|
|
|
private $checkFileEncodeType = true; |
|
|
|
|
|
|
|
|
private $preset = ""; |
|
|
private $preset = ""; |
|
|
|
|
|
|
|
|
private $redis = null; |
|
|
private $redis = null; |
|
|
@ -197,6 +202,12 @@ class FfmpegService { |
|
|
Log::info("filesize: " . $fileInfo["filename"]); |
|
|
Log::info("filesize: " . $fileInfo["filename"]); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
$fileSha = sha1_file($pathFile); |
|
|
|
|
|
$existItem = EncodeRecord::where("file_hash_sha", $fileSha)->first(); |
|
|
|
|
|
if ($existItem != null) { |
|
|
|
|
|
Log::info("$pathFile has already encode by h265 return and path is {$existItem["file_path"]}"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
if ($this->getRedis()->sismember("hasEncode", $fileInfo["filename"]) || $this->checkFileEncodeType($pathFile)) { |
|
|
if ($this->getRedis()->sismember("hasEncode", $fileInfo["filename"]) || $this->checkFileEncodeType($pathFile)) { |
|
|
$this->getRedis()->sadd("hasEncode", $fileInfo["filename"]); |
|
|
$this->getRedis()->sadd("hasEncode", $fileInfo["filename"]); |
|
|
Log::info("$pathFile has already encode by h265 return"); |
|
|
Log::info("$pathFile has already encode by h265 return"); |
|
|
@ -210,7 +221,7 @@ class FfmpegService { |
|
|
$mtime = date("Y-m-d H:i:s", filemtime($pathFile)); |
|
|
$mtime = date("Y-m-d H:i:s", filemtime($pathFile)); |
|
|
// dump("$pathFile modify at $mtime is before 2021-07-19 00:00:00");
|
|
|
// dump("$pathFile modify at $mtime is before 2021-07-19 00:00:00");
|
|
|
} |
|
|
} |
|
|
if (ends_with($fileInfo["filename"], "-x265")) { |
|
|
|
|
|
|
|
|
if (Str::endsWith($fileInfo["filename"], "-x265")) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
$targetFile = $fileInfo["dirname"] . DIRECTORY_SEPARATOR . $fileInfo["filename"] . '-x265' . '.' . self::DEFAULT_EXTENSION; |
|
|
$targetFile = $fileInfo["dirname"] . DIRECTORY_SEPARATOR . $fileInfo["filename"] . '-x265' . '.' . self::DEFAULT_EXTENSION; |
|
|
@ -228,6 +239,12 @@ class FfmpegService { |
|
|
} else { |
|
|
} else { |
|
|
$preset = " -preset ultrafast"; |
|
|
$preset = " -preset ultrafast"; |
|
|
} |
|
|
} |
|
|
|
|
|
$dimension = $this->getDimension($pathFile); |
|
|
|
|
|
if (Str::startsWith($pathFile, "/mnt/e/rec/") && App::environment() == "txy4" && (($dimension->getWidth() == 854 && $dimension->getHeight() == 480)||($dimension->getWidth() == 480 && $dimension->getHeight() == 854))) { |
|
|
|
|
|
Log::info("$pathFile is vip useless cover skip and delete"); |
|
|
|
|
|
unlink($pathFile); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
if ($this->getDimension($pathFile)->getWidth() > 3840) { |
|
|
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 -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/software/ffmpeg -i " . escapeshellarg($pathFile) . " {$preset} -c:v libx265 -x265-params pools=8 -vtag hvc1 -vf \"scale=4096:-1\" " . escapeshellarg($targetFile) . " && echo 'ok'"); |
|
|
$result = shell_exec("/Users/shixuesen/Downloads/software/ffmpeg -i " . escapeshellarg($pathFile) . " {$preset} -c:v libx265 -x265-params pools=8 -vtag hvc1 -vf \"scale=4096:-1\" " . escapeshellarg($targetFile) . " && echo 'ok'"); |
|
|
@ -257,6 +274,11 @@ class FfmpegService { |
|
|
unlink($pathFile); |
|
|
unlink($pathFile); |
|
|
rename($targetFile, $pathFile); |
|
|
rename($targetFile, $pathFile); |
|
|
} |
|
|
} |
|
|
|
|
|
$encodeRecord = new EncodeRecord(); |
|
|
|
|
|
$encodeRecord->file_hash_sha = $fileSha; |
|
|
|
|
|
$encodeRecord->file_path = pathinfo($pathFile, PATHINFO_DIRNAME); |
|
|
|
|
|
$encodeRecord->file_name = pathinfo($pathFile, PATHINFO_BASENAME); |
|
|
|
|
|
$encodeRecord->save(); |
|
|
} |
|
|
} |
|
|
$this->getRedis()->del("encode:lock:" . $fileInfo["filename"]); |
|
|
$this->getRedis()->del("encode:lock:" . $fileInfo["filename"]); |
|
|
} |
|
|
} |
|
|
@ -383,6 +405,12 @@ class FfmpegService { |
|
|
return $dimensions; |
|
|
return $dimensions; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getMeta($file, $key) |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->ffprobe |
|
|
|
|
|
->format($file); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param bool $needRemoveAfterEncode |
|
|
* @param bool $needRemoveAfterEncode |
|
|
*/ |
|
|
*/ |
|
|
@ -411,4 +439,14 @@ class FfmpegService { |
|
|
return $this->needRemoveExistFiles; |
|
|
return $this->needRemoveExistFiles; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function isCheckFileEncodeType(): bool |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->checkFileEncodeType; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function setCheckFileEncodeType(bool $checkFileEncodeType): void |
|
|
|
|
|
{ |
|
|
|
|
|
$this->checkFileEncodeType = $checkFileEncodeType; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |