Skip to content

Commit e45cd3a

Browse files
- Bug fixes and other minor improvements
1 parent e3f8970 commit e45cd3a

File tree

5 files changed

+55
-36
lines changed

5 files changed

+55
-36
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ If applicable, add screenshots to help explain your problem.
2626
**Desktop/Server (please complete the following information):**
2727
- OS: [e.g. Linux]
2828
- Version [e.g. Ubuntu 18]
29-
- FFmpeg vesion
29+
- FFmpeg vesion [e.g. 4.1]
3030

3131
**Additional context**
3232
Add any other context about the problem here.

README.md

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# 📼 PHP FFMPEG Video Streaming
2-
32
[![Build Status](https://travis-ci.org/aminyazdanpanah/PHP-FFmpeg-video-streaming.svg?branch=master)](https://travis-ci.org/aminyazdanpanah/PHP-FFmpeg-video-streaming)
43
[![Build status](https://img.shields.io/appveyor/ci/aminyazdanpanah/PHP-FFmpeg-video-streaming/master.svg?style=flat&logo=appveyor)](https://ci.appveyor.com/project/aminyazdanpanah/php-ffmpeg-video-streaming)
54
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/aminyazdanpanah/PHP-FFmpeg-video-streaming/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/aminyazdanpanah/PHP-FFmpeg-video-streaming/?branch=master)
@@ -8,10 +7,10 @@
87
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/blob/master/LICENSE)
98

109
## Overview
11-
This package provides integration with **[PHP-FFmpeg](https://github.com/PHP-FFMpeg/PHP-FFMpeg)** and packages well-known online streaming techniques such as DASH and HLS. You can also use DRM for HLS packaging.
12-
- Before you get started, please read the FFMpeg Document found **[here](https://ffmpeg.org/ffmpeg-formats.html)**.
10+
This package provides integration with **[PHP-FFmpeg](https://github.com/PHP-FFMpeg/PHP-FFMpeg)** and packages media content for online streaming such as DASH and HLS. You can also use DRM for HLS packaging. There are options to open a file from clouds and also save files to clouds.
11+
- This package uses FFMpeg, so before you get started, take the time to read the **[FFMpeg documentation](https://ffmpeg.org/ffmpeg-formats.html)**.
1312
- **[Full Documentation](https://video.aminyazdanpanah.com/)** is available describing all features and components.
14-
- 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.
13+
- For DRM and encryption, I **recommend** to try **[Shaka PHP](https://github.com/aminyazdanpanah/shaka-php)**, which is a great tool for this use case.
1514

1615
**Contents**
1716
- [Requirements](#requirements)
@@ -24,7 +23,9 @@ This package provides integration with **[PHP-FFmpeg](https://github.com/PHP-FFM
2423
- [Encrypted HLS](#encrypted-hls)
2524
- [Transcoding](#transcoding)
2625
- [Saving Files](#saving-files)
26+
- [Metadata Extraction](#metadata-extraction)
2727
- [Other Advanced Features](#other-advanced-features)
28+
- [Asynchronous Task Execution](#asynchronous-task-execution)
2829
- [Several Open Source Players](#several-open-source-players)
2930
- [Contributing and Reporting Bug](#contributing-and-reporting-bugs)
3031
- [Credits](#credits)
@@ -52,7 +53,7 @@ First of all, you need to include the package in Your Code:
5253
``` php
5354
require 'vendor/autoload.php'; // path to the autoload file
5455
```
55-
**Note:** If you are using such a framework(e.g. **[Laravel](https://github.com/laravel/laravel)**) that include the autoload automatically, then you can skip this step.
56+
**Note:** If you are using such a framework(e.g. **[Laravel](https://github.com/laravel/laravel)**) that auto include the autoload in your code, then you can skip this step.
5657

5758
### Configuration
5859
FFMpeg will autodetect FFmpeg and FFprobe binaries. If you want to give binary paths explicitly, you can pass an array as configuration. A Psr\Logger\LoggerInterface can also be passed to log binary executions.
@@ -92,14 +93,14 @@ $current_percentage = 0;
9293
$options = [
9394
'auth' => ['username', 'password', 'digest'],
9495
'form_params' => [
95-
'token' => 'YOR_TOKEN',
96-
'method' => 'download',
97-
'path' => ['dir3', 'videos', 'my_sweetie.mp4']
96+
'user' => 'USER_ID',
97+
'method' => 'download',
98+
'file' => ['dir3', 'videos', 'my_sweetie.mp4']
9899
],
99100
'headers' => [
100-
'User-Agent' => 'testing/1.0',
101+
'User-Agent' => 'Mozilla/5.0 (compatible; AminYazdanpanahBot/1.0; +http://aminyazdanpanah.com/bots)',
101102
'Accept' => 'application/json',
102-
'X-Authentication' => 'Bearer x1234'
103+
'Authorization' => 'Bearer ACCESS_TOKEN'
103104
],
104105
'progress' => function(
105106
$downloadTotal,
@@ -124,7 +125,6 @@ $video = $ffmpeg->fromURL($api, $save_to, $method, $options);
124125
#### 3. From Amazon S3
125126
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)
126127
- For getting credentials, you need to have an AWS account or you can **[create one](https://portal.aws.amazon.com/billing/signup#/start)**.
127-
- Before you get started, please read the AWS SDK for PHP Document found **[here](https://aws.amazon.com/sdk-for-php/)**.
128128

129129
For downloading a file from Amazon S3, you need to pass an associative array of options, the name of your bucket, and the key of your bucket to the `fromS3` method:
130130
``` php
@@ -141,24 +141,23 @@ $key = '/videos/my_sweetie.mp4';
141141

142142
$video = $ffmpeg->fromS3($config, $bucket, $key);
143143
```
144-
A path can also be passed to save the file on your local computer/server.
145-
144+
A path can also be passed to save the file on your local machine.
146145

147146
#### 4. From Google Cloud Storage
148-
[Google Cloud Storage](https://console.cloud.google.com/storage) is a RESTful online file storage web service for storing and accessing data on Google Cloud Platform infrastructure. The service combines the performance and scalability of Google's cloud with advanced security and sharing capabilities. It is an Infrastructure as a Service (IaaS), comparable to Amazon S3 online storage service. Contrary to Google Drive and according to different service specifications, Google Cloud Storage appears to be more suitable for enterprises. [Learn more](https://en.wikipedia.org/wiki/Google_Storage)
149-
- For creating credentials, read the Cloud Storage Authentication found **[here](https://cloud.google.com/storage/docs/authentication)** or you can [create it](https://console.cloud.google.com/apis/credentials) directly.
147+
**[Google Cloud Storage](https://console.cloud.google.com/storage)** is a RESTful online file storage web service for storing and accessing data on Google Cloud Platform infrastructure. The service combines the performance and scalability of Google's cloud with advanced security and sharing capabilities. It is an Infrastructure as a Service (IaaS), comparable to Amazon S3 online storage service. Contrary to Google Drive and according to different service specifications, Google Cloud Storage appears to be more suitable for enterprises. [Learn more](https://en.wikipedia.org/wiki/Google_Storage)
148+
- For creating credentials, read the Cloud Storage Authentication found **[here](https://cloud.google.com/storage/docs/authentication)** or you can **[create it](https://console.cloud.google.com/apis/credentials)** directly (Select the "Service account key" option).
150149

151150
For downloading a file from Google Cloud Storage, you need to pass an associative array of config, the name of your bucket, and the name of your file in the bucket to the `fromGCS` method:
152151
``` php
153152
$config = [
154-
'keyFilePath' => '/path/to/credentials.json'
153+
'keyFilePath' => '/path/to/credentials.json' // Alternativaely, you can authenticate by setting the environment variable. See https://cloud.google.com/docs/authentication/production#auth-cloud-implicit-php
155154
];
156155
$bucket = 'my_bucket';
157156
$name = 'my_sweetie.mp4';
158157

159158
$video = $ffmpeg->fromGCS($config, $bucket, $name);
160159
```
161-
A path can also be passed to save the file on your local computer/server.
160+
A path can also be passed to save the file on your local machine.
162161

163162
### DASH
164163
**[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.
@@ -315,9 +314,9 @@ $api = 'https://www.aminyazdanpanah.com/api/v1.0/video/uploading';
315314
$field_name = 'MY_FILES';
316315
$method = 'POST';
317316
$headers = [
318-
'User-Agent' => 'testing/1.0',
317+
'User-Agent' => 'Mozilla/5.0 (compatible; AminYazdanpanahBot/1.0; +http://aminyazdanpanah.com/bots)',
319318
'Accept' => 'application/json',
320-
'X-Authentication' => 'Bearer x1234'
319+
'Authorization' => 'Bearer ACCESS_TOKEN'
321320
];
322321
$current_percentage = 0;
323322
$options = [
@@ -340,7 +339,7 @@ $options = [
340339

341340
$dash->saveToCloud($api, $field_name, null, $method, $headers, $options);
342341
```
343-
A path can also be passed to save a copy of files on your local server/computer:
342+
A path can also be passed to save a copy of files on your local machine:
344343
``` php
345344
$save_to = '/var/www/media/videos/hls/test.m3u8';
346345
$hls->saveToCloud($api, $field_name, $save_to, $method, $headers, $options);
@@ -363,7 +362,7 @@ Upload DASH files to Amazon Simple Storage Service:
363362
``` php
364363
$dash->saveToS3($config, $dest);
365364
```
366-
A path can also be passed to save a copy of files on your local computer/server.
365+
A path can also be passed to save a copy of files on your local machine.
367366
``` php
368367
$hls->saveToS3($config, $dest, '/var/www/media/videos/hls/test.m3u8');
369368
```
@@ -378,12 +377,12 @@ $bucket = 'my_bucket';
378377

379378
$dash->saveToGCS($config, $bucket);
380379
```
381-
A path can also be passed to save a copy of files on your local computer/server.
380+
A path can also be passed to save a copy of files on your local machine.
382381
``` php
383382
$hls->saveToGCS($config, $bucket, '/var/www/media/videos/hls/test.m3u8');
384383
```
385384

386-
**NOTE:** You can mix opening and saving options together. For instance, you can open a file on your local computer/server and save packaged files to a Cloud (or vice versa).
385+
**NOTE:** You can mix opening and saving options together. For instance, you can open a file on your local machine and save packaged files to a Cloud (or vice versa).
387386

388387
![schema](/docs/schema.gif?raw=true "schema" )
389388

@@ -395,7 +394,7 @@ $metadata = $hls->save();
395394
echo $metadata['filename']; // path to metadata.json
396395
var_dump($metadata['metadata']); // dump all metadata
397396
```
398-
**NOTE:** You can save these metadata in your database.
397+
**NOTE:** You can save these metadata to your database.
399398

400399
### Other Advanced Features
401400
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 `fromURL`), it holds the Media object that belongs to the PHP-FFMpeg.
@@ -411,6 +410,16 @@ $frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(42));
411410
$frame->save('image.jpg');
412411
```
413412

413+
## Asynchronous Task Execution
414+
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.
415+
- **[Symphony(The Console Component)](https://github.com/symfony/console):** You can use this library to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs. [Learn more](https://symfony.com/doc/current/components/console.html#learn-more)
416+
417+
- **[Laravel(Queues)](https://symfony.com/doc/current/components/console.html):** If you are using laravel for development, Laravel Queues is a wonderful tool for this use case. It allows you to create a job and dispatch it. [Learn more](https://laravel.com/docs/6.0/queues)
418+
419+
- **[Google Cloud Tasks](https://github.com/googleapis/google-cloud-php-tasks):** Google Cloud Tasks is a fully managed service that allows you to manage the execution, dispatch and delivery of a large number of distributed tasks. You can asynchronously perform work outside of a user request. [Learn more](https://cloud.google.com/tasks/)
420+
421+
**NOTE:** It is not necessary to use this library. It is just a suggestion. You can also create a script to create packaged video files and run it in a cron-job.
422+
414423
## Several Open Source Players
415424
You can use these libraries to play your streams.
416425
- **WEB**
@@ -433,9 +442,11 @@ You can use these libraries to play your streams.
433442
I'd love your help in improving, correcting, adding to the specification.
434443
Please **[file an issue](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/issues)** or **[submit a pull request](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/pulls)**.
435444
- Please see **[Contributing File](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/blob/master/CONTRIBUTING.md)** for more information.
436-
- Please, just **[file an issue](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/issues)** for reporting bugs or if you have any question.
445+
- If you have any questions or you want to report a bug, please just **[file an issue](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/issues)**
437446
- If you discover a security vulnerability within this package, please see **[SECURITY File](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/blob/master/SECURITY.md)** for more information to help with that.
438447

448+
**NOTE:** If you have any questions about this package or FFMpeg, please **DO NOT** send an email to me or submit the contact form in my website. Emails related to these issues **will be ignored**.
449+
439450
## Credits
440451
- **[Amin Yazdanpanah](https://www.aminyazdanpanah.com/?u=github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming)**
441452

src/GoogleCloudStorage.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class GoogleCloudStorage
3131
*/
3232
public function __construct(array $config, string $bucket, $userProject = false)
3333
{
34-
try{
34+
try {
3535
$storage = new StorageClient($config);
3636
$this->bucket = $storage->bucket($bucket, $userProject);
37-
}catch (\Exception $e){
37+
} catch (\Exception $e) {
3838
throw new InvalidArgumentException(sprintf("Invalid inputs:\n %s", $e->getMessage()), $e->getCode(), $e);
3939
}
4040
}
@@ -45,15 +45,15 @@ public function __construct(array $config, string $bucket, $userProject = false)
4545
*/
4646
public function uploadDirectory(string $dir, array $options = [])
4747
{
48-
try{
48+
try {
4949
foreach (scandir($dir) as $key => $filename) {
5050
$path = $dir . DIRECTORY_SEPARATOR . $filename;
5151

5252
if (is_file($path)) {
5353
$this->bucket->upload(fopen($path, 'r'), $options);
5454
}
5555
}
56-
}catch (\Exception $e){
56+
} catch (\Exception $e) {
5757
throw new RuntimeException(sprintf("There wan an error during uploading files:\n %s", $e->getMessage()), $e->getCode(), $e);
5858
}
5959
}
@@ -65,10 +65,10 @@ public function uploadDirectory(string $dir, array $options = [])
6565
*/
6666
public function download(string $name, string $save_to)
6767
{
68-
try{
68+
try {
6969
return $this->bucket->object($name)
7070
->downloadToFile($save_to);
71-
}catch (\Exception $e){
71+
} catch (\Exception $e) {
7272
throw new RuntimeException(sprintf("There wan an error during fetch the file:\n %s", $e->getMessage()), $e->getCode(), $e);
7373
}
7474
}

src/Metadata.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function extract()
3737
$metadata["video"] = $this->getVideoMetadata();
3838
$metadata["streams"] = $this->getStreamsMetadata();
3939

40-
$filename = $this->export->getPathInfo()["dirname"] . DIRECTORY_SEPARATOR . "_" . Helper::randomString(20) . "_metadata.json";
40+
$name = $this->export->getPathInfo()["filename"] . "-" . Helper::randomString(12) . ".json";
41+
$filename = $this->export->getPathInfo()["dirname"] . DIRECTORY_SEPARATOR . $name;
4142
file_put_contents($filename, json_encode($metadata, JSON_PRETTY_PRINT));
4243

4344
return [

src/helpers.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
use Streaming\Format\X264;
1616

1717
if (!function_exists('dash')) {
18+
@trigger_error('dash method is deprecated and will be removed in a future release. Use Streaming\DASH instead', E_USER_DEPRECATED);
19+
1820
/**
1921
* Auto generate dash MPD file
2022
*
2123
* @param string $input_path
2224
* @param string|null $save_path
2325
* @param callable $listener
2426
* @return mixed
25-
* @deprecated this method has been deprecated
27+
* @deprecated this method is deprecated
2628
*/
2729
function dash(string $input_path, string $save_path = null, callable $listener = null)
2830
{
31+
2932
$format = new HEVC();
3033

3134
if (is_callable($listener)) {
@@ -51,6 +54,8 @@ function dash(string $input_path, string $save_path = null, callable $listener =
5154
}
5255

5356
if (!function_exists('hls')) {
57+
@trigger_error('hls method is deprecated and will be removed in a future release. Use Streaming\HLS instead', E_USER_DEPRECATED);
58+
5459
/**
5560
* Auto generate HLS M3U8 file
5661
*
@@ -59,7 +64,7 @@ function dash(string $input_path, string $save_path = null, callable $listener =
5964
* @param callable|null $listener
6065
* @param string $hls_key
6166
* @return mixed
62-
* @deprecated this method has been deprecated
67+
* @deprecated this method is deprecated
6368
*/
6469
function hls(string $input_path, string $save_path = null, callable $listener = null, $hls_key = "")
6570
{
@@ -88,6 +93,8 @@ function hls(string $input_path, string $save_path = null, callable $listener =
8893
}
8994

9095
if (!function_exists('encrypted_hls')) {
96+
@trigger_error('encrypted_hls method is deprecated and will be removed in a future release. Use Streaming\HLS instead', E_USER_DEPRECATED);
97+
9198
/**
9299
* Auto generate HLS M3U8 file
93100
*
@@ -97,7 +104,7 @@ function hls(string $input_path, string $save_path = null, callable $listener =
97104
* @param string|null $save_path
98105
* @param callable|null $listener
99106
* @return mixed
100-
* @deprecated this method has been deprecated
107+
* @deprecated this method is deprecated
101108
*/
102109
function encrypted_hls(string $input_path, string $url, string $key_path, string $save_path = null, callable $listener = null)
103110
{

0 commit comments

Comments
 (0)