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\AutoReps; |
15
|
|
|
use Streaming\Exception\InvalidArgumentException; |
16
|
|
|
use Streaming\RepresentationInterface; |
17
|
|
|
use Streaming\RepsCollection; |
18
|
|
|
|
19
|
|
|
trait Representations |
20
|
|
|
{ |
21
|
|
|
/** @var RepsCollection */ |
22
|
|
|
protected $reps; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* add a representation |
26
|
|
|
* @param RepresentationInterface $rep |
27
|
|
|
* @return $this |
28
|
|
|
*/ |
29
|
|
|
public function addRepresentation(RepresentationInterface $rep) |
30
|
|
|
{ |
31
|
|
|
$this->reps->add($rep); |
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* add representations using an array |
37
|
|
|
* @param array $reps |
38
|
|
|
* @return $this |
39
|
|
|
*/ |
40
|
|
|
public function addRepresentations(array $reps) |
41
|
|
|
{ |
42
|
|
|
array_walk($reps, [$this, 'addRepresentation']); |
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array|null $sides |
48
|
|
|
* @param array|null $k_bitrate |
49
|
|
|
* @param bool $acceding_order |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function autoGenerateRepresentations(array $sides = null, array $k_bitrate = null, bool $acceding_order = true) |
53
|
|
|
{ |
54
|
|
|
if (!$this->format) { |
55
|
|
|
throw new InvalidArgumentException('First you must set the format of the video'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$reps = new AutoReps($this->getMedia(), $this->getFormat(), $sides, $k_bitrate); |
|
|
|
|
59
|
|
|
$reps->sort($acceding_order); |
60
|
|
|
|
61
|
|
|
foreach ($reps as $rep) { |
62
|
|
|
$this->addRepresentation($rep); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return RepsCollection |
70
|
|
|
*/ |
71
|
|
|
public function getRepresentations(): RepsCollection |
72
|
|
|
{ |
73
|
|
|
return $this->reps; |
74
|
|
|
} |
75
|
|
|
} |