Browse Source

modify ffmpeg

feature/new_bilibili_and_instagram_sxs20191126
shixuesen 4 years ago
parent
commit
fd8a046677
5 changed files with 257 additions and 7 deletions
  1. +3
    -0
      .idea/php.xml
  2. +1
    -0
      app/Console/Commands/CommonTest.php
  3. +34
    -5
      app/Services/FfmpegService.php
  4. +1
    -0
      composer.json
  5. +218
    -2
      composer.lock

+ 3
- 0
.idea/php.xml View File

@ -169,6 +169,9 @@
<path value="$PROJECT_DIR$/vendor/mnapoli/front-yaml" /> <path value="$PROJECT_DIR$/vendor/mnapoli/front-yaml" />
<path value="$PROJECT_DIR$/vendor/symfony/yaml" /> <path value="$PROJECT_DIR$/vendor/symfony/yaml" />
<path value="$PROJECT_DIR$/vendor/spatie/yaml-front-matter" /> <path value="$PROJECT_DIR$/vendor/spatie/yaml-front-matter" />
<path value="$PROJECT_DIR$/vendor/neutron/temporary-filesystem" />
<path value="$PROJECT_DIR$/vendor/alchemy/binary-driver" />
<path value="$PROJECT_DIR$/vendor/php-ffmpeg/php-ffmpeg" />
</include_path> </include_path>
</component> </component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" /> <component name="PhpProjectSharedConfiguration" php_language_level="7.1" />


+ 1
- 0
app/Console/Commands/CommonTest.php View File

@ -46,6 +46,7 @@ class CommonTest extends Command
date_default_timezone_set('PRC'); date_default_timezone_set('PRC');
$path = $this->argument("path"); $path = $this->argument("path");
$service = new FfmpegService(); $service = new FfmpegService();
// $service->checkFileEncodeType();exit;
$service->processDir(trim($path));exit; $service->processDir(trim($path));exit;
$cache = Cache::driver("redis"); $cache = Cache::driver("redis");
$cache->tags(["aaa", "bbb"])->put("key1", "value1"); $cache->tags(["aaa", "bbb"])->put("key1", "value1");


+ 34
- 5
app/Services/FfmpegService.php View File

@ -6,6 +6,7 @@ use App\Utils\FileUtils;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Mhor\MediaInfo\MediaInfo; use Mhor\MediaInfo\MediaInfo;
use FFMpeg\FFProbe;
@ -14,11 +15,21 @@ class FfmpegService
private $mediainfo; private $mediainfo;
private $ffprobe;
public function __construct() public function __construct()
{ {
$this->mediainfo = new MediaInfo(); $this->mediainfo = new MediaInfo();
$this->mediainfo->setConfig('use_oldxml_mediainfo_output_format', true); $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/泡泡条纹袜/") public function handleVideos($dir = "/Users/shixuesen/Documents/tmp/柚木/2017/泡泡条纹袜/")
@ -93,13 +104,17 @@ class FfmpegService
if (!$this->checkFileSize($pathFile)) { if (!$this->checkFileSize($pathFile)) {
return; 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)); $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; return;
} else { } else {
$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 after 2021-07-19 00:00:00");
dump("$pathFile modify at $mtime is before 2021-07-19 00:00:00");
} }
$fileInfo = pathinfo($pathFile); $fileInfo = pathinfo($pathFile);
if (ends_with($fileInfo["filename"], "-x265")) { if (ends_with($fileInfo["filename"], "-x265")) {
@ -108,6 +123,9 @@ class FfmpegService
if (Redis::sismember("unneed", $fileInfo["filename"])) { if (Redis::sismember("unneed", $fileInfo["filename"])) {
return; return;
} }
if (Redis::get("stopFlag") != null) {
return;
}
$targetFile = $fileInfo["dirname"] . '/' .$fileInfo["filename"] . '-x265'. '.' . $fileInfo["extension"]; $targetFile = $fileInfo["dirname"] . '/' .$fileInfo["filename"] . '-x265'. '.' . $fileInfo["extension"];
if (is_file($targetFile)) { if (is_file($targetFile)) {
unlink($pathFile); unlink($pathFile);
@ -217,14 +235,25 @@ class FfmpegService
public function checkFileSize($file, $size = 1): bool 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; return true;
} }
$fileSize = FileUtils::humanFilesize(filesize($file)); $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; 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";
}


+ 1
- 0
composer.json View File

@ -29,6 +29,7 @@
"monolog/monolog": "^1.24", "monolog/monolog": "^1.24",
"netresearch/jsonmapper": "^1.6", "netresearch/jsonmapper": "^1.6",
"norkunas/youtube-dl-php": "^1.4", "norkunas/youtube-dl-php": "^1.4",
"php-ffmpeg/php-ffmpeg": "^0.18.0",
"protoqol/prequel": "^1.22", "protoqol/prequel": "^1.22",
"ps/image-optimizer": "^2.0", "ps/image-optimizer": "^2.0",
"qcloud/cos-sdk-v5": ">=1.0", "qcloud/cos-sdk-v5": ">=1.0",


+ 218
- 2
composer.lock View File

@ -4,8 +4,80 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "7dcd4159bc96ec62d11f8ee396e25a1b",
"content-hash": "8df7e68982ce393eba0eb816afef15e4",
"packages": [ "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", "name": "barryvdh/laravel-ide-helper",
"version": "v2.6.6", "version": "v2.6.6",
@ -4274,6 +4346,56 @@
}, },
"time": "2019-08-15T19:41:25+00:00" "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", "name": "nexmo/client",
"version": "1.9.1", "version": "1.9.1",
@ -4637,6 +4759,100 @@
}, },
"time": "2018-07-02T15:55:56+00:00" "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", "name": "php-http/guzzle6-adapter",
"version": "v1.1.1", "version": "v1.1.1",
@ -11922,5 +12138,5 @@
"ext-json": "*" "ext-json": "*"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.0.0"
"plugin-api-version": "2.1.0"
} }

Loading…
Cancel
Save