Passed
Push — master ( 20660a...ab558f )
by Amin
02:37
created

ffmpeg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 1
b 1
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
use FFMpeg\FFProbe;
13
use Psr\Log\LoggerInterface;
14
use Streaming\Exception\StreamingExceptionInterface;
15
use Streaming\FFMpeg;
16
use Streaming\Format\HEVC;
17
use Streaming\Format\X264;
18
19
if (!function_exists('dash')) {
20
    @trigger_error('dash method is deprecated and will be removed in a future release. Use Streaming\DASH instead', E_USER_DEPRECATED);
21
22
    /**
23
     * Auto generate dash MPD file
24
     *
25
     * @param string $input_path
26
     * @param string|null $save_path
27
     * @param callable $listener
28
     * @return mixed
29
     * @deprecated this method is deprecated
30
     */
31
    // @TODO: should be removed in the next releases.
32
    function dash(string $input_path, string $save_path = null, callable $listener = null)
33
    {
34
35
        $format = new HEVC();
36
37
        if (is_callable($listener)) {
38
            $format->on('progress', $listener);
0 ignored issues
show
Bug introduced by
It seems like $listener can also be of type null; however, parameter $listener of Evenement\EventEmitter::on() does only seem to accept callable, 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

38
            $format->on('progress', /** @scrutinizer ignore-type */ $listener);
Loading history...
39
        }
40
41
        try {
42
            if (filter_var($input_path, FILTER_VALIDATE_URL)) {
43
                $video = FFMpeg::create()->fromURL($input_path);
0 ignored issues
show
Deprecated Code introduced by
The function Streaming\FFMpeg::fromURL() has been deprecated: this method is deprecated ( Ignorable by Annotation )

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

43
                $video = /** @scrutinizer ignore-deprecated */ FFMpeg::create()->fromURL($input_path);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
44
            } else {
45
                $video = FFMpeg::create()->open($input_path);
46
            }
47
48
            return $video->DASH()
49
                ->setFormat($format)
50
                ->autoGenerateRepresentations()
51
                ->setAdaption('id=0,streams=v id=1,streams=a')
52
                ->save($save_path);
53
        } catch (StreamingExceptionInterface $e) {
54
            return "Failed: error: " . $e->getMessage();
55
        }
56
    }
57
}
58
59
if (!function_exists('hls')) {
60
    @trigger_error('hls method is deprecated and will be removed in a future release. Use Streaming\HLS instead', E_USER_DEPRECATED);
61
62
    /**
63
     * Auto generate HLS M3U8 file
64
     *
65
     * @param string $input_path
66
     * @param string|null $save_path
67
     * @param callable|null $listener
68
     * @param string $hls_key
69
     * @return mixed
70
     * @deprecated this method is deprecated
71
     */
72
    // @TODO: should be removed in the next releases.
73
    function hls(string $input_path, string $save_path = null, callable $listener = null, $hls_key = "")
74
    {
75
        $format = new X264();
76
77
        if (is_callable($listener)) {
78
            $format->on('progress', $listener);
0 ignored issues
show
Bug introduced by
It seems like $listener can also be of type null; however, parameter $listener of Evenement\EventEmitter::on() does only seem to accept callable, 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

78
            $format->on('progress', /** @scrutinizer ignore-type */ $listener);
Loading history...
79
        }
80
81
        try {
82
            if (filter_var($input_path, FILTER_VALIDATE_URL)) {
83
                $video = FFMpeg::create()->fromURL($input_path);
0 ignored issues
show
Deprecated Code introduced by
The function Streaming\FFMpeg::fromURL() has been deprecated: this method is deprecated ( Ignorable by Annotation )

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

83
                $video = /** @scrutinizer ignore-deprecated */ FFMpeg::create()->fromURL($input_path);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
84
            } else {
85
                $video = FFMpeg::create()->open($input_path);
86
            }
87
88
            return $video->HLS()
89
                ->setFormat($format)
90
                ->autoGenerateRepresentations()
91
                ->setHlsKeyInfoFile($hls_key)
92
                ->save($save_path);
93
        } catch (StreamingExceptionInterface $e) {
94
            return "Failed: error: " . $e->getMessage();
95
        }
96
    }
97
}
98
99
if (!function_exists('encrypted_hls')) {
100
    @trigger_error('encrypted_hls method is deprecated and will be removed in a future release. Use Streaming\HLS instead', E_USER_DEPRECATED);
101
102
    /**
103
     * Auto generate HLS M3U8 file
104
     *
105
     * @param string $input_path
106
     * @param string | null $url
107
     * @param string $key_path
108
     * @param string|null $save_path
109
     * @param callable|null $listener
110
     * @return mixed
111
     * @deprecated this method is deprecated
112
     */
113
    // @TODO: should be removed in the next releases.
114
    function encrypted_hls(string $input_path, string $url, string $key_path, string $save_path = null, callable $listener = null)
115
    {
116
        $format = new X264();
117
118
        if (is_callable($listener)) {
119
            $format->on('progress', $listener);
0 ignored issues
show
Bug introduced by
It seems like $listener can also be of type null; however, parameter $listener of Evenement\EventEmitter::on() does only seem to accept callable, 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

119
            $format->on('progress', /** @scrutinizer ignore-type */ $listener);
Loading history...
120
        }
121
122
        try {
123
            if (filter_var($input_path, FILTER_VALIDATE_URL)) {
124
                $video = FFMpeg::create()->fromURL($input_path);
0 ignored issues
show
Deprecated Code introduced by
The function Streaming\FFMpeg::fromURL() has been deprecated: this method is deprecated ( Ignorable by Annotation )

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

124
                $video = /** @scrutinizer ignore-deprecated */ FFMpeg::create()->fromURL($input_path);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
125
            } else {
126
                $video = FFMpeg::create()->open($input_path);
127
            }
128
129
            return $video->HLS()
130
                ->setFormat($format)
131
                ->autoGenerateRepresentations()
132
                ->generateRandomKeyInfo($url, $key_path)
133
                ->save($save_path);
134
        } catch (StreamingExceptionInterface $e) {
135
            return "Failed: error: " . $e->getMessage();
136
        }
137
    }
138
}
139
140
if (!function_exists('ffmpeg')) {
141
142
    /**
143
     * @param array $config
144
     * @param LoggerInterface|null $logger
145
     * @param FFProbe|null $probe
146
     * @return FFMpeg
147
     */
148
    function ffmpeg($config = array(), LoggerInterface $logger = null, FFProbe $probe = null)
149
    {
150
        return Streaming\FFMpeg::create($config, $logger, $probe);
151
    }
152
}