init
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Video\Model;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class Ffmpeg
|
||||
{
|
||||
public function __construct(private readonly Config $config)
|
||||
{
|
||||
}
|
||||
|
||||
public function createCover(string $videoFile, string $coverFile): void
|
||||
{
|
||||
$process = new Process([
|
||||
$this->config->getFfmpegBinary(),
|
||||
'-hide_banner',
|
||||
'-loglevel', 'error',
|
||||
'-ss', '1',
|
||||
'-i', $videoFile,
|
||||
'-frames:v', '1',
|
||||
'-q:v', '2',
|
||||
'-y',
|
||||
$coverFile,
|
||||
]);
|
||||
$process->setTimeout(60);
|
||||
|
||||
try {
|
||||
$process->run();
|
||||
} catch (\Throwable $e) {
|
||||
throw new LocalizedException(__('Unable to run ffmpeg: %1', $e->getMessage()));
|
||||
}
|
||||
|
||||
if (!$process->isSuccessful() || !is_file($coverFile) || filesize($coverFile) === 0) {
|
||||
throw new LocalizedException(
|
||||
__('ffmpeg failed to create the cover image: %1', trim($process->getErrorOutput()) ?: __('unknown error'))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user