Passed
Push — master ( 50f2bb...00ec2b )
by Sébastien
03:06
created

ThumbService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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