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

Formats::x264()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
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
namespace Streaming\Traits;
13
14
use FFMpeg\Format\VideoInterface;
15
use Streaming\Exception\InvalidArgumentException;
16
use Streaming\Format\HEVC;
17
use Streaming\Format\StreamFormat;
18
use Streaming\Format\VP9;
19
use Streaming\Format\X264;
20
21
trait Formats
22
{
23
    /** @var VideoInterface | \FFMpeg\Format\Video\DefaultVideo */
24
    protected $format;
25
26
    /**
27
     * @param string $video_codec
28
     * @param string|null $audio_codec
29
     * @return $this
30
     */
31
    public function x264(string $video_codec = 'libx264', string $audio_codec = null)
32
    {
33
        $this->setFormat(new X264($video_codec, $audio_codec));
0 ignored issues
show
Bug introduced by
It seems like $audio_codec can also be of type string; however, parameter $audio_codec of Streaming\Format\X264::__construct() does only seem to accept null, maybe add an additional type check? ( Ignorable by Annotation )

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

33
        $this->setFormat(new X264($video_codec, /** @scrutinizer ignore-type */ $audio_codec));
Loading history...
34
        return $this;
35
    }
36
37
    /**
38
     * @param string $video_codec
39
     * @param string|null $audio_codec
40
     * @return $this
41
     */
42
    public function hevc(string $video_codec = 'libx265', string $audio_codec = null)
43
    {
44
        $this->setFormat(new HEVC($video_codec, $audio_codec));
45
        return $this;
46
    }
47
48
    /**
49
     * @param string $video_codec
50
     * @param string|null $audio_codec
51
     * @return $this
52
     */
53
    public function vp9(string $video_codec = 'libvpx-vp9', string $audio_codec = null)
54
    {
55
        $this->setFormat(new VP9($video_codec, $audio_codec));
56
        return $this;
57
    }
58
59
    /**
60
     * @return VideoInterface
61
     */
62
    public function getFormat(): VideoInterface
63
    {
64
        return $this->format;
65
    }
66
67
    /**
68
     * @param mixed $format
69
     * @return $this
70
     * @throws InvalidArgumentException
71
     */
72
    public function setFormat($format)
73
    {
74
        if (!$format instanceof StreamFormat) {
75
            throw new InvalidArgumentException("The format must be instance of 'Streaming\Format\StreamFormat'");
76
        }
77
78
        $this->format = $format;
79
        return $this;
80
    }
81
}