|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Soluble\MediaTools\Video; |
|
6
|
|
|
|
|
7
|
|
|
use Soluble\MediaTools\Config\FFMpegConfig; |
|
8
|
|
|
use Soluble\MediaTools\Exception\FileNotFoundException; |
|
9
|
|
|
use Soluble\MediaTools\Util\Assert\PathAssertionsTrait; |
|
10
|
|
|
use Soluble\MediaTools\Video\Filter\EmptyVideoFilter; |
|
11
|
|
|
use Soluble\MediaTools\Video\Filter\VideoFilterInterface; |
|
12
|
|
|
|
|
13
|
|
|
class ThumbService implements ThumbServiceInterface |
|
14
|
|
|
{ |
|
15
|
|
|
use PathAssertionsTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** @var FFMpegConfig */ |
|
18
|
|
|
protected $ffmpegConfig; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(FFMpegConfig $ffmpegConfig) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->ffmpegConfig = $ffmpegConfig; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function makeThumbnails(string $videoFile, string $outputFile, float $time = 0.0, VideoFilterInterface $videoFilter = null): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->ensureFileExists($videoFile); |
|
28
|
|
|
|
|
29
|
|
|
if ($videoFilter === null) { |
|
30
|
|
|
$videoFilter = new EmptyVideoFilter(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$process = $this->ffmpegConfig->getProcess(); |
|
34
|
|
|
|
|
35
|
|
|
$ffmpegCmd = $process->buildCommand( |
|
36
|
|
|
[ |
|
37
|
|
|
($time > 0.0) ? sprintf('-ss %s', $time) : '', // putting time in front is much more efficient |
|
38
|
|
|
sprintf('-i %s', escapeshellarg($videoFile)), // input filename |
|
39
|
|
|
$videoFilter->getFFMpegCLIArgument(), // add -vf yadif,nlmeans |
|
40
|
|
|
'-frames:v 1', |
|
41
|
|
|
'-q:v 2', |
|
42
|
|
|
'-y', // tell to overwrite |
|
43
|
|
|
sprintf('%s', escapeshellarg($outputFile)), |
|
44
|
|
|
] |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$process->runCommand($ffmpegCmd); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|