Completed
Branch v7 (f01542)
by Pascal
08:46
created

AdvancedOutputMapping::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 5
1
<?php
2
3
namespace Pbmedia\LaravelFFMpeg\FFMpeg;
4
5
use FFMpeg\Format\FormatInterface;
6
use FFMpeg\Format\Video\DefaultVideo;
7
use FFMpeg\Media\AdvancedMedia;
8
use Pbmedia\LaravelFFMpeg\Filesystem\Media;
9
10
class AdvancedOutputMapping
11
{
12
    private array $outs;
13
    private FormatInterface $format;
14
    private Media $output;
15
    private bool $forceDisableAudio = false;
16
    private bool $forceDisableVideo = false;
17
18
    public function __construct(array $outs, FormatInterface $format, Media $output, $forceDisableAudio = false, $forceDisableVideo = false)
19
    {
20
        $this->outs              = $outs;
21
        $this->format            = $format;
22
        $this->output            = $output;
23
        $this->forceDisableAudio = $forceDisableAudio;
24
        $this->forceDisableVideo = $forceDisableVideo;
25
    }
26
27
    /**
28
     * Applies the attributes to the format and specifies the video
29
     * bitrate if it's missing.
30
     */
31
    public function apply(AdvancedMedia $advancedMedia): void
32
    {
33
        if ($this->format instanceof DefaultVideo) {
34
            $parameters = $this->format->getAdditionalParameters() ?: [];
0 ignored issues
show
Bug introduced by
The method getAdditionalParameters() does not exist on FFMpeg\Format\FormatInterface. It seems like you code against a sub-type of FFMpeg\Format\FormatInterface such as FFMpeg\Format\VideoInterface or FFMpeg\Format\Video\DefaultVideo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
            $parameters = $this->format->/** @scrutinizer ignore-call */ getAdditionalParameters() ?: [];
Loading history...
35
36
            if (!in_array('-b:v', $parameters)) {
37
                $parameters = ['-b:v', $this->format->getKiloBitrate() . 'k'] + $parameters;
0 ignored issues
show
Bug introduced by
The method getKiloBitrate() does not exist on FFMpeg\Format\FormatInterface. It seems like you code against a sub-type of FFMpeg\Format\FormatInterface such as FFMpeg\Format\VideoInterface or FFMpeg\Format\Video\DefaultVideo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
                $parameters = ['-b:v', $this->format->/** @scrutinizer ignore-call */ getKiloBitrate() . 'k'] + $parameters;
Loading history...
38
            }
39
40
            $this->format->setAdditionalParameters($parameters);
0 ignored issues
show
Bug introduced by
The method setAdditionalParameters() does not exist on FFMpeg\Format\FormatInterface. It seems like you code against a sub-type of FFMpeg\Format\FormatInterface such as FFMpeg\Format\Video\DefaultVideo or FFMpeg\Format\Video\DefaultVideo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            $this->format->/** @scrutinizer ignore-call */ 
41
                           setAdditionalParameters($parameters);
Loading history...
41
        }
42
43
        $advancedMedia->map($this->outs, $this->format, $this->output->getLocalPath(), $this->forceDisableAudio, $this->forceDisableVideo);
44
    }
45
46
    public function getFormat(): FormatInterface
47
    {
48
        return $this->format;
49
    }
50
51
    public function getOutputMedia(): Media
52
    {
53
        return $this->output;
54
    }
55
56
    public function hasOut(string $out): bool
57
    {
58
        return in_array($out, $this->outs);
59
    }
60
}
61