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
This package provides an integration with [PHP-FFmpeg](https://github.com/PHP-FFMpeg/PHP-FFMpeg) and packages well-known live streaming techniques such as DASH and HLS. Also you can use DRM for HLS packaging.
13
13
14
14
- Before you get started, please read the FFMpeg Document found **[here](https://ffmpeg.org/ffmpeg-formats.html)**.
15
-
-**[Full API Documentation](https://video.aminyazdanpanah.com/)** is available describing all features and components.
15
+
-**[Full Documentation](https://video.aminyazdanpanah.com/)** is available describing all features and components.
16
16
- For DRM and encryption(DASH and HLS), I **strongly recommend** to try **[Shaka PHP](https://github.com/aminyazdanpanah/shaka-php)**, which is a great tool for this use case.
17
17
18
18
**Contents**
@@ -22,18 +22,13 @@ This package provides an integration with [PHP-FFmpeg](https://github.com/PHP-FF
Also, the path to save the file, the method of request, and [request options](http://docs.guzzlephp.org/en/stable/request-options.html) can be passed to the method.
103
98
99
+
#### 3. From Amazon S3
100
+
Amazon S3 or Amazon Simple Storage Service is a service offered by [Amazon Web Services (AWS)](https://aws.amazon.com/) that provides object storage through a web service interface. [learn more](https://en.wikipedia.org/wiki/Amazon_S3)
101
+
102
+
- For getting credentials, you need to have an AWS account or you can [create one](https://portal.aws.amazon.com/billing/signup#/start).
103
+
- Before you get started, please read the "AWS SDK for PHP" Document found **[here](https://aws.amazon.com/sdk-for-php/)**.
104
+
105
+
For downloading a file from Amazon S3, you need to pass an array as configuration, name of the bucket, and the key of your bucket to `fromS3` method:
106
+
107
+
```php
108
+
$config = [
109
+
'version' => 'latest',
110
+
'region' => 'us-west-1',
111
+
'credentials' => [
112
+
'key' => 'my-access-key-id',
113
+
'secret' => 'my-secret-access-key',
114
+
]
115
+
];
116
+
117
+
$bucket = "my-bucket-name";
118
+
$key = "/videos/my_sweetie.mp4";
119
+
120
+
$video = $ffmpeg->fromS3($config, $bucket, $key);
121
+
```
122
+
123
+
A path can also be passed to save the file on your local computer/server.
124
+
104
125
### DASH
105
126
**[Dynamic Adaptive Streaming over HTTP (DASH)](https://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP)**, also known as MPEG-DASH, is an adaptive bitrate streaming technique that enables high quality streaming of media content over the Internet delivered from conventional HTTP web servers.
106
127
@@ -109,7 +130,7 @@ Similar to Apple's HTTP Live Streaming (HLS) solution, MPEG-DASH works by breaki
109
130
#### Create DASH Files
110
131
```php
111
132
$video->DASH()
112
-
->HEVC() // Format of the video. For Using another format, see Traits\Formats
133
+
->HEVC() // Format of the video. Alternatives: X264() and VP9()
113
134
->autoGenerateRepresentations() // Auto generate representations
114
135
->setAdaption('id=0,streams=v id=1,streams=a') // Set the adaption.
115
136
->save(); // It can be passed a path to the method or it can be null
@@ -122,38 +143,13 @@ $rep_1 = (new Representation())->setKiloBitrate(800)->setResize(1080 , 720);
122
143
$rep_2 = (new Representation())->setKiloBitrate(300)->setResize(640 , 360);
123
144
124
145
$video->DASH()
125
-
->HEVC() // Format of the video.For Using another format, see Traits\Formats
146
+
->HEVC()
126
147
->addRepresentation($rep_1) // Add a representation
127
148
->addRepresentation($rep_2) // Add a representation
128
149
->setAdaption('id=0,streams=v id=1,streams=a') // Set a adaption.
129
-
->save(); // It can be passed a path to the method or it can be null
130
-
131
-
```
132
-
133
-
134
-
#### Transcoding(DASH)
135
-
136
-
You can transcode videos using the `on` method in the format class.
137
-
138
-
Transcoding progress can be monitored in realtime, see Format documentation in [FFMpeg documentation](https://github.com/PHP-FFMpeg/PHP-FFMpeg#documentation) for more information.
139
-
140
-
```php
141
-
$format = new Streaming\Format\HEVC();
142
-
143
-
$format->on('progress', function ($video, $format, $percentage) {
144
-
echo "$percentage% is transcoded\n";
145
-
});
146
-
147
-
$video->DASH()
148
-
->setFormat($format)
149
-
->autoGenerateRepresentations()
150
-
->setAdaption('id=0,streams=v id=1,streams=a')
151
-
->save('/var/www/media/videos/dash/test.mpd');
152
-
150
+
->save('/var/www/media/videos/dash/test.mpd'); // It can be passed a path to the method or it can be null
153
151
```
154
152
155
-
156
-
157
153
For more information about **[FFMpeg](https://ffmpeg.org/)** and its **[dash options](https://ffmpeg.org/ffmpeg-formats.html#dash-2)** please visit its website.
158
154
159
155
### HLS
@@ -187,22 +183,10 @@ $video->HLS()
187
183
->setHlsAllowCache(false) // Default value is true
188
184
->save();
189
185
```
190
-
See [HLS options](https://ffmpeg.org/ffmpeg-formats.html#hls-2) for more information.
191
186
192
-
#### Transcoding(HLS)
193
-
194
-
```php
195
-
$format = new Streaming\Format\X264();
196
-
197
-
$format->on('progress', function ($video, $format, $percentage) {
198
-
echo "$percentage% is transcoded\n";
199
-
});
187
+
**NOTE:** You cannot use HEVC and VP9 formats for HLS packaging.
200
188
201
-
$video->HLS()
202
-
->setFormat($format)
203
-
->autoGenerateRepresentations()
204
-
->save('/var/www/media/videos/dash/test.m3u8');
205
-
```
189
+
See [HLS options](https://ffmpeg.org/ffmpeg-formats.html#hls-2) for more information.
206
190
207
191
#### Encrypted HLS
208
192
@@ -234,6 +218,76 @@ $video->HLS()
234
218
-**NOTE:** It is very important to protect your key on your website using a token or a session/cookie(****It is highly recommended****).
235
219
-**NOTE:** For getting the benefit of the OpenSSL binary detection in windows, you need to add it to your system path otherwise, you have to pass the path to OpenSSL binary to the `generateRandomKeyInfo` method explicitly.
236
220
221
+
### Transcoding
222
+
223
+
You can transcode videos using the `on` method in the format class.
224
+
225
+
Transcoding progress can be monitored in realtime, see Format documentation in [FFMpeg documentation](https://github.com/PHP-FFMpeg/PHP-FFMpeg#documentation) for more information.
226
+
227
+
```php
228
+
$format = new Streaming\Format\HEVC();
229
+
230
+
$format->on('progress', function ($video, $format, $percentage) {
231
+
echo "$percentage% is transcoded\n";
232
+
});
233
+
234
+
$video->DASH()
235
+
->setFormat($format)
236
+
->autoGenerateRepresentations()
237
+
->setAdaption('id=0,streams=v id=1,streams=a')
238
+
->save();
239
+
```
240
+
241
+
HLS Transcoding:
242
+
243
+
```php
244
+
$format = new Streaming\Format\X264();
245
+
246
+
$format->on('progress', function ($video, $format, $percentage) {
247
+
echo "$percentage% is transcoded\n";
248
+
});
249
+
250
+
$video->HLS()
251
+
->setFormat($format)
252
+
->autoGenerateRepresentations()
253
+
->save('/var/www/media/videos/dash/test.m3u8');
254
+
```
255
+
256
+
### Save to Amazon S3
257
+
You can save and upload entire packaged video files to [Amazon S3](https://aws.amazon.com/). For uploading files, you need to have credentials.
258
+
259
+
```php
260
+
$config = [
261
+
'version' => 'latest',
262
+
'region' => 'us-west-1',
263
+
'credentials' => [
264
+
'key' => 'my-access-key-id',
265
+
'secret' => 'my-secret-access-key',
266
+
]
267
+
];
268
+
269
+
$dest = 's3://bucket';
270
+
```
271
+
272
+
Upload DASH files to Amazon Simple Storage Service:
273
+
```php
274
+
$video->DASH()
275
+
->HEVC()
276
+
->autoGenerateRepresentations()
277
+
->setAdaption('id=0,streams=v id=1,streams=a')
278
+
->saveToS3($config, $dest);
279
+
```
280
+
A filename can also be passed to save files on your local computer/server.
For more information, please read [AWS SDK for PHP](https://aws.amazon.com/sdk-for-php/) document.
290
+
237
291
### Other Advanced Features
238
292
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 `open` method(or `fromURL`), it holds the Media object that belongs to the PHP-FFMpeg.
0 commit comments