YadifVideoFilter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @see       https://github.com/soluble-io/soluble-mediatools for the canonical repository
7
 *
8
 * @copyright Copyright (c) 2018-2020 Sébastien Vanvelthem. (https://github.com/belgattitude)
9
 * @license   https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT
10
 */
11
12
namespace Soluble\MediaTools\Video\Filter;
13
14
use Soluble\MediaTools\Video\Filter\Type\FFMpegVideoFilterInterface;
15
use Soluble\MediaTools\Video\Filter\Type\VideoDeinterlacerInterface;
16
17
final class YadifVideoFilter implements FFMpegVideoFilterInterface, VideoDeinterlacerInterface
18
{
19
    public const DEFAULT_MODE   = 0;
20
    public const DEFAULT_PARITY = -1;
21
    public const DEFAULT_DEINT  = 0;
22
23
    /** @var array<string, int> */
24
    private $defaultOptions = [
25
        'mode'   => self::DEFAULT_MODE,
26
        'parity' => self::DEFAULT_PARITY,
27
        'deint'  => self::DEFAULT_DEINT,
28
    ];
29
30
    /** @var array<string, int> */
31
    private $options = [];
32
33
    /**
34
     * @param int $mode   The interlacing mode to adopt (0, send_frame Output one frame for each frame)
35
     * @param int $parity default=-1 Enable automatic detection of field parity. 0:
36
     * @param int $deint  Specify which frames to deinterlace (0: all - Deinterlace all frames.)
37
     */
38 7
    public function __construct(int $mode = self::DEFAULT_MODE, int $parity = self::DEFAULT_PARITY, int $deint = self::DEFAULT_DEINT)
39
    {
40 7
        $this->options = array_merge($this->defaultOptions, [
41 7
            'mode'   => $mode,
42 7
            'parity' => $parity,
43 7
            'deint'  => $deint,
44
        ]);
45 7
    }
46
47 7
    public function getFFmpegCLIValue(): string
48
    {
49 7
        $yadifArg = sprintf(
50 7
            'yadif=mode=%s:parity=%s:deint=%s',
51 7
            $this->options['mode'],
52 7
            $this->options['parity'],
53 7
            $this->options['deint']
54
        );
55
56 7
        return $yadifArg;
57
    }
58
}
59