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

143 lines
3.2 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-05-30 12:22:22 +02:00
namespace FFMpeg\Format\Audio;
2012-04-13 12:45:41 +02:00
2013-06-25 10:03:20 +02:00
use Evenement\EventEmitter;
2012-05-25 16:21:16 +02:00
use FFMpeg\Exception\InvalidArgumentException;
2013-06-25 10:03:20 +02:00
use FFMpeg\Format\AudioInterface;
use FFMpeg\Media\MediaTypeInterface;
use FFMpeg\Format\ProgressableInterface;
use FFMpeg\Format\ProgressListener\AudioProgressListener;
use FFMpeg\FFProbe;
2012-05-25 16:21:16 +02:00
2013-06-25 10:03:20 +02:00
abstract class DefaultAudio extends EventEmitter implements AudioInterface, ProgressableInterface
2012-04-13 12:45:41 +02:00
{
2013-06-25 10:03:20 +02:00
/** @var string */
2012-04-13 12:45:41 +02:00
protected $audioCodec;
2013-06-25 10:03:20 +02:00
/** @var integer */
protected $audioKiloBitrate = 128;
2012-04-13 12:45:41 +02:00
2014-06-25 09:55:00 +02:00
/** @var integer */
protected $audioChannels = null;
2012-04-13 15:42:34 +02:00
/**
2013-06-25 10:03:20 +02:00
* {@inheritdoc}
2012-04-13 15:42:34 +02:00
*/
2012-04-13 12:45:41 +02:00
public function getExtraParams()
{
2012-10-08 14:20:59 +02:00
return array();
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 getAudioCodec()
{
return $this->audioCodec;
}
2012-04-13 15:42:34 +02:00
/**
2013-06-25 10:03:20 +02:00
* Sets the audio codec, Should be in the available ones, otherwise an
2013-06-25 10:40:20 +02:00
* exception is thrown.
2012-04-13 15:42:34 +02:00
*
2013-06-25 10:03:20 +02:00
* @param string $audioCodec
*
* @throws InvalidArgumentException
2012-04-13 15:42:34 +02:00
*/
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
*/
2013-06-25 10:03:20 +02:00
public function getAudioKiloBitrate()
2012-04-13 12:45:41 +02:00
{
2013-06-25 10:03:20 +02:00
return $this->audioKiloBitrate;
2012-04-13 12:45:41 +02:00
}
2012-04-13 15:42:34 +02:00
/**
2013-06-25 10:40:20 +02:00
* Sets the kiloBitrate value.
2012-04-13 15:42:34 +02:00
*
2013-06-25 10:03:20 +02:00
* @param integer $kiloBitrate
* @throws InvalidArgumentException
2012-04-13 15:42:34 +02:00
*/
2013-06-25 10:03:20 +02:00
public function setAudioKiloBitrate($kiloBitrate)
2012-04-13 12:45:41 +02:00
{
2013-06-25 10:03:20 +02:00
if ($kiloBitrate < 1) {
throw new InvalidArgumentException('Wrong kiloBitrate value');
2012-04-13 12:45:41 +02:00
}
2013-06-25 10:03:20 +02:00
$this->audioKiloBitrate = (int) $kiloBitrate;
2012-05-25 16:21:16 +02:00
return $this;
2012-04-13 12:45:41 +02:00
}
2014-08-08 23:50:33 +02:00
/**
2014-06-25 09:55:00 +02:00
* {@inheritdoc}
*/
2014-08-08 23:50:33 +02:00
public function getAudioChannels()
{
return $this->audioChannels;
}
2014-06-25 09:55:00 +02:00
2014-08-08 23:50:33 +02:00
/**
2014-06-25 09:55:00 +02:00
* Sets the channels value.
*
* @param integer $channels
* @throws InvalidArgumentException
*/
public function setAudioChannels($channels)
{
if ($channels < 1) {
throw new InvalidArgumentException('Wrong channels value');
}
$this->audioChannels = (int) $channels;
return $this;
}
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
*/
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0)
2012-04-13 12:45:41 +02:00
{
2013-06-25 10:03:20 +02:00
$format = $this;
$listener = new AudioProgressListener($ffprobe, $media->getPathfile(), $pass, $total);
$listener->on('progress', function () use ($media, $format) {
$format->emit('progress', array_merge(array($media, $format), func_get_args()));
});
2012-04-13 12:45:41 +02:00
2013-06-25 10:03:20 +02:00
return array($listener);
2012-04-13 12:45:41 +02:00
}
/**
* {@inheritDoc}
*/
public function getPasses()
{
return 1;
}
2012-04-13 12:45:41 +02:00
}