ffmpeg-mappable-media/src/FFMpeg/Format/DefaultAudio.php

116 lines
2.5 KiB
PHP
Raw Normal View History

2012-04-13 12:45:41 +02:00
<?php
2012-04-13 14:34:53 +02:00
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2012-04-13 12:45:41 +02:00
namespace FFMpeg\Format;
2012-05-25 16:21:16 +02:00
use FFMpeg\Exception\InvalidArgumentException;
2012-04-13 15:42:34 +02:00
/**
* The abstract default Audio format
*
* @author Romain Neutron imprec@gmail.com
*/
2012-05-25 20:53:56 +02:00
abstract class DefaultAudio implements Audio
2012-04-13 12:45:41 +02:00
{
protected $audioCodec;
protected $audioSampleRate = 44100;
2012-04-27 00:48:57 +02:00
protected $kiloBitrate = 128;
2012-04-13 12:45:41 +02:00
2012-04-13 15:42:34 +02:00
/**
* Returns extra parameters for the encoding
*
* @return string
*/
2012-04-13 12:45:41 +02:00
public function getExtraParams()
{
return '';
}
2012-04-13 15:42:34 +02:00
/**
2012-05-25 16:21:16 +02:00
* {@inheritdoc}
2012-04-13 15:42:34 +02:00
*/
2012-04-13 12:45:41 +02:00
public function getAudioCodec()
{
return $this->audioCodec;
}
2012-04-13 15:42:34 +02:00
/**
* Set the audio codec, Should be in the available ones, otherwise an
* exception is thrown
*
2012-05-25 15:44:43 +02:00
* @param string $audioCodec
2012-04-13 15:42:34 +02:00
* @throws \InvalidArgumentException
*/
2012-04-13 12:45:41 +02:00
public function setAudioCodec($audioCodec)
{
2012-04-27 00:48:57 +02:00
if ( ! in_array($audioCodec, $this->getAvailableAudioCodecs())) {
2012-05-25 16:21:16 +02:00
throw new InvalidArgumentException(sprintf(
2012-04-27 00:48:57 +02:00
'Wrong audiocodec value for %s, available formats are %s'
, $audioCodec, implode(', ', $this->getAvailableAudioCodecs())
));
2012-04-13 12:45:41 +02:00
}
$this->audioCodec = $audioCodec;
2012-05-25 16:21:16 +02:00
return $this;
2012-04-13 12:45:41 +02:00
}
2012-04-13 15:42:34 +02:00
/**
2012-05-25 16:21:16 +02:00
* {@inheritdoc}
2012-04-13 15:42:34 +02:00
*/
2012-04-13 12:45:41 +02:00
public function getAudioSampleRate()
{
return $this->audioSampleRate;
}
2012-04-13 15:42:34 +02:00
/**
* Set the audio sample rate
*
2012-05-25 15:44:43 +02:00
* @param integer $audioSampleRate
2012-04-13 15:42:34 +02:00
* @throws \InvalidArgumentException
*/
2012-04-13 12:45:41 +02:00
public function setAudioSampleRate($audioSampleRate)
{
2012-04-27 00:48:57 +02:00
if ($audioSampleRate < 1) {
2012-05-25 16:21:16 +02:00
throw new InvalidArgumentException('Wrong audio sample rate value');
2012-04-13 12:45:41 +02:00
}
$this->audioSampleRate = (int) $audioSampleRate;
2012-05-25 16:21:16 +02:00
return $this;
2012-04-13 12:45:41 +02:00
}
2012-04-13 15:42:34 +02:00
/**
2012-05-25 16:21:16 +02:00
* {@inheritdoc}
2012-04-13 15:42:34 +02:00
*/
2012-04-13 12:45:41 +02:00
public function getKiloBitrate()
{
return $this->kiloBitrate;
}
2012-04-13 15:42:34 +02:00
/**
* Set the kiloBitrate value
*
2012-05-25 15:44:43 +02:00
* @param int integer $kiloBitrate
2012-04-13 15:42:34 +02:00
* @throws \InvalidArgumentException
*/
2012-04-13 12:45:41 +02:00
public function setKiloBitrate($kiloBitrate)
{
2012-04-27 00:48:57 +02:00
if ($kiloBitrate < 1) {
2012-05-25 16:21:16 +02:00
throw new InvalidArgumentException('Wrong kiloBitrate value');
2012-04-13 12:45:41 +02:00
}
$this->kiloBitrate = (int) $kiloBitrate;
2012-05-25 16:21:16 +02:00
return $this;
2012-04-13 12:45:41 +02:00
}
}