|
1 | 1 | # 📼 PHP FFMPEG Video Streaming
|
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/aminyazdanpanah/PHP-FFmpeg-video-streaming)
|
4 |
| -[](https://packagist.org/packages/aminyazdanpanah/php-ffmpeg-video-streaming) |
| 4 | +[](https://ci.appveyor.com/project/aminyazdanpanah/php-ffmpeg-video-streaming) |
5 | 5 | [](https://scrutinizer-ci.com/g/aminyazdanpanah/PHP-FFmpeg-video-streaming/?branch=master)
|
6 |
| -[](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/blob/master/LICENSE) |
7 | 6 | [](https://scrutinizer-ci.com/code-intelligence)
|
8 | 7 | [](https://packagist.org/packages/aminyazdanpanah/php-ffmpeg-video-streaming)
|
9 |
| -[](https://ci.appveyor.com/project/aminyazdanpanah/php-ffmpeg-video-streaming) |
| 8 | +[](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/blob/master/LICENSE) |
| 9 | +[](https://packagist.org/packages/aminyazdanpanah/php-ffmpeg-video-streaming) |
10 | 10 |
|
11 | 11 | 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.
|
12 | 12 |
|
@@ -50,19 +50,21 @@ $listener = function ($audio, $format, $percentage) {
|
50 | 50 | //Also, it can be null-the default path is the input path.
|
51 | 51 | //These values are optional
|
52 | 52 | $output_path_dash = '/var/www/media/videos/test/dash/output.mpd'; //or null
|
53 |
| -$output_path_hls = null; //or '/var/www/media/videos/test/hls/output.m3u8' |
| 53 | +$output_path_hls = null; //or '/var/www/media/videos/test/hls/output.m3u8'; |
| 54 | +$output_path_encrypted_hls = '/var/www/media/videos/test/hls/output.m3u8'; // or null |
54 | 55 |
|
55 |
| -//The path to the key info for encrypted hls. |
56 |
| -//This value is optional. |
57 |
| -$url_to_key = "https://www.aminyazdanpanah.com/enc.key"; //Path to get the key on your website |
58 |
| -$path_to_save_key = "/var/www/media/keys/my_key/enc.key"; //Path to save the random key on your server |
59 |
| -$hls_key_info = new Streaming\KeyInfo($url_to_key, $path_to_save_key); |
| 56 | +//Path to acceess the key on your website. |
| 57 | +// NOTE: It is highly recommended to protect the key using a token or a session/cookie. |
| 58 | +$url_to_key = "https://www.aminyazdanpanah.com/enc.key"; |
| 59 | +//Path to save the random key on your server. |
| 60 | +$path_to_save_key = "/var/www/media/keys/my_key/enc.key"; |
60 | 61 |
|
61 | 62 | $result_dash = dash($input_path, $output_path_dash, $listener); //Create dash files.
|
62 | 63 | $result_hls = hls($input_path, $output_path_hls, $listener, $hls_key_info); //Create hls files.
|
| 64 | +$result_encrypted_hls = encrypted_hls($input_path, $output_path_encrypted_hls, $listener, $url_to_key, $path_to_save_key); //Create encrypted hls files |
63 | 65 |
|
64 | 66 | //dupm the results
|
65 |
| -var_dump($result_dash, $result_hls); |
| 67 | +var_dump($result_dash, $result_hls, $result_encrypted_hls); |
66 | 68 | ```
|
67 | 69 |
|
68 | 70 | ## Documentation
|
@@ -216,28 +218,30 @@ Streaming\FFMpeg::create()
|
216 | 218 |
|
217 | 219 | The encryption process requires some kind of secret (key) together with an encryption algorithm.
|
218 | 220 |
|
219 |
| -HLS uses AES in cipher block chaining (CBC) mode. This means each block is encrypted using the cipher text of the preceding block. [read more](http://hlsbook.net/how-to-encrypt-hls-video-with-ffmpeg/) |
| 221 | +HLS uses AES in cipher block chaining (CBC) mode. This means each block is encrypted using the cipher text of the preceding block. [learn more](http://hlsbook.net/how-to-encrypt-hls-video-with-ffmpeg/) |
220 | 222 |
|
221 | 223 | Before we can encrypt videos, we need an encryption key. However you can use any software that can generate key, this package requires a working OpenSSL to create the key:
|
222 | 224 |
|
223 |
| -``` php |
224 |
| -$url_to_key = "https://www.aminyazdanpanah.com/enc.key"; //Path to get the key on your website |
225 |
| -$path_to_save_key = "/var/www/media/keys/my_key/enc.key"; //Path to save the random key on your server |
226 |
| -$hls_key_info = new Streaming\KeyInfo($url_to_key, $path_to_save_key); |
227 |
| -``` |
228 |
| - - **NOTE:** It is recommended to protect your key on your website using a token or a session/cookie. |
| 225 | +Getting OpenSSL: https://www.openssl.org/source/ |
| 226 | + |
| 227 | +Getting OpenSSL(Windows): https://slproweb.com/products/Win32OpenSSL.html |
229 | 228 |
|
230 | 229 | The next step is to pass key info to `setHlsKeyInfoFile` method:
|
231 | 230 | ``` php
|
| 231 | +$url = "https://www.aminyazdanpanah.com/enc.key"; //Path to access the key on your website |
| 232 | +$path = "/var/www/media/keys/my_key/enc.key"; //Path to save the random key on your server |
| 233 | + |
232 | 234 | Streaming\FFMpeg::create()
|
233 | 235 | ->open('/var/www/media/videos/test.mp4')
|
234 | 236 | ->HLS()
|
235 | 237 | ->X264()
|
236 |
| - ->setHlsKeyInfoFile($hls_key_info) |
| 238 | + ->generateRandomKeyInfo($url, $path) |
237 | 239 | ->autoGenerateRepresentations()
|
238 | 240 | ->save('/var/www/media/videos/hls/test.m3u8');
|
239 | 241 | ```
|
240 |
| -- **Note:** Alternatively, you can generate a key info using another library and pass the path to the method. |
| 242 | +- **Note:** Alternatively, you can generate a key info using another library and pass the path to the `setHlsKeyInfoFile` method. |
| 243 | +- **NOTE:** It is highly recommended to protect your key on your website using a token or a session/cookie (e.x. https://wwww.aminyazdanpanah.com/enc.key?tk=J5HLhi97Tjk4N). |
| 244 | +- **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. |
241 | 245 |
|
242 | 246 | ### Other Advanced Features
|
243 | 247 | 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, it holds the Media object that belongs to the PHP-FFMpeg.
|
|
0 commit comments