Skip to content

Commit 91f9dd6

Browse files
renew readme
1 parent 2f0598b commit 91f9dd6

File tree

1 file changed

+67
-87
lines changed

1 file changed

+67
-87
lines changed

README.md

Lines changed: 67 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,43 @@
88
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/blob/master/LICENSE)
99
[![Latest Version on Packagist](https://img.shields.io/packagist/v/aminyazdanpanah/php-ffmpeg-video-streaming.svg?style=flat-square)](https://packagist.org/packages/aminyazdanpanah/php-ffmpeg-video-streaming)
1010

11+
## Overview
1112
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.
1213

13-
- [Full Documentation](https://video.aminyazdanpanah.com/)
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.
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+
18+
**Contents**
19+
- [Installation](#installation)
20+
- [Required Libraries](#required-libraries)
21+
- [Installing Package](#installing-package)
22+
- [Usage](#usage)
23+
- [Configuration](#configuration)
24+
- [Opening a File](#opening-a-file)
25+
- [From Local](#1-from-local)
26+
- [From Cloud](#2-from-cloud)
27+
- [DASH](#dash)
28+
- [Create DASH Files](#create-dash-files)
29+
- [Transcoding(DASH)](#transcodingdash)
30+
- [HLS](#hls)
31+
- [Create HLS Files](#create-hls-files)
32+
- [Transcoding(HLS)](#transcodinghls)
33+
- [Encrypted HLS](#encrypted-hls)
34+
- [Other Advanced Features](#other-advanced-features)
35+
- [Extracting image](#extracting-image)
36+
- [Watermark](#watermark)
37+
- [Several Open Source Players](#several-open-source-players)
38+
- [Contributing](#contributing)
39+
- [Security](#security)
40+
- [Reporting Bugs](#reporting-bugs)
41+
- [Credits](#credits)
42+
- [License](#license)
1443

15-
- ****NOTE:**** 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.
1644

45+
## Installation
1746

18-
## Required Libraries
47+
### Required Libraries
1948

2049
This library requires a working FFMpeg. You will need both FFMpeg and FFProbe binaries to use it.
2150
- Getting FFmpeg: https://ffmpeg.org/download.html
@@ -24,8 +53,8 @@ Also, for HLS encryption you will need a working OpenSSL:
2453
- Getting OpenSSL: https://www.openssl.org/source/
2554
- Getting OpenSSL(Windows): https://slproweb.com/products/Win32OpenSSL.html
2655

27-
## Installation
2856

57+
### Installing Package
2958
This version of the package is only compatible with PHP 7.1.0 and later.
3059

3160
Install the package via composer:
@@ -34,43 +63,8 @@ Install the package via composer:
3463
composer require aminyazdanpanah/php-ffmpeg-video-streaming
3564
```
3665

37-
## Basic Usage
38-
39-
``` php
40-
require_once 'vendor/autoload.php';
41-
42-
// the path to a video or it can be a URL
43-
$input_path = '/var/www/media/videos/test.mp4';// or "https://www.aminyazdanpanah.com/my_sweetie.mp4"
44-
45-
//You can transcode videos using a callback method.
46-
//If you do not want to transcode video, do not pass it(it can be null).
47-
$listener = function ($audio, $format, $percentage) {
48-
echo "$percentage% is transcoded\n";
49-
};
50-
51-
//The path you want to save your files.
52-
//Also, it can be null - the default path is the input path.
53-
$output_path_dash = '/var/www/media/videos/test/dash/output.mpd'; //or null
54-
$output_path_hls = null; //or '/var/www/media/videos/test/hls/output.m3u8';
55-
$output_path_encrypted_hls = '/var/www/media/videos/test/hls/output.m3u8'; // or null
56-
57-
//Path to acceess the key on your website.
58-
// NOTE: It is highly recommended to protect the key using a token or a session/cookie.
59-
$url_to_key = "https://www.aminyazdanpanah.com/enc.key";
60-
//Path to save the random key on your server.
61-
$path_to_save_key = "/var/www/media/keys/my_key/enc.key";
62-
63-
$result_dash = dash($input_path, $output_path_dash, $listener); //Create dash files.
64-
$result_hls = hls($input_path, $output_path_hls, $listener, $hls_key_info); //Create hls files.
65-
$result_encrypted_hls = encrypted_hls($input_path, $output_path_encrypted_hls, $listener, $url_to_key, $path_to_save_key); //Create encrypted hls files
66-
67-
//dupm the results
68-
var_dump($result_dash, $result_hls, $result_encrypted_hls);
69-
```
70-
7166
## Usage
72-
73-
- [Full Documentation](https://video.aminyazdanpanah.com/)
67+
You can find Full Documentation **[here](https://video.aminyazdanpanah.com/).**
7468

7569
### Configuration
7670

@@ -87,7 +81,6 @@ $config = [
8781
$ffmpeg = Streaming\FFMpeg::create($config);
8882
```
8983

90-
9184
### Opening a File
9285

9386
There are two ways to open a file:
@@ -111,10 +104,9 @@ Also, the path to save the file, the method of request, and [request options](ht
111104
### DASH
112105
**[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.
113106

114-
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.
107+
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)
115108

116-
- [Learn more](https://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP)
117-
#### Auto Create DASH Files
109+
#### Create DASH Files
118110
``` php
119111
$video->DASH()
120112
->HEVC() // Format of the video. For Using another format, see Traits\Formats
@@ -123,9 +115,7 @@ $video->DASH()
123115
->save(); // It can be passed a path to the method or it can be null
124116
```
125117

126-
127-
#### Create Representations Manually
128-
Create multi-representations video files using `Representation` object:
118+
Also, You can create multi-representations video files using `Representation` object:
129119

130120
``` php
131121
$rep_1 = (new Representation())->setKiloBitrate(800)->setResize(1080 , 720);
@@ -141,7 +131,7 @@ $video->DASH()
141131
```
142132

143133

144-
#### Transcoding
134+
#### Transcoding(DASH)
145135

146136
You can transcode videos using the `on` method in the format class.
147137

@@ -170,18 +160,18 @@ For more information about **[FFMpeg](https://ffmpeg.org/)** and its **[dash opt
170160

171161
**[HTTP Live Streaming (also known as HLS)](https://en.wikipedia.org/wiki/HTTP_Live_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.
172162

173-
HLS resembles MPEG-DASH in that it works by breaking the overall stream into a sequence of small HTTP-based file downloads, each download loading one short chunk of an overall potentially unbounded transport stream. A list of available streams, encoded at different bit rates, is sent to the client using an extended M3U playlist.
174-
175-
- [Learn more](https://en.wikipedia.org/wiki/HTTP_Live_Streaming)
163+
HLS resembles MPEG-DASH in that it works by breaking the overall stream into a sequence of small HTTP-based file downloads, each download loading one short chunk of an overall potentially unbounded transport stream. A list of available streams, encoded at different bit rates, is sent to the client using an extended M3U playlist. [Learn more](https://en.wikipedia.org/wiki/HTTP_Live_Streaming)
176164

165+
#### Create HLS Files
166+
Create HLS files based on original video(auto generate qualities).
177167
``` php
178168
$video->HLS()
179169
->X264()
180170
->autoGenerateRepresentations() // Auto generate representations
181171
->save(); // It can be passed a path to the method or it can be null
182172
```
183173

184-
Create multi-qualities video files using `Representation` object:
174+
Create multi-qualities video files using `Representation` object(set bit-rate and size manually):
185175

186176
``` php
187177
$rep_1 = (new Representation())->setKiloBitrate(1000)->setResize(1080 , 720);
@@ -199,7 +189,7 @@ $video->HLS()
199189
```
200190
See [HLS options](https://ffmpeg.org/ffmpeg-formats.html#hls-2) for more information.
201191

202-
#### Transcoding
192+
#### Transcoding(HLS)
203193

204194
``` php
205195
$format = new Streaming\Format\X264();
@@ -228,36 +218,34 @@ Getting OpenSSL(Windows): https://slproweb.com/products/Win32OpenSSL.html
228218

229219
You need to pass both 'URL to Key' and a path to save a random key:
230220
``` php
231-
//Path to save a random key on your server
232-
$save_as = "/var/www/my_website_project/storage/enc.key";
221+
//A path you want to save a random key on your server
222+
$save_to = "/var/www/my_website_project/storage/keys/enc.key";
233223

234-
//Path to access the key on your website
235-
$url = "https://www.aminyazdanpanah.com/enc.key";
224+
//A URL (or a path) to access the key on your website
225+
$url = "https://www.aminyazdanpanah.com/keys/enc.key";// or "/keys/enc.key";
236226

237227
$video->HLS()
238228
->X264()
239-
->generateRandomKeyInfo($url, $save_as)
229+
->generateRandomKeyInfo($url, $save_to)
240230
->autoGenerateRepresentations()
241231
->save('/var/www/media/videos/hls/test.m3u8');
242232
```
243-
- **Note:** Alternatively, you can generate a key info using another library and pass the path to the `setHlsKeyInfoFile` method.
244-
- **NOTE:** It is very important to protect your key on your website using a token or a session/cookie(****It is highly recommended****).
245-
246-
(e.x. https://wwww.aminyazdanpanah.com/enc.key?tk=J5HLhi97Tjk4N).
247-
233+
- **Note:** Alternatively, you can generate a key info using another library and pass the path of key info to the `setHlsKeyInfoFile` method.
234+
- **NOTE:** It is very important to protect your key on your website using a token or a session/cookie(****It is highly recommended****).
248235
- **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.
249236

250237
### Other Advanced Features
251-
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.
238+
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.
252239

253-
- [Full PHP-FFMpeg Documentation](https://github.com/PHP-FFMpeg/PHP-FFMpeg#documentation)
240+
For exploring other advanced features, please read the [Full PHP-FFMpeg Documentation](https://github.com/PHP-FFMpeg/PHP-FFMpeg#documentation).
254241

255242
``` php
256243
$ffmpeg = Streaming\FFMpeg::create()
257244
$video = $$ffmpeg->fromURL("https://www.aminyazdanpanah.com/my_sweetie.mp4", "/var/wwww/media/my/new/video.mp4");
258245
```
246+
259247
#### Extracting image
260-
ou can extract a frame at any timecode using the `FFMpeg\Media\Video::frame` method.
248+
You can extract a frame at any timecode using the `FFMpeg\Media\Video::frame` method.
261249

262250
``` php
263251
$video
@@ -269,15 +257,6 @@ $video
269257
->save(new FFMpeg\Format\Video\X264(), '/path/to/new/file');
270258
```
271259

272-
#### Clip
273-
Cuts the video at a desired point. Use input seeking method. It is faster option than use filter clip.
274-
275-
``` php
276-
$clip = $video->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(30), FFMpeg\Coordinate\TimeCode::fromSeconds(15));
277-
$clip->filters()->resize(new FFMpeg\Coordinate\Dimension(320, 240), FFMpeg\Filters\Video\ResizeFilter::RESIZEMODE_INSET, true);
278-
$clip->save(new FFMpeg\Format\Video\X264(), 'video.avi');
279-
```
280-
281260
#### Watermark
282261
Watermark a video with a given image.
283262

@@ -292,19 +271,20 @@ $video
292271
```
293272

294273
## Several Open Source Players
295-
296-
- DASH and HLS on Web: [Flowplayer](https://flowplayer.com/)
274+
You can use these player to play your packaged videos
275+
- **WEB**
276+
- DASH and HLS: [Plyr](https://github.com/sampotts/plyr)
277+
- DASH and HLS: [MediaElement.js](https://github.com/mediaelement/mediaelement)
278+
- DASH and HLS: [Clappr](https://github.com/clappr/clappr)
279+
- DASH and HLS: [Flowplayer](https://flowplayer.com/)
280+
- DASH and HLS: [Shaka Player](https://github.com/google/shaka-player)
281+
- DASH and HLS: [videojs-http-streaming (VHS)](https://github.com/videojs/http-streaming)
282+
- DASH: [dash.js](https://github.com/Dash-Industry-Forum/dash.js)
283+
- HLS: [hls.js](https://github.com/video-dev/hls.js)
284+
285+
- **Android**
286+
- DASH and HLS: [ExoPlayer](https://github.com/google/ExoPlayer)
297287

298-
- DASH and HLS on Web: [Shaka Player](https://github.com/google/shaka-player)
299-
300-
- DASH and HLS on Web: [videojs-http-streaming (VHS)](https://github.com/videojs/http-streaming)
301-
302-
- DASH on Web: [dash.js](https://github.com/Dash-Industry-Forum/dash.js)
303-
304-
- HLS on Web: [hls.js](https://github.com/video-dev/hls.js)
305-
306-
- DASH and HLS on Android: [ExoPlayer](https://github.com/google/ExoPlayer)
307-
308288
## Contributing
309289

310290
I'd love your help in improving, correcting, adding to the specification.

0 commit comments

Comments
 (0)