Passed
Push — master ( b23da5...cc1845 )
by Amin
04:10
created

CommandBuilder::getInputOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
13
namespace Streaming;
14
15
16
use FFMpeg\Filters\Audio\SimpleFilter;
17
use FFMpeg\Format\VideoInterface;
18
19
class CommandBuilder
20
{
21
    /** @var Media */
22
    private $media;
23
24
    /** @var \FFMpeg\Filters\FiltersCollection */
25
    private $filters;
26
27
    /** @var \FFMpeg\Driver\FFMpegDriver */
28
    private $driver;
29
30
    /**
31
     * CommandBuilder constructor.
32
     * @param Media $media
33
     */
34
    public function __construct(Media $media)
35
    {
36
        $this->media = $media;
37
        $this->filters = clone $this->media->getFiltersCollection();
0 ignored issues
show
Bug introduced by
The method getFiltersCollection() does not exist on Streaming\Media. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

37
        $this->filters = clone $this->media->/** @scrutinizer ignore-call */ getFiltersCollection();
Loading history...
Documentation Bug introduced by
It seems like clone $this->media->getFiltersCollection() of type FFMpeg\Media\Video or Streaming\Media is incompatible with the declared type FFMpeg\Filters\FiltersCollection of property $filters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
        $this->driver = clone $this->media->getFFMpegDriver();
0 ignored issues
show
Bug introduced by
The method getFFMpegDriver() does not exist on Streaming\Media. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

38
        $this->driver = clone $this->media->/** @scrutinizer ignore-call */ getFFMpegDriver();
Loading history...
Documentation Bug introduced by
It seems like clone $this->media->getFFMpegDriver() of type FFMpeg\Media\Video or Streaming\Media is incompatible with the declared type FFMpeg\Driver\FFMpegDriver of property $driver.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
    }
40
41
    /**
42
     * @param VideoInterface $format
43
     * @param string $path
44
     * @return array
45
     * @TODO: optimize this function
46
     */
47
    public function build(VideoInterface $format, string $path): array
48
    {
49
        $commands = [];
50
        $this->filters->add(new SimpleFilter($format->getExtraParams(), 10));
51
52
        if ($this->driver->getConfiguration()->has('ffmpeg.threads')) {
53
            $this->filters->add(new SimpleFilter(['-threads', $this->driver->getConfiguration()->get('ffmpeg.threads')]));
54
        }
55
56
        foreach ($this->filters as $filter) {
57
            $commands = array_merge($this->getInputOptions(), $filter->apply($this->media->baseMedia(), $format));
58
        }
59
        array_push($commands, $path);
60
61
        return $commands;
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    private function getInputOptions(): array
68
    {
69
        $path = $this->media->getPathfile();
0 ignored issues
show
Bug introduced by
The method getPathfile() does not exist on Streaming\Media. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

69
        /** @scrutinizer ignore-call */ 
70
        $path = $this->media->getPathfile();
Loading history...
70
        $input_options = Utiles::arrayToFFmpegOpt($this->media->getInputOptions());
71
72
        return array_merge($input_options, ['-y', '-i', $path]);
73
    }
74
}