Passed
Push — master ( 1e8bfe...85c284 )
by Sébastien
03:02
created

VideoThumbService::__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;
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
use Soluble\MediaTools\Video\ThumbServiceInterface;
13
14
class VideoThumbService implements ThumbServiceInterface
15
{
16
    use PathAssertionsTrait;
17
18
    /** @var FFMpegConfig */
19
    protected $ffmpegConfig;
20
21 2
    public function __construct(FFMpegConfig $ffmpegConfig)
22
    {
23 2
        $this->ffmpegConfig = $ffmpegConfig;
24 2
    }
25
26
    /**
27
     * @param null|VideoFilterInterface $videoFilter
28
     *
29
     * @throws FileNotFoundException
30
     */
31 2
    public function makeThumbnail(string $videoFile, string $outputFile, float $time = 0.0, ?VideoFilterInterface $videoFilter = null): void
32
    {
33 2
        $this->ensureFileExists($videoFile);
34
35 1
        if ($videoFilter === null) {
36 1
            $videoFilter = new EmptyVideoFilter();
37
        }
38
39 1
        $process = $this->ffmpegConfig->getProcess();
40
41 1
        $ffmpegCmd = $process->buildCommand(
42
            [
43 1
                ($time > 0.0) ? sprintf('-ss %s', $time) : '', // putting time in front is much more efficient
44 1
                sprintf('-i %s', escapeshellarg($videoFile)),  // input filename
45 1
                $videoFilter->getFFMpegCLIArgument(),                // add -vf yadif,nlmeans
46 1
                '-frames:v 1',
47 1
                '-q:v 2',
48 1
                '-y', // tell to overwrite
49 1
                sprintf('%s', escapeshellarg($outputFile)),
50
            ]
51
        );
52
53 1
        $process->runCommand($ffmpegCmd);
54 1
    }
55
}
56