Passed
Push — master ( 00ec2b...220eca )
by Sébastien
03:08 queued 47s
created

ThumbService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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\Util\Assert\PathAssertionsTrait;
9
use Soluble\MediaTools\Video\Filter\EmptyVideoFilter;
10
use Soluble\MediaTools\Video\Filter\VideoFilterInterface;
11
12
class ThumbService implements ThumbServiceInterface
13
{
14
    use PathAssertionsTrait;
15
16
    /** @var FFMpegConfig */
17
    protected $ffmpegConfig;
18
19 1
    public function __construct(FFMpegConfig $ffmpegConfig)
20
    {
21 1
        $this->ffmpegConfig = $ffmpegConfig;
22 1
    }
23
24 1
    public function makeThumbnails(string $videoFile, string $outputFile, float $time = 0.0, ?VideoFilterInterface $videoFilter = null): void
25
    {
26 1
        $this->ensureFileExists($videoFile);
27
28 1
        if ($videoFilter === null) {
29 1
            $videoFilter = new EmptyVideoFilter();
30
        }
31
32 1
        $process = $this->ffmpegConfig->getProcess();
33
34 1
        $ffmpegCmd = $process->buildCommand(
35
            [
36 1
                ($time > 0.0) ? sprintf('-ss %s', $time) : '', // putting time in front is much more efficient
37 1
                sprintf('-i %s', escapeshellarg($videoFile)),  // input filename
38 1
                $videoFilter->getFFMpegCLIArgument(),                // add -vf yadif,nlmeans
39 1
                '-frames:v 1',
40 1
                '-q:v 2',
41 1
                '-y', // tell to overwrite
42 1
                sprintf('%s', escapeshellarg($outputFile)),
43
            ]
44
        );
45
46 1
        $process->runCommand($ffmpegCmd);
47 1
    }
48
}
49