X264::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 17
rs 9.9666
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\Format;
13
14
final class X264 extends StreamFormat
15
{
16
    private const MODULUS = 2;
17
18
    /**
19
     * X264 constructor.
20
     * @param string $video_codec
21
     * @param string $audio_codec
22
     * @param bool $default_init_opts
23
     */
24
    public function __construct($video_codec = 'libx264', string $audio_codec = 'aac', bool $default_init_opts = true)
25
    {
26
        $this
27
            ->setVideoCodec($video_codec)
28
            ->setAudioCodec($audio_codec);
29
30
        /**
31
         * set the default value of h264 codec options
32
         * see https://ffmpeg.org/ffmpeg-codecs.html#Options-28 for more information about options
33
         * return array
34
         */
35
        if ($default_init_opts) {
36
            $this->setAdditionalParameters([
37
                'bf' => 1,
38
                'keyint_min' => 25,
39
                'g' => 250,
40
                'sc_threshold' => 40
41
            ]);
42
        }
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function getAvailableAudioCodecs()
49
    {
50
        return ['aac', 'libvo_aacenc', 'libfaac', 'libmp3lame', 'libfdk_aac'];
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function getAvailableVideoCodecs()
57
    {
58
        return ['libx264', 'h264', 'h264_afm', 'h264_nvenc'];
59
    }
60
61
    /**
62
     * @return int
63
     */
64
    public function getModulus()
65
    {
66
        return static::MODULUS;
67
    }
68
69
    /**
70
     * Returns true if the current format supports B-Frames.
71
     *
72
     * @see https://wikipedia.org/wiki/Video_compression_picture_types
73
     *
74
     * @return Boolean
75
     */
76
    public function supportBFrames()
77
    {
78
        return true;
79
    }
80
}