Add filter priorities
This commit is contained in:
parent
5ecb6f1cfe
commit
890cbce1f9
10 changed files with 156 additions and 33 deletions
|
|
@ -18,10 +18,21 @@ class AudioResamplableFilter implements AudioFilterInterface
|
|||
{
|
||||
/** @var string */
|
||||
private $rate;
|
||||
/** @var integer */
|
||||
private $priority;
|
||||
|
||||
public function __construct($rate)
|
||||
public function __construct($rate, $priority = 0)
|
||||
{
|
||||
$this->rate = $rate;
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
34
src/FFMpeg/Filters/Audio/SimpleFilter.php
Normal file
34
src/FFMpeg/Filters/Audio/SimpleFilter.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg\Filters\Audio;
|
||||
|
||||
use FFMpeg\Media\Audio;
|
||||
use FFMpeg\Format\AudioInterface;
|
||||
|
||||
class SimpleFilter implements AudioFilterInterface
|
||||
{
|
||||
private $params;
|
||||
private $priority;
|
||||
|
||||
public function __construct(array $params, $priority = 0)
|
||||
{
|
||||
$this->params = $params;
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(Audio $audio, AudioInterface $format)
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,4 +13,10 @@ namespace FFMpeg\Filters;
|
|||
|
||||
interface FilterInterface
|
||||
{
|
||||
/**
|
||||
* Returns the priority of the filter.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getPriority();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace FFMpeg\Filters;
|
|||
|
||||
class FiltersCollection implements \Countable, \IteratorAggregate
|
||||
{
|
||||
private $sorted;
|
||||
private $filters = array();
|
||||
|
||||
/**
|
||||
|
|
@ -22,7 +23,8 @@ class FiltersCollection implements \Countable, \IteratorAggregate
|
|||
*/
|
||||
public function add(FilterInterface $filter)
|
||||
{
|
||||
$this->filters[] = $filter;
|
||||
$this->filters[$filter->getPriority()][] = $filter;
|
||||
$this->sorted = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -32,7 +34,11 @@ class FiltersCollection implements \Countable, \IteratorAggregate
|
|||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->filters);
|
||||
if (0 === count($this->filters)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return count(call_user_func_array('array_merge', $this->filters));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -40,6 +46,11 @@ class FiltersCollection implements \Countable, \IteratorAggregate
|
|||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->filters);
|
||||
if (null === $this->sorted) {
|
||||
krsort($this->filters);
|
||||
$this->sorted = call_user_func_array('array_merge', $this->filters);
|
||||
}
|
||||
|
||||
return new \ArrayIterator($this->sorted);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,23 @@ class ResizeFilter implements VideoFilterInterface
|
|||
private $mode;
|
||||
/** @var Boolean */
|
||||
private $forceStandards;
|
||||
/** @var integer */
|
||||
private $priority;
|
||||
|
||||
public function __construct(Dimension $dimension, $mode = self::RESIZEMODE_FIT, $forceStandards = true)
|
||||
public function __construct(Dimension $dimension, $mode = self::RESIZEMODE_FIT, $forceStandards = true, $priority = 0)
|
||||
{
|
||||
$this->dimension = $dimension;
|
||||
$this->mode = $mode;
|
||||
$this->forceStandards = $forceStandards;
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,6 +19,21 @@ use FFMpeg\Media\Video;
|
|||
*/
|
||||
class SynchronizeFilter implements VideoFilterInterface
|
||||
{
|
||||
private $priority;
|
||||
|
||||
public function __construct($priority = 12)
|
||||
{
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -19,11 +19,21 @@ class VideoResampleFilter implements VideoFilterInterface
|
|||
{
|
||||
private $rate;
|
||||
private $gop;
|
||||
private $priority;
|
||||
|
||||
public function __construct(FrameRate $rate, $gop)
|
||||
public function __construct(FrameRate $rate, $gop, $priority = 0)
|
||||
{
|
||||
$this->rate = $rate;
|
||||
$this->gop = $gop;
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue