Passed
Push — master ( 4422d3...1f3291 )
by Pascal
19:42 queued 15:59
created

AdvancedOutputMapping   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormat() 0 3 1
A hasOut() 0 3 1
A apply() 0 13 4
A __construct() 0 7 1
A getOutputMedia() 0 3 1
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg;
4
5
use FFMpeg\Format\FormatInterface;
6
use FFMpeg\Format\Video\DefaultVideo;
7
use FFMpeg\Media\AdvancedMedia;
8
use ProtoneMedia\LaravelFFMpeg\Filesystem\Media;
9
10
class AdvancedOutputMapping
11
{
12
    /**
13
     * @var array
14
     */
15
    private $outs;
16
17
    /**
18
     * @var \FFMpeg\Format\FormatInterface
19
     */
20
    private $format;
21
22
    /**
23
     * @var \ProtoneMedia\LaravelFFMpeg\Filesystem\Media
24
     */
25
    private $output;
26
27
    /**
28
     * @var boolean
29
     */
30
    private $forceDisableAudio = false;
31
32
    /**
33
     * @var boolean
34
     */
35
    private $forceDisableVideo = false;
36
37
    public function __construct(array $outs, FormatInterface $format, Media $output, bool $forceDisableAudio = false, bool $forceDisableVideo = false)
38
    {
39
        $this->outs              = $outs;
40
        $this->format            = $format;
41
        $this->output            = $output;
42
        $this->forceDisableAudio = $forceDisableAudio;
43
        $this->forceDisableVideo = $forceDisableVideo;
44
    }
45
46
    /**
47
     * Applies the attributes to the format and specifies the video
48
     * bitrate if it's missing.
49
     */
50
    public function apply(AdvancedMedia $advancedMedia): void
51
    {
52
        if ($this->format instanceof DefaultVideo) {
53
            $parameters = $this->format->getAdditionalParameters() ?: [];
54
55
            if (!in_array('-b:v', $parameters)) {
56
                $parameters = ['-b:v', $this->format->getKiloBitrate() . 'k'] + $parameters;
57
            }
58
59
            $this->format->setAdditionalParameters($parameters);
60
        }
61
62
        $advancedMedia->map($this->outs, $this->format, $this->output->getLocalPath(), $this->forceDisableAudio, $this->forceDisableVideo);
63
    }
64
65
    public function getFormat(): FormatInterface
66
    {
67
        return $this->format;
68
    }
69
70
    public function getOutputMedia(): Media
71
    {
72
        return $this->output;
73
    }
74
75
    public function hasOut(string $out): bool
76
    {
77
        return in_array($out, $this->outs);
78
    }
79
}
80