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\AutoRepresentations; |
15
|
|
|
use Streaming\Exception\InvalidArgumentException; |
16
|
|
|
use Streaming\Representation; |
17
|
|
|
|
18
|
|
|
trait Representations |
19
|
|
|
{ |
20
|
|
|
/** @var array */ |
21
|
|
|
protected $representations = []; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Representation $rep |
25
|
|
|
* @return $this |
26
|
|
|
* @deprecated Please use addRepresentations instead |
27
|
|
|
*/ |
28
|
|
|
public function addRepresentation(Representation $rep) |
29
|
|
|
{ |
30
|
|
|
@trigger_error('addRepresentation method is deprecated and will be removed in a future release. Use addRepresentations instead.', E_USER_DEPRECATED); |
31
|
|
|
$this->checkFormat(); |
32
|
|
|
$this->representations[] = $rep; |
33
|
|
|
|
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return $this |
39
|
|
|
*/ |
40
|
|
|
public function addRepresentations() |
41
|
|
|
{ |
42
|
|
|
$this->checkFormat(); |
43
|
|
|
$reps = func_get_args(); |
44
|
|
|
|
45
|
|
|
foreach ($reps as $rep) { |
46
|
|
|
if (!$rep instanceof Representation) { |
47
|
|
|
throw new InvalidArgumentException('It must be instance of Representation object'); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->representations = $reps; |
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
public function getRepresentations(): array |
59
|
|
|
{ |
60
|
|
|
return $this->representations; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param array $side_values |
65
|
|
|
* @param array|null $k_bitrate_values |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
|
|
public function autoGenerateRepresentations(array $side_values = null, array $k_bitrate_values = null) |
69
|
|
|
{ |
70
|
|
|
$this->checkFormat(); |
71
|
|
|
$this->representations = (new AutoRepresentations($this->getMedia()->probe(), $side_values, $k_bitrate_values))->get(); |
|
|
|
|
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* check whether format is set or nor |
78
|
|
|
*/ |
79
|
|
|
private function checkFormat() |
80
|
|
|
{ |
81
|
|
|
if (!$this->format) { |
82
|
|
|
throw new InvalidArgumentException('First you must set the format of the video'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |