Formats::x264()   A
last analyzed

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
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 4
rs 10
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
     * @param bool $default_init_opts
30
     * @return $this
31
     */
32
    public function x264(string $video_codec = 'libx264', string $audio_codec = 'aac', bool $default_init_opts = true)
33
    {
34
        $this->setFormat(new X264($video_codec, $audio_codec, $default_init_opts));
35
        return $this;
36
    }
37
38
    /**
39
     * @param string $video_codec
40
     * @param string|null $audio_codec
41
     * @param bool $default_init_opts
42
     * @return $this
43
     */
44
    public function hevc(string $video_codec = 'libx265', string $audio_codec = 'aac', bool $default_init_opts = true)
45
    {
46
        $this->setFormat(new HEVC($video_codec, $audio_codec, $default_init_opts));
47
        return $this;
48
    }
49
50
    /**
51
     * @param string $video_codec
52
     * @param string|null $audio_codec
53
     * @param bool $default_init_opts
54
     * @return $this
55
     */
56
    public function vp9(string $video_codec = 'libvpx-vp9', string $audio_codec = 'aac', bool $default_init_opts = true)
57
    {
58
        $this->setFormat(new VP9($video_codec, $audio_codec, $default_init_opts));
59
        return $this;
60
    }
61
62
    /**
63
     * @return VideoInterface
64
     */
65
    public function getFormat(): VideoInterface
66
    {
67
        return $this->format;
68
    }
69
70
    /**
71
     * @param mixed $format
72
     * @return $this
73
     * @throws InvalidArgumentException
74
     */
75
    public function setFormat(StreamFormat $format)
76
    {
77
        $this->format = $format;
78
        return $this;
79
    }
80
}