Skip to content

Commit

Permalink
bug fixes #33 and other minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aminyazdanpanah committed Mar 6, 2020
1 parent 4bc7af1 commit ac0e9df
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 123 deletions.
4 changes: 2 additions & 2 deletions src/DASH.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Streaming;

use Streaming\Filters\DASHFilter;
use Streaming\Filters\FilterStreamingInterface;
use Streaming\Filters\StreamFilterInterface;

class DASH extends Streaming
{
Expand Down Expand Up @@ -82,7 +82,7 @@ public function isGenerateHlsPlaylist(): bool
/**
* @return DASHFilter
*/
protected function getFilter(): FilterStreamingInterface
protected function getFilter(): StreamFilterInterface
{
return new DASHFilter($this);
}
Expand Down
74 changes: 38 additions & 36 deletions src/Filters/DASHFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,62 @@
namespace Streaming\Filters;


use Streaming\DASH;
use Streaming\StreamInterface;
use Streaming\Format\X264;
use Streaming\Representation;

class DASHFilter extends Filter
class DASHFilter extends StreamFilter
{
/** @var \Streaming\DASH */
private $dash;
/**
* @param $media
* @param StreamInterface $stream
*/
public function setFilter($media): void
public function streamFilter(StreamInterface $stream): void
{
$this->filter = $this->DASHFilter($media);
$this->dash = $stream;
$this->set();
}

/**
* @param DASH $dash
* @return array
*/
private function DASHFilter(DASH $dash): array
private function set()
{
$filter = $this->getBaseFilters($dash, count($dash->getRepresentations()));
$this->filter = $this->getBaseFilters();

foreach ($dash->getRepresentations() as $key => $representation) {
$filter[] = "-map";
$filter[] = "0";
$filter[] = "-b:v:" . $key;
$filter[] = $representation->getKiloBitrate() . "k";
$filter = array_merge($filter, $this->getAudioBitrate($representation, $key));
foreach ($this->dash->getRepresentations() as $key => $representation) {
$this->filter[] = "-map";
$this->filter[] = "0";
$this->filter[] = "-b:v:" . $key;
$this->filter[] = $representation->getKiloBitrate() . "k";
$this->filter = array_merge($this->filter, $this->getAudioBitrate($representation, $key));

if (null !== $representation->getResize()) {
$filter[] = "-s:v:" . $key;
$filter[] = $representation->getResize();
$this->filter[] = "-s:v:" . $key;
$this->filter[] = $representation->getResize();
}
}

if ($dash->getAdaption()) {
$filter[] = "-adaptation_sets";
$filter[] = $dash->getAdaption();
if ($this->dash->getAdaption()) {
$this->filter[] = "-adaptation_sets";
$this->filter[] = $this->dash->getAdaption();
}
$filter = array_merge($filter, $dash->getAdditionalParams());
$filter = array_merge($filter, ["-strict", $dash->getStrict()]);
$this->filter = array_merge($this->filter, $this->dash->getAdditionalParams());
$this->filter = array_merge($this->filter, ["-strict", $this->dash->getStrict()]);

return $filter;
return $this->filter;
}

/**
* @param $dash
* @param $count
* @return array
*/
private function getBaseFilters(DASH $dash, int $count): array
private function getBaseFilters(): array
{
$dirname = $dash->getPathInfo(PATHINFO_FILENAME);
$filename = $dash->getPathInfo(PATHINFO_FILENAME);
$filename = $this->dash->getPathInfo(PATHINFO_FILENAME);

$filter = [
$this->filter = [
"-bf", "1",
"-keyint_min", "120",
"-g", "120",
Expand All @@ -78,23 +78,25 @@ private function getBaseFilters(DASH $dash, int $count): array
"-use_template", "1",
"-init_seg_name", ($filename . '_init_$RepresentationID$.$ext$'),
"-media_seg_name", ($filename . '_chunk_$RepresentationID$_$Number%05d$.$ext$'),
"-seg_duration", $dash->getSegDuration(),
"-hls_playlist", (int)$dash->isGenerateHlsPlaylist(),
"-seg_duration", $this->dash->getSegDuration(),
"-hls_playlist", (int)$this->dash->isGenerateHlsPlaylist(),
"-f", "dash",
];

if ($dash->getFormat() instanceof X264) {
$filter[] = "-profile:v:0";
$filter[] = "main";
if ($this->dash->getFormat() instanceof X264) {
$this->filter[] = "-profile:v:0";
$this->filter[] = "main";

$count = count($this->dash->getRepresentations());

while ($count > 0) {
$filter[] = "-profile:v:" . $count;
$filter[] = "baseline";
$this->filter[] = "-profile:v:" . $count;
$this->filter[] = "baseline";
$count--;
}
}

return $filter;
return $this->filter;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/Filters/HLSFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

namespace Streaming\Filters;

use Streaming\StreamInterface;
use Streaming\File;
use Streaming\Representation;
use Streaming\Utiles;

class HLSFilter extends Filter
class HLSFilter extends StreamFilter
{
/** @var \Streaming\HLS */
private $hls;
Expand Down Expand Up @@ -97,7 +98,7 @@ private function getInitFilename(): string
*/
private function getSegmentFilename(Representation $rep): string
{
$ext = ($this->hls->getHlsFmp4InitFilename() === "fmp4") ? "m4s" : "ts";
$ext = ($this->hls->getHlsSegmentType() === "fmp4") ? "m4s" : "ts";
return $this->seg_filename . "_" . $rep->getHeight() . "p_%04d." . $ext;
}

Expand Down Expand Up @@ -169,12 +170,12 @@ private function setPaths(): void
}

/**
* @param $media
* @param StreamInterface $stream
* @return void
*/
public function setFilter($media): void
public function streamFilter(StreamInterface $stream): void
{
$this->hls = $media;
$this->hls = $stream;
$this->setPaths();

$reps = $this->hls->getRepresentations();
Expand Down
13 changes: 6 additions & 7 deletions src/Filters/Filter.php → src/Filters/StreamFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@

namespace Streaming\Filters;

use Streaming\Export;
use FFMpeg\Filters\FilterInterface;
use Streaming\StreamInterface;

abstract class Filter implements FilterInterface, FilterStreamingInterface
abstract class StreamFilter implements StreamFilterInterface
{
private $priority = 2;

protected $filter = [];

/**
* Filter constructor.
* @param Export $media
* @param StreamInterface $stream
*/
public function __construct(Export $media)
public function __construct(StreamInterface $stream)
{
$this->setFilter($media);
$this->streamFilter($stream);
}

/**
* Applies the filter on the the Audio media given an format.
* Applies the filter on the the stream media
*
* @return array An array of arguments
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@

namespace Streaming\Filters;

interface FilterStreamingInterface
use FFMpeg\Filters\FilterInterface;
use Streaming\StreamInterface;

interface StreamFilterInterface extends FilterInterface
{
/**
* @param $media
* @param StreamInterface $stream
* @return mixed
*/
public function setFilter($media): void;
public function streamFilter(StreamInterface $stream): void;

/**
* @return array
*/
public function apply(): array;
}
16 changes: 4 additions & 12 deletions src/Filters/StreamToFileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,18 @@
namespace Streaming\Filters;


use Streaming\StreamInterface;
use Streaming\StreamToFile;

class StreamToFileFilter extends Filter
class StreamToFileFilter extends StreamFilter
{

/**
* @param $media
* @return mixed
*/
public function setFilter($media): void
public function streamFilter(StreamInterface $media): void
{
$this->filter = $this->StreamToFileFilter($media);
}

/**
* @param StreamToFile $stf
* @return array
*/
private function StreamToFileFilter(StreamToFile $stf)
{
return array_merge(['-c', 'copy'], $stf->getParams());
$this->filter = array_merge(['-c', 'copy'], $media->getParams());
}
}
5 changes: 2 additions & 3 deletions src/HLS.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

namespace Streaming;

use phpDocumentor\Reflection\Types\This;
use Streaming\Filters\FilterStreamingInterface;
use Streaming\Filters\HLSFilter;
use Streaming\Filters\StreamFilterInterface;

class HLS extends Streaming
{
Expand Down Expand Up @@ -225,7 +224,7 @@ public function getHlsFmp4InitFilename(): string
/**
* @return HLSFilter
*/
protected function getFilter(): FilterStreamingInterface
protected function getFilter(): StreamFilterInterface
{
return new HLSFilter($this);
}
Expand Down
Loading

0 comments on commit ac0e9df

Please sign in to comment.