Add Audio and Video interfaces
This commit is contained in:
parent
aa681f66b1
commit
94775176c9
14 changed files with 294 additions and 222 deletions
|
|
@ -54,7 +54,7 @@ class FFMpeg extends Binary
|
|||
return true;
|
||||
}
|
||||
|
||||
public function encode(Format\Format $format, $outputPathfile, $threads = 1)
|
||||
public function encode(Format\AudioFormat $format, $outputPathfile, $threads = 1)
|
||||
{
|
||||
if ( ! $this->pathfile)
|
||||
{
|
||||
|
|
|
|||
14
src/FFMpeg/Format/AudioFormat.php
Normal file
14
src/FFMpeg/Format/AudioFormat.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg\Format;
|
||||
|
||||
interface AudioFormat
|
||||
{
|
||||
|
||||
public function getAudioCodec();
|
||||
|
||||
public function getAudioSampleRate();
|
||||
|
||||
public function getKiloBitrate();
|
||||
|
||||
}
|
||||
64
src/FFMpeg/Format/DefaultAudioFormat.php
Normal file
64
src/FFMpeg/Format/DefaultAudioFormat.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg\Format;
|
||||
|
||||
abstract class DefaultAudioFormat implements AudioFormat
|
||||
{
|
||||
|
||||
protected $audioCodec;
|
||||
protected $audioSampleRate = 44100;
|
||||
protected $kiloBitrate = 1000;
|
||||
|
||||
public function getExtraParams()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getAudioCodec()
|
||||
{
|
||||
return $this->audioCodec;
|
||||
}
|
||||
|
||||
public function setAudioCodec($audioCodec)
|
||||
{
|
||||
if ( ! in_array($audioCodec, $this->getAvailableAudioCodecs()))
|
||||
{
|
||||
throw new \InvalidArgumentException('Wrong audiocodec value');
|
||||
}
|
||||
|
||||
$this->audioCodec = $audioCodec;
|
||||
}
|
||||
|
||||
public function getAudioSampleRate()
|
||||
{
|
||||
return $this->audioSampleRate;
|
||||
}
|
||||
|
||||
public function setAudioSampleRate($audioSampleRate)
|
||||
{
|
||||
if ($audioSampleRate < 1)
|
||||
{
|
||||
throw new \InvalidArgumentException('Wrong audio sample rate value');
|
||||
}
|
||||
|
||||
$this->audioSampleRate = (int) $audioSampleRate;
|
||||
}
|
||||
|
||||
public function getKiloBitrate()
|
||||
{
|
||||
return $this->kiloBitrate;
|
||||
}
|
||||
|
||||
public function setKiloBitrate($kiloBitrate)
|
||||
{
|
||||
if ($kiloBitrate < 1)
|
||||
{
|
||||
throw new \InvalidArgumentException('Wrong kiloBitrate value');
|
||||
}
|
||||
|
||||
$this->kiloBitrate = (int) $kiloBitrate;
|
||||
}
|
||||
|
||||
abstract protected function getAvailableAudioCodecs();
|
||||
|
||||
}
|
||||
|
|
@ -2,28 +2,20 @@
|
|||
|
||||
namespace FFMpeg\Format;
|
||||
|
||||
abstract class DefaultFormat implements Format
|
||||
abstract class DefaultVideoFormat extends DefaultAudioFormat implements VideoFormat
|
||||
{
|
||||
|
||||
protected $width;
|
||||
protected $height;
|
||||
protected $frameRate = 25;
|
||||
protected $audioCodec;
|
||||
protected $audioSampleRate = 44100;
|
||||
protected $frameRate = 25;
|
||||
protected $videoCodec;
|
||||
protected $kiloBitrate = 1000;
|
||||
protected $GOPsize = 25;
|
||||
protected $GOPsize = 25;
|
||||
|
||||
public function __construct($width, $height)
|
||||
{
|
||||
$this->setDimensions($width, $height);
|
||||
}
|
||||
|
||||
public function getExtraParams()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
|
|
@ -66,36 +58,6 @@ abstract class DefaultFormat implements Format
|
|||
$this->frameRate = (int) $frameRate;
|
||||
}
|
||||
|
||||
public function getAudioCodec()
|
||||
{
|
||||
return $this->audioCodec;
|
||||
}
|
||||
|
||||
public function setAudioCodec($audioCodec)
|
||||
{
|
||||
if ( ! in_array($audioCodec, $this->getAvailableAudioCodecs()))
|
||||
{
|
||||
throw new \InvalidArgumentException('Wrong audiocodec value');
|
||||
}
|
||||
|
||||
$this->audioCodec = $audioCodec;
|
||||
}
|
||||
|
||||
public function getAudioSampleRate()
|
||||
{
|
||||
return $this->audioSampleRate;
|
||||
}
|
||||
|
||||
public function setAudioSampleRate($audioSampleRate)
|
||||
{
|
||||
if ($audioSampleRate < 1)
|
||||
{
|
||||
throw new \InvalidArgumentException('Wrong audio sample rate value');
|
||||
}
|
||||
|
||||
$this->audioSampleRate = (int) $audioSampleRate;
|
||||
}
|
||||
|
||||
public function getVideoCodec()
|
||||
{
|
||||
return $this->videoCodec;
|
||||
|
|
@ -111,21 +73,6 @@ abstract class DefaultFormat implements Format
|
|||
$this->videoCodec = $videoCodec;
|
||||
}
|
||||
|
||||
public function getKiloBitrate()
|
||||
{
|
||||
return $this->kiloBitrate;
|
||||
}
|
||||
|
||||
public function setKiloBitrate($kiloBitrate)
|
||||
{
|
||||
if ($kiloBitrate < 1)
|
||||
{
|
||||
throw new \InvalidArgumentException('Wrong kiloBitrate value');
|
||||
}
|
||||
|
||||
$this->kiloBitrate = (int) $kiloBitrate;
|
||||
}
|
||||
|
||||
public function getGOPsize()
|
||||
{
|
||||
return $this->GOPsize;
|
||||
|
|
@ -172,8 +119,6 @@ abstract class DefaultFormat implements Format
|
|||
return (int) $ret;
|
||||
}
|
||||
|
||||
abstract protected function getAvailableAudioCodecs();
|
||||
|
||||
abstract protected function getAvailableVideoCodecs();
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg\Format;
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
class Ogg extends DefaultFormat
|
||||
use FFMpeg\Format\DefaultVideoFormat;
|
||||
|
||||
class Ogg extends DefaultVideoFormat
|
||||
{
|
||||
|
||||
protected $audioCodec = 'libvorbis';
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg\Format;
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
class WebM extends DefaultFormat
|
||||
use FFMpeg\Format\DefaultVideoFormat;
|
||||
|
||||
class WebM extends DefaultVideoFormat
|
||||
{
|
||||
|
||||
protected $audioCodec = 'libvorbis';
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg\Format;
|
||||
namespace FFMpeg\Format\Video;
|
||||
|
||||
class X264 extends DefaultFormat
|
||||
use FFMpeg\Format\DefaultVideoFormat;
|
||||
|
||||
class X264 extends DefaultVideoFormat
|
||||
{
|
||||
|
||||
protected $audioCodec = 'libmp3lame';
|
||||
|
|
@ -2,25 +2,17 @@
|
|||
|
||||
namespace FFMpeg\Format;
|
||||
|
||||
interface Format
|
||||
interface VideoFormat
|
||||
{
|
||||
|
||||
public function getExtraParams();
|
||||
|
||||
public function getWidth();
|
||||
|
||||
public function getHeight();
|
||||
|
||||
public function getFrameRate();
|
||||
|
||||
public function getAudioCodec();
|
||||
|
||||
public function getAudioSampleRate();
|
||||
|
||||
public function getVideoCodec();
|
||||
|
||||
public function getKiloBitrate();
|
||||
|
||||
public function getGOPSize();
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue