Skip to content

Commit

Permalink
bug fixes and other minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aminyazdanpanah committed Dec 20, 2019
1 parent ec49aeb commit a933aae
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 47 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/aminyazdanpanah/PHP-FFmpeg-video-streaming/blob/master/LICENSE)

## Overview
This package provides integration with **[PHP-FFMpeg](https://github.com/PHP-FFMpeg/PHP-FFMpeg)** and package media content for online streaming such as DASH and HLS. You can also use **[DRM](https://en.wikipedia.org/wiki/Digital_rights_management)** for HLS packaging. There are several options to open a file from clouds and save files to them as well.
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 use **[DRM](https://en.wikipedia.org/wiki/Digital_rights_management)** for HLS packaging. There are several options to open a file from a cloud and save files to clouds as well.
- **[Full Documentation](https://video.aminyazdanpanah.com/)** is available describing all features and components.
- **[A complete example](https://video.aminyazdanpanah.com/start/example)** is provided. It contains server-side(Transcoding + cloud + progress + web socket) and client-side(progress bar + web socket + player).
- For using DRM and encryption, I **recommend** trying **[Shaka PHP](https://github.com/aminyazdanpanah/shaka-php)**, which is a great tool for this use case.
Expand Down Expand Up @@ -111,7 +111,7 @@ $r_4k = (new Representation)->setKiloBitrate(17408)->setResize(3840, 2160);

$video->DASH()
->HEVC()
->addRepresentations($r_144p, $r_240p, $r_360p, $r_480p, $r_720p, $r_1080p, $r_2k, $r_4k)
->addRepresentations([$r_144p, $r_240p, $r_360p, $r_480p, $r_720p, $r_1080p, $r_2k, $r_4k])
->setAdaption('id=0,streams=v id=1,streams=a')
->save('/var/www/media/videos/dash-stream.mpd');
```
Expand All @@ -137,7 +137,7 @@ $r_720p = (new Representation)->setKiloBitrate(2048)->setResize(1280, 720);
$video->HLS()
->X264()
->setHlsBaseUrl('https://bucket.s3-us-west-1.amazonaws.com/videos') // Add a base URL
->addRepresentations($r_360p, $r_480p, $r_720p)
->addRepresentations([$r_360p, $r_480p, $r_720p])
->setHlsTime(5) // Set Hls Time. Default value is 10
->setHlsAllowCache(false) // Default value is true
->save();
Expand Down
4 changes: 2 additions & 2 deletions src/AutoRepresentations.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function getKiloBitrateValues(?array $k_bitrate_values): void
{
$count_sides = count($this->side_values);

if ($k_bitrate_values) {
if (!empty($k_bitrate_values)) {
if ($count_sides !== count($k_bitrate_values)) {
throw new InvalidArgumentException("The count of side value array must be the same as the count of kilo bitrate array");
}
Expand All @@ -133,7 +133,7 @@ private function getKiloBitrateValues(?array $k_bitrate_values): void
*/
private function getSideValues(?array $side_values): void
{
if ($side_values) {
if (!empty($side_values)) {
$this->side_values = $side_values;
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private function tmpDirectory(?string $path): void
*/
private function makePaths(?string $path, array $clouds): void
{
if ($clouds) {
if (!empty($clouds)) {
$this->tmpDirectory($path);
} elseif (!is_null($path)) {
if (strlen($path) > PHP_MAXPATHLEN) {
Expand Down Expand Up @@ -197,15 +197,15 @@ public function __destruct()
sleep(1);

if ($this->media->isTmp()) {
@unlink($this->media->getPath());
File::remove($this->media->getPath());
}

if ($this->tmp_dir) {
File::deleteDirectory($this->tmp_dir);
File::remove($this->tmp_dir);
}

if ($this instanceof HLS && $this->tmp_key_info_file) {
@unlink($this->getHlsKeyInfoFile());
File::remove($this->getHlsKeyInfoFile());
}
}
}
2 changes: 1 addition & 1 deletion src/FFMpeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function open(string $path, bool $is_tmp = false): Media
} catch (ExceptionInterface $e) {
if ($is_tmp) {
sleep(1);
@unlink($path);
File::remove($path);
}
throw new RuntimeException("An error occurred while opening the file: " . $e->getMessage(), $e->getCode(), $e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ private static function tmpDirPath(): string
public static function moveDir(string $src, string $dst): void
{
static::filesystem('mirror', [$src, $dst]);
static::deleteDirectory($src);
static::remove($src);
}

/**
* @param $dir
*/
public static function deleteDirectory(string $dir): void
public static function remove(string $dir): void
{
static::filesystem('remove', [$dir]);
}
Expand Down
13 changes: 0 additions & 13 deletions src/HLS.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,6 @@ public function encryption(string $save_to, string $url, int $length = 16): HLS
return $this;
}

/**
* @param string $url
* @param string $path
* @param int $length
* @return HLS
* @deprecated Please use encryption instead
*/
public function generateRandomKeyInfo(string $url, string $path, int $length = 16): HLS
{
@trigger_error('generateRandomKeyInfo method is deprecated and will be removed in a future release. Use encryption instead.', E_USER_DEPRECATED);
return $this->encryption($path, $url, $length);
}

/**
* @return string
*/
Expand Down
14 changes: 6 additions & 8 deletions src/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ public function __construct(Export $export)
*/
public function extract(): array
{
$metadata["video"] = $this->getVideoMetadata();
$metadata["streams"] = $this->getStreamsMetadata();

$filename = 'It is not possible to save metadata to clouds.';
if (!$this->export->isTmpDir()) {
$filename = $this->saveAsJson($metadata);
}
$metadata = [
"video" => $this->getVideoMetadata(),
"streams" => $this->getStreamsMetadata()
];

return [
'filename' => $filename,
'filename' => !$this->export->isTmpDir() ? $this->saveAsJson($metadata) : null,
'metadata' => $metadata
];
}
Expand Down Expand Up @@ -72,6 +69,7 @@ private function getVideoMetadata(): array
*/
private function getStreamsMetadata(): array
{
$metadata = [];
$stream_path = $this->export->getPathInfo();
$metadata["filename"] = $stream_path["dirname"] . DIRECTORY_SEPARATOR . $stream_path["basename"];
$metadata["size_of_stream_dir"] = File::directorySize($stream_path["dirname"]);
Expand Down
14 changes: 0 additions & 14 deletions src/Traits/Representations.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ trait Representations
/** @var array */
protected $representations = [];

/**
* @param Representation $rep
* @return $this
* @deprecated Please use addRepresentations instead
*/
public function addRepresentation(Representation $rep)
{
@trigger_error('addRepresentation method is deprecated and will be removed in a future release. Use addRepresentations instead.', E_USER_DEPRECATED);
$this->checkFormat();
$this->representations[] = $rep;

return $this;
}

/**
* @return $this
*/
Expand Down

0 comments on commit a933aae

Please sign in to comment.