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

122 lines
2.8 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;
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
*
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 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
}
2012-10-31 00:30:24 +01:00
/**
* {@inheritDoc}
*/
public function getPasses()
{
return 1;
}
/**
2013-06-25 10:03:20 +02:00
* @return integer
*/
2013-06-25 10:03:20 +02:00
public function getModulus()
{
2013-06-25 10:03:20 +02:00
return $this->modulus;
}
/**
2013-06-25 10:03:20 +02:00
* {@inheritdoc}
*/
2013-06-25 10:03:20 +02:00
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total)
{
2013-06-25 10:03:20 +02:00
$format = $this;
$listeners = array(new VideoProgressListener($ffprobe, $media->getPathfile(), $pass, $total));
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
}