<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
use App\Jobs\BilibiliEncode;
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
class QueuedFfmpegService {
|
|
|
|
public function processDir($path)
|
|
{
|
|
$files = scandir($path);
|
|
foreach ($files as $file) {
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store" || $file == "1762") {
|
|
continue;
|
|
}
|
|
$subDir = implode(DIRECTORY_SEPARATOR, [$path, $file]);
|
|
$isDir = is_dir($subDir);
|
|
if ($isDir) {
|
|
$this->processDir($subDir);
|
|
} else {
|
|
$this->addToQueue($subDir);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function addToQueue($file)
|
|
{
|
|
// BilibiliEncode::dispatch($file);
|
|
Redis::connection()->rpush("file_to_encode", $file);
|
|
// $result = Redis::publish("file_to_process", $file);
|
|
// echo $result;
|
|
}
|
|
|
|
public function processQueue()
|
|
{
|
|
$ffmpeg = new FfmpegService();
|
|
$ffmpeg->setNeedRemoveAfterEncode(true);
|
|
$ffmpeg->setNeedRemoveExistFiles(false);
|
|
$item = Redis::connection()->rpop("file_to_encode");
|
|
while ($item != null) {
|
|
echo $item . "\n";
|
|
$item = Redis::connection()->rpop("file_to_encode");
|
|
}
|
|
exit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// redis 订阅逻辑
|
|
// Redis::subscribe(["file_to_process"], function ($message) use ($ffmpeg) {
|
|
// echo $message;
|
|
// sleep(10);
|
|
// $ffmpeg->processVideo($message);
|
|
// });
|
|
}
|
|
}
|