diff --git a/.idea/php.xml b/.idea/php.xml
index 3e60f53..58a22dd 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -169,6 +169,9 @@
+
+
+
diff --git a/app/Console/Commands/CommonTest.php b/app/Console/Commands/CommonTest.php
index e324563..635bcf0 100644
--- a/app/Console/Commands/CommonTest.php
+++ b/app/Console/Commands/CommonTest.php
@@ -46,6 +46,7 @@ class CommonTest extends Command
date_default_timezone_set('PRC');
$path = $this->argument("path");
$service = new FfmpegService();
+// $service->checkFileEncodeType();exit;
$service->processDir(trim($path));exit;
$cache = Cache::driver("redis");
$cache->tags(["aaa", "bbb"])->put("key1", "value1");
diff --git a/app/Services/FfmpegService.php b/app/Services/FfmpegService.php
index 095da9a..af05580 100644
--- a/app/Services/FfmpegService.php
+++ b/app/Services/FfmpegService.php
@@ -6,6 +6,7 @@ use App\Utils\FileUtils;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Mhor\MediaInfo\MediaInfo;
+use FFMpeg\FFProbe;
@@ -14,11 +15,21 @@ class FfmpegService
private $mediainfo;
+ private $ffprobe;
+
public function __construct()
{
$this->mediainfo = new MediaInfo();
$this->mediainfo->setConfig('use_oldxml_mediainfo_output_format', true);
+ $config = array(
+ 'ffmpeg.binarie' => '/usr/local/bin/ffmpeg',
+ 'ffprobe.binaries' => '/usr/local/bin/ffprobe',
+ 'timeout' => 3600,
+ 'ffmpeg.threads' => 12,
+ );
+ $this->ffprobe = FFProbe::create($config);
+
}
public function handleVideos($dir = "/Users/shixuesen/Documents/tmp/柚木/2017/泡泡条纹袜/")
@@ -93,13 +104,17 @@ class FfmpegService
if (!$this->checkFileSize($pathFile)) {
return;
}
- if (filemtime($pathFile) > strtotime("2021-07-19 00:00:00")) {
+ if ($this->checkFileEncodeType($pathFile)) {
+ Log::info("$pathFile has already encode by h265 return");
+ return;
+ }
+ if (filemtime($pathFile) > strtotime("2021-07-26 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");
+ dump("$pathFile modify at $mtime is after 2021-07-26 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");
+ dump("$pathFile modify at $mtime is before 2021-07-19 00:00:00");
}
$fileInfo = pathinfo($pathFile);
if (ends_with($fileInfo["filename"], "-x265")) {
@@ -108,6 +123,9 @@ class FfmpegService
if (Redis::sismember("unneed", $fileInfo["filename"])) {
return;
}
+ if (Redis::get("stopFlag") != null) {
+ return;
+ }
$targetFile = $fileInfo["dirname"] . '/' .$fileInfo["filename"] . '-x265'. '.' . $fileInfo["extension"];
if (is_file($targetFile)) {
unlink($pathFile);
@@ -217,14 +235,25 @@ class FfmpegService
public function checkFileSize($file, $size = 1): bool
{
- if (is_file($file) && filesize($file) > 50 * 1024 * 1024) {
+ if (is_file($file) && filesize($file) > 100 * 1024 * 1024) {
return true;
}
$fileSize = FileUtils::humanFilesize(filesize($file));
- echo "$file size < 100Mb filesize is $fileSize skip \n";
+ echo "$file size < 200Mb filesize is $fileSize skip \n";
return false;
}
+ public function checkFileEncodeType($file): bool
+ {
+
+ $codecName = $this->ffprobe
+ ->streams($file) // extracts streams informations
+ ->videos() // filters video streams
+ ->first() // returns the first video stream
+ ->get('codec_name');
+ return trim($codecName) == "hevc";
+ }
+
diff --git a/composer.json b/composer.json
index 13a4d00..9d8fbe9 100644
--- a/composer.json
+++ b/composer.json
@@ -29,6 +29,7 @@
"monolog/monolog": "^1.24",
"netresearch/jsonmapper": "^1.6",
"norkunas/youtube-dl-php": "^1.4",
+ "php-ffmpeg/php-ffmpeg": "^0.18.0",
"protoqol/prequel": "^1.22",
"ps/image-optimizer": "^2.0",
"qcloud/cos-sdk-v5": ">=1.0",
diff --git a/composer.lock b/composer.lock
index d325dcb..ef247a3 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,80 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "7dcd4159bc96ec62d11f8ee396e25a1b",
+ "content-hash": "8df7e68982ce393eba0eb816afef15e4",
"packages": [
+ {
+ "name": "alchemy/binary-driver",
+ "version": "v5.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/alchemy-fr/BinaryDriver.git",
+ "reference": "e0615cdff315e6b4b05ada67906df6262a020d22"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/alchemy-fr/BinaryDriver/zipball/e0615cdff315e6b4b05ada67906df6262a020d22",
+ "reference": "e0615cdff315e6b4b05ada67906df6262a020d22",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
+ "require": {
+ "evenement/evenement": "^3.0|^2.0|^1.0",
+ "php": ">=5.5",
+ "psr/log": "^1.0",
+ "symfony/process": "^2.3|^3.0|^4.0|^5.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^4.0|^5.0"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-0": {
+ "Alchemy": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Le Goff",
+ "email": "legoff.n@gmail.com"
+ },
+ {
+ "name": "Romain Neutron",
+ "email": "imprec@gmail.com",
+ "homepage": "http://www.lickmychip.com/"
+ },
+ {
+ "name": "Phraseanet Team",
+ "email": "info@alchemy.fr",
+ "homepage": "http://www.phraseanet.com/"
+ },
+ {
+ "name": "Jens Hausdorf",
+ "email": "mail@jens-hausdorf.de",
+ "homepage": "https://jens-hausdorf.de",
+ "role": "Maintainer"
+ }
+ ],
+ "description": "A set of tools to build binary drivers",
+ "keywords": [
+ "binary",
+ "driver"
+ ],
+ "support": {
+ "issues": "https://github.com/alchemy-fr/BinaryDriver/issues",
+ "source": "https://github.com/alchemy-fr/BinaryDriver/tree/master"
+ },
+ "time": "2020-02-12T19:35:11+00:00"
+ },
{
"name": "barryvdh/laravel-ide-helper",
"version": "v2.6.6",
@@ -4274,6 +4346,56 @@
},
"time": "2019-08-15T19:41:25+00:00"
},
+ {
+ "name": "neutron/temporary-filesystem",
+ "version": "3.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/romainneutron/Temporary-Filesystem.git",
+ "reference": "60e79adfd16f42f4b888e351ad49f9dcb959e3c2"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/romainneutron/Temporary-Filesystem/zipball/60e79adfd16f42f4b888e351ad49f9dcb959e3c2",
+ "reference": "60e79adfd16f42f4b888e351ad49f9dcb959e3c2",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
+ "require": {
+ "php": ">=5.6",
+ "symfony/filesystem": "^2.3 || ^3.0 || ^4.0 || ^5.0"
+ },
+ "require-dev": {
+ "symfony/phpunit-bridge": "^5.0.4"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-0": {
+ "Neutron": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Romain Neutron",
+ "email": "imprec@gmail.com"
+ }
+ ],
+ "description": "Symfony filesystem extension to handle temporary files",
+ "support": {
+ "issues": "https://github.com/romainneutron/Temporary-Filesystem/issues",
+ "source": "https://github.com/romainneutron/Temporary-Filesystem/tree/3.0"
+ },
+ "time": "2020-07-27T14:00:33+00:00"
+ },
{
"name": "nexmo/client",
"version": "1.9.1",
@@ -4637,6 +4759,100 @@
},
"time": "2018-07-02T15:55:56+00:00"
},
+ {
+ "name": "php-ffmpeg/php-ffmpeg",
+ "version": "v0.18.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/PHP-FFMpeg/PHP-FFMpeg.git",
+ "reference": "edc0a7729d8818ed883e77b3d26ceb6d49ec41de"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/PHP-FFMpeg/PHP-FFMpeg/zipball/edc0a7729d8818ed883e77b3d26ceb6d49ec41de",
+ "reference": "edc0a7729d8818ed883e77b3d26ceb6d49ec41de",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
+ "require": {
+ "alchemy/binary-driver": "^1.5 || ~2.0.0 || ^5.0",
+ "doctrine/cache": "^1.0",
+ "evenement/evenement": "^3.0 || ^2.0 || ^1.0",
+ "neutron/temporary-filesystem": "^2.1.1 || ^3.0",
+ "php": ">=5.3.9"
+ },
+ "require-dev": {
+ "silex/silex": "~1.0",
+ "symfony/phpunit-bridge": "^5.0.4",
+ "symfony/process": "2.8 || 3.3"
+ },
+ "suggest": {
+ "php-ffmpeg/extras": "A compilation of common audio & video drivers for PHP-FFMpeg"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "FFMpeg": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Romain Neutron",
+ "email": "imprec@gmail.com",
+ "homepage": "http://www.lickmychip.com/"
+ },
+ {
+ "name": "Phraseanet Team",
+ "email": "info@alchemy.fr",
+ "homepage": "http://www.phraseanet.com/"
+ },
+ {
+ "name": "Patrik Karisch",
+ "email": "patrik@karisch.guru",
+ "homepage": "http://www.karisch.guru"
+ },
+ {
+ "name": "Romain Biard",
+ "email": "romain.biard@gmail.com",
+ "homepage": "https://www.strime.io/"
+ },
+ {
+ "name": "Jens Hausdorf",
+ "email": "hello@jens-hausdorf.de",
+ "homepage": "https://jens-hausdorf.de"
+ }
+ ],
+ "description": "FFMpeg PHP, an Object Oriented library to communicate with AVconv / ffmpeg",
+ "keywords": [
+ "audio",
+ "audio processing",
+ "avconv",
+ "avprobe",
+ "ffmpeg",
+ "ffprobe",
+ "video",
+ "video processing"
+ ],
+ "support": {
+ "issues": "https://github.com/PHP-FFMpeg/PHP-FFMpeg/issues",
+ "source": "https://github.com/PHP-FFMpeg/PHP-FFMpeg/tree/v0.18.0"
+ },
+ "time": "2021-03-29T20:20:00+00:00"
+ },
{
"name": "php-http/guzzle6-adapter",
"version": "v1.1.1",
@@ -11922,5 +12138,5 @@
"ext-json": "*"
},
"platform-dev": [],
- "plugin-api-version": "2.0.0"
+ "plugin-api-version": "2.1.0"
}