Passed
Push — master ( 3ee3fe...b14545 )
by Amin
04:48
created

Formats::getFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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 Streaming\Exception\Exception;
15
use Streaming\Format\HEVC;
16
use Streaming\Format\Video;
17
use Streaming\Format\VP9;
18
use Streaming\Format\X264;
19
use FFMpeg\Format\FormatInterface;
20
21
trait Formats
22
{
23
    /** @var object */
24
    protected $format;
25
26
    /**
27
     * @param string $videoCodec
28
     * @return $this
29
     * @throws Exception
30
     */
31
    public function X264($videoCodec = 'libx264')
32
    {
33
        $this->setFormat(new X264($videoCodec));
34
        return $this;
35
    }
36
37
    /**
38
     * @param string $videoCodec
39
     * @return $this
40
     * @throws Exception
41
     */
42
    public function HEVC($videoCodec = 'libx265')
43
    {
44
        $this->setFormat(new HEVC($videoCodec));
45
        return $this;
46
    }
47
48
    /**
49
     * @param string $videoCodec
50
     * @return $this
51
     * @throws Exception
52
     */
53
    public function WebM($videoCodec = 'libvpx-vp9')
54
    {
55
        $this->setFormat(new VP9($videoCodec));
56
        return $this;
57
    }
58
59
    /**
60
     * @return FormatInterface|mixed
61
     */
62
    public function getFormat(): FormatInterface
63
    {
64
        return $this->format;
65
    }
66
67
    /**
68
     * @param mixed $format
69
     * @return $this
70
     * @throws Exception
71
     */
72
    public function setFormat($format)
73
    {
74
        if (!$format instanceof Video) {
75
            throw new Exception("Sorry! the format must be inherited from 'Streaming\Format\Video'");
76
        }
77
78
        $this->format = $format;
79
        return $this;
80
    }
81
}