ffmpeg-mappable-media/src/FFMpeg/Format/Video/DefaultVideo.php

170 lines
4 KiB
PHP
Raw Normal View History

2012-04-13 10:20:54 +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\Video;
2012-04-13 10:20:54 +02:00
2013-06-25 10:03:20 +02:00
use FFMpeg\FFProbe;
2012-05-25 16:21:16 +02:00
use FFMpeg\Exception\InvalidArgumentException;
2013-06-25 10:03:20 +02:00
use FFMpeg\Format\Audio\DefaultAudio;
use FFMpeg\Format\VideoInterface;
use FFMpeg\Media\MediaTypeInterface;
use FFMpeg\Format\ProgressListener\VideoProgressListener;
2012-05-25 16:21:16 +02:00
2012-04-13 15:42:34 +02:00
/**
* The abstract default Video format
*/
2013-06-25 10:03:20 +02:00
abstract class DefaultVideo extends DefaultAudio implements VideoInterface
2012-04-13 10:20:54 +02:00
{
2013-06-25 10:03:20 +02:00
/** @var string */
2012-04-13 10:20:54 +02:00
protected $videoCodec;
2013-06-25 10:03:20 +02:00
/** @var Integer */
protected $kiloBitrate = 1000;
2013-06-25 10:03:20 +02:00
/** @var Integer */
protected $modulus = 16;
/** @var Array */
protected $additionalParamaters;
2020-02-24 21:42:38 +01:00
/** @var Array */
protected $initialParamaters;
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 getKiloBitrate()
2012-04-13 10:20:54 +02:00
{
2013-06-25 10:03:20 +02:00
return $this->kiloBitrate;
2012-04-13 10:20:54 +02:00
}
2012-04-13 15:42:34 +02:00
/**
2013-06-25 10:40:20 +02:00
* Sets the kiloBitrate value.
2012-05-25 16:21:16 +02:00
*
* @param int $kiloBitrate
2013-06-25 10:03:20 +02:00
* @throws InvalidArgumentException
2012-04-13 15:42:34 +02:00
*/
2013-06-25 10:03:20 +02:00
public function setKiloBitrate($kiloBitrate)
2012-04-13 10:20:54 +02:00
{
2013-06-25 10:03:20 +02:00
if ($kiloBitrate < 1) {
throw new InvalidArgumentException('Wrong kiloBitrate value');
2012-04-13 10:20:54 +02:00
}
2013-06-25 10:03:20 +02:00
$this->kiloBitrate = (int) $kiloBitrate;
2012-05-25 16:21:16 +02:00
return $this;
2012-04-13 10:20:54 +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 10:20:54 +02:00
public function getVideoCodec()
{
return $this->videoCodec;
}
2012-04-13 15:42:34 +02:00
/**
2013-06-25 10:03:20 +02:00
* Sets the video 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 $videoCodec
* @throws InvalidArgumentException
2012-04-13 15:42:34 +02:00
*/
2012-04-13 10:20:54 +02:00
public function setVideoCodec($videoCodec)
{
2012-04-27 00:48:57 +02:00
if ( ! in_array($videoCodec, $this->getAvailableVideoCodecs())) {
2012-05-25 16:21:16 +02:00
throw new InvalidArgumentException(sprintf(
2012-04-27 00:48:57 +02:00
'Wrong videocodec value for %s, available formats are %s'
, $videoCodec, implode(', ', $this->getAvailableVideoCodecs())
));
2012-04-13 10:20:54 +02:00
}
$this->videoCodec = $videoCodec;
2012-05-25 16:21:16 +02:00
return $this;
2012-04-13 10:20:54 +02:00
}
/**
* @return int
*/
2013-06-25 10:03:20 +02:00
public function getModulus()
{
2013-06-25 10:03:20 +02:00
return $this->modulus;
}
/**
* {@inheritdoc}
*/
public function getAdditionalParameters()
{
return $this->additionalParamaters;
}
/**
* Sets additional parameters.
*
* @param array $additionalParamaters
* @throws InvalidArgumentException
*/
public function setAdditionalParameters($additionalParamaters)
{
if (!is_array($additionalParamaters)) {
throw new InvalidArgumentException('Wrong additionalParamaters value');
}
$this->additionalParamaters = $additionalParamaters;
return $this;
}
2020-02-24 21:42:38 +01:00
/**
* {@inheritdoc}
*/
public function getInitialParameters()
{
return $this->initialParamaters;
}
/**
* Sets initial parameters.
*
* @param array $initialParamaters
* @throws InvalidArgumentException
*/
public function setInitialParameters($initialParamaters)
{
if (!is_array($initialParamaters)) {
throw new InvalidArgumentException('Wrong initialParamaters value');
}
$this->initialParamaters = $initialParamaters;
return $this;
}
/**
2013-06-25 10:03:20 +02:00
* {@inheritdoc}
*/
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0)
{
2013-06-25 10:03:20 +02:00
$format = $this;
$listeners = array(new VideoProgressListener($ffprobe, $media->getPathfile(), $pass, $total, $duration));
2013-06-25 10:03:20 +02:00
foreach ($listeners as $listener) {
$listener->on('progress', function () use ($format, $media) {
$format->emit('progress', array_merge(array($media, $format), func_get_args()));
});
}
return $listeners;
}
2012-04-13 15:42:34 +02:00
}