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
Copy file name to clipboardExpand all lines: README.md
+73-3Lines changed: 73 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ This package provides integration with **[PHP-FFMpeg](https://github.com/PHP-FFM
20
20
-[Opening a Resource](#opening-a-resource)
21
21
-[DASH](#dash)
22
22
-[HLS](#hls)
23
-
-[Encrypted HLS](#encrypted-hls)
23
+
-[DRM (Encrypted HLS)](#drm-encrypted-hls)
24
24
-[Transcoding](#transcoding)
25
25
-[Saving Files](#saving-files)
26
26
-[Metadata Extraction](#metadata-extraction)
@@ -160,10 +160,14 @@ $video->HLS()
160
160
```
161
161
**NOTE:** You cannot use HEVC and VP9 formats for HLS packaging.
162
162
163
-
#### Encrypted HLS
163
+
#### DRM (Encrypted HLS)
164
164
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)
165
165
166
166
You must specify a path to save a random key to your local machine and also a URL(or a path) to access the key on your website(the key you will save must be accessible from your website). You must pass both these parameters to the `encryption` method:
167
+
168
+
##### Single Key
169
+
The following code generates a key for all TS files.
170
+
167
171
```php
168
172
//A path you want to save a random key to your server
The code below, allows you to encrypt each TS file with a new encryption key. This can improve security and allows for more flexibility. You can also modify the code to use a different key for each set of segments(i.e. if 10 TS files has been generated then rotate the key) or you can generate a new encryption key at every periodic time(i.e. every 10 seconds).
189
+
190
+
First you need to create a listener class that is extended by `Evenement\EventEmitter` and is implemented by `Alchemy\BinaryDriver\Listeners\ListenerInterface`. This allows you to get all lines of FFmpeg logs regardless of the type of them.
191
+
```php
192
+
class LineListener extends Evenement\EventEmitter implements Alchemy\BinaryDriver\Listeners\ListenerInterface
193
+
{
194
+
private $event;
195
+
196
+
public function __construct($event = 'line')
197
+
{
198
+
$this->event = $event;
199
+
}
200
+
201
+
public function handle($type, $data)
202
+
{
203
+
foreach (explode(PHP_EOL, $data) as $line) {
204
+
$this->emit($this->event, [$line]);
205
+
}
206
+
}
207
+
208
+
public function forwardedEvents()
209
+
{
210
+
return [$this->event];
211
+
}
212
+
}
213
+
```
214
+
215
+
You can also use `Alchemy\BinaryDriver\Listeners\DebugListener` object instead and skip this step.
216
+
217
+
After that, you should pass an instance of the object to the `listen` method in the `FFMpegDriver` object and get the line of FFmpeg logs. When a new TS file has been created, you should generate a new encryption key and update the key info file.
**NOTE:** It is very important to protect your key on your website using a token or a session/cookie(**It is highly recommended**).
183
252
253
+
**NOTE:** However HLS supports AES encryption, that you can encrypt your streams, it is not a full DRM solution. If you want to use a full DRM solution, I recommend to try **[FairPlay Streaming](https://developer.apple.com/streaming/fps/)** solution which then securely exchange keys, and protect playback on devices.
184
254
185
255
### Transcoding
186
256
A format can also extend `FFMpeg\Format\ProgressableInterface` to get realtime information about the transcoding.
0 commit comments