You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to Apple's HTTP Live Streaming (HLS) solution, MPEG-DASH works by breaking the content into a sequence of small HTTP-based file segments, each segment containing a short interval of playback time of content that is potentially many hours in duration, such as a movie or the live broadcast of a sports event. The content is made available at a variety of different bit rates, i.e., alternative segments encoded at different bit rates covering aligned short intervals of playback time. While the content is being played back by an MPEG-DASH client, the client uses a bit rate adaptation (ABR) algorithm to automatically select the segment with the highest bit rate possible that can be downloaded in time for playback without causing stalls or re-buffering events in the playback. The current MPEG-DASH reference client dash.js offers both buffer-based (BOLA) and hybrid (DYNAMIC) bit rate adaptation algorithms. Thus, an MPEG-DASH client can seamlessly adapt to changing network conditions and provide high quality playback with fewer stalls or re-buffering events. [Learn more](https://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP)
94
94
95
-
Create DASH Files:
95
+
Create DASH files:
96
96
```php
97
97
$video->DASH()
98
98
->HEVC() // Format of the video. Alternatives: X264() and VP9()
99
99
->autoGenerateRepresentations() // Auto generate representations
100
100
->setAdaption('id=0,streams=v id=1,streams=a') // Set the adaption.
101
101
->save(); // It can be passed a path to the method or it can be null
102
102
```
103
-
You can also create multi-representations video files using the `Representation` object:
103
+
Generate representations manually:
104
104
```php
105
105
use Streaming\Representation;
106
106
107
-
$rep_1 = (new Representation())->setKiloBitrate(800)->setResize(1280 , 720);
108
-
$rep_2 = (new Representation())->setKiloBitrate(300)->setResize(640 , 360);
107
+
$rep_144 = (new Representation)->setKiloBitrate(95)->setResize(256 , 144);
108
+
$rep_240 = (new Representation)->setKiloBitrate(150)->setResize(426 , 240);
109
+
$rep_360 = (new Representation)->setKiloBitrate(276)->setResize(640 , 360);
110
+
$rep_480 = (new Representation)->setKiloBitrate(750)->setResize(854 , 480);
111
+
$rep_720 = (new Representation)->setKiloBitrate(2048)->setResize(1280 , 720);
112
+
$rep_1080 = (new Representation)->setKiloBitrate(4096)->setResize(1920 , 1080);
113
+
$rep_1440 = (new Representation)->setKiloBitrate(6096)->setResize(2560 , 1440);
109
114
110
115
$video->DASH()
111
116
->HEVC()
112
-
->addRepresentation($rep_1) // Add a representation
113
-
->addRepresentation($rep_2)
117
+
->addRepresentation($rep_144)// add a representation
118
+
->addRepresentation($rep_240)
119
+
->addRepresentation($rep_360)
120
+
->addRepresentation($rep_480)
121
+
->addRepresentation($rep_720)
122
+
->addRepresentation($rep_1080)
123
+
->addRepresentation($rep_1440)
114
124
->setAdaption('id=0,streams=v id=1,streams=a') // Set a adaption.
115
125
->save('/var/www/media/videos/dash-stream.mpd');
116
126
```
117
-
See **[DASH options](https://ffmpeg.org/ffmpeg-formats.html#dash-2)** for more information.
118
127
119
128
### HLS
120
129
**[HTTP Live Streaming (also known as HLS)](https://developer.apple.com/streaming/)** is an HTTP-based adaptive bitrate streaming communications protocol implemented by Apple Inc. as part of its QuickTime, Safari, OS X, and iOS software. Client implementations are also available in Microsoft Edge, Firefox and some versions of Google Chrome. Support is widespread in streaming media servers.
@@ -128,20 +137,20 @@ $video->HLS()
128
137
->autoGenerateRepresentations([720, 360]) // You can limit the numbers of representatons
129
138
->save();
130
139
```
131
-
Generate `Representation` object(set bit-rate and size manually):
140
+
Generate representations manually:
132
141
```php
133
142
use Streaming\Representation;
134
143
135
-
$rep_1 = (new Representation())->setKiloBitrate(1000)->setResize(1280 , 720);
136
-
$rep_2 = (new Representation())->setKiloBitrate(500)->setResize(854 , 480);
137
-
$rep_3 = (new Representation())->setKiloBitrate(200)->setResize(640 , 360);
144
+
$rep_360 = (new Representation)->setKiloBitrate(276)->setResize(640 , 360);
145
+
$rep_480 = (new Representation)->setKiloBitrate(750)->setResize(854 , 480);
146
+
$rep_720 = (new Representation)->setKiloBitrate(2048)->setResize(1280 , 720);
138
147
139
148
$video->HLS()
140
149
->X264()
141
150
->setHlsBaseUrl('https://bucket.s3-us-west-1.amazonaws.com/videos') // Add a base URL
142
-
->addRepresentation($rep_1)
143
-
->addRepresentation($rep_2)
144
-
->addRepresentation($rep_3)
151
+
->addRepresentation($rep_360)
152
+
->addRepresentation($rep_480)
153
+
->addRepresentation($rep_720)
145
154
->setHlsTime(5) // Set Hls Time. Default value is 10
146
155
->setHlsAllowCache(false) // Default value is true
147
156
->save();
@@ -151,7 +160,7 @@ $video->HLS()
151
160
#### Encrypted HLS
152
161
The encryption process requires some kind of secret (key) together with an encryption algorithm. HLS uses AES in cipher block chaining (CBC) mode. This means each block is encrypted using the ciphertext of the preceding block. [Learn more](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation)
153
162
154
-
You need to pass both `URL to the key` and `path to save a random key` to the `generateRandomKeyInfo` method:
163
+
You need to pass both `A URL to the key` and `A path to save a random key on your local machine` to the `generateRandomKeyInfo` method:
155
164
```php
156
165
//A path you want to save a random key on your server
You can pass a local path to the `save` method. If there was no directory in the path, then the package auto makes the directory.
@@ -231,7 +238,7 @@ $hls->save();
231
238
#### 2. To Clouds
232
239
You can save your files to a cloud by passing an array of cloud configuration to the `save` method.
233
240
234
-
In **[this page](https://video.aminyazdanpanah.com/start/open-clouds)**, you will find some examples of opening a file from**[Amazon Web Services (AWS)](https://aws.amazon.com/)**, **[Google Cloud Storage](https://console.cloud.google.com/storage)**, **[Microsoft Azure Storage](https://azure.microsoft.com/en-us/features/storage-explorer/)**, and a custom cloud.
241
+
In **[this page](https://video.aminyazdanpanah.com/start/open-clouds)**, you will find some examples of saving files to**[Amazon Web Services (AWS)](https://aws.amazon.com/)**, **[Google Cloud Storage](https://console.cloud.google.com/storage)**, **[Microsoft Azure Storage](https://azure.microsoft.com/en-us/features/storage-explorer/)**, and a custom cloud.
echo $metadata['filename']; // path to metadata.json
254
261
var_dump($metadata['metadata']); // dump all metadata
255
262
```
256
-
**NOTE:** It won't save metadata to clouds because of some security concerns.
263
+
**NOTE:** It won't save metadata to clouds because of some security reasons.
257
264
258
265
### Other Advanced Features
259
266
You can easily use other advanced features in the **[PHP-FFMpeg](https://github.com/PHP-FFMpeg/PHP-FFMpeg)** library. In fact, when you open a file with the `open` method(or `openFromCloud`), it holds the Media object that belongs to the PHP-FFMpeg.
@@ -268,7 +275,7 @@ You can extract a frame at any timecode using the `FFMpeg\Media\Video::frame` me
To see more example, please go to the **[PHP-FFMpeg Documentation](https://github.com/PHP-FFMpeg/PHP-FFMpeg)**
278
+
To see more example, please vist the **[PHP-FFMpeg Documentation](https://github.com/PHP-FFMpeg/PHP-FFMpeg)** page.
272
279
273
280
## Asynchronous Task Execution
274
281
Packaging process will may take a while and it is recommended to run it in the background(or in a cloud e.g. Google Cloud). There are some libraries that you can use.
0 commit comments