/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Format/Audio/DefaultAudio.php |
@@ -0,0 +1,142 @@ |
<?php |
|
/* |
* 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. |
*/ |
|
namespace FFMpeg\Format\Audio; |
|
use Evenement\EventEmitter; |
use FFMpeg\Exception\InvalidArgumentException; |
use FFMpeg\Format\AudioInterface; |
use FFMpeg\Media\MediaTypeInterface; |
use FFMpeg\Format\ProgressableInterface; |
use FFMpeg\Format\ProgressListener\AudioProgressListener; |
use FFMpeg\FFProbe; |
|
abstract class DefaultAudio extends EventEmitter implements AudioInterface, ProgressableInterface |
{ |
/** @var string */ |
protected $audioCodec; |
|
/** @var integer */ |
protected $audioKiloBitrate = 128; |
|
/** @var integer */ |
protected $audioChannels = null; |
|
/** |
* {@inheritdoc} |
*/ |
public function getExtraParams() |
{ |
return array(); |
} |
|
/** |
* {@inheritdoc} |
*/ |
public function getAudioCodec() |
{ |
return $this->audioCodec; |
} |
|
/** |
* Sets the audio codec, Should be in the available ones, otherwise an |
* exception is thrown. |
* |
* @param string $audioCodec |
* |
* @throws InvalidArgumentException |
*/ |
public function setAudioCodec($audioCodec) |
{ |
if ( ! in_array($audioCodec, $this->getAvailableAudioCodecs())) { |
throw new InvalidArgumentException(sprintf( |
'Wrong audiocodec value for %s, available formats are %s' |
, $audioCodec, implode(', ', $this->getAvailableAudioCodecs()) |
)); |
} |
|
$this->audioCodec = $audioCodec; |
|
return $this; |
} |
|
/** |
* {@inheritdoc} |
*/ |
public function getAudioKiloBitrate() |
{ |
return $this->audioKiloBitrate; |
} |
|
/** |
* Sets the kiloBitrate value. |
* |
* @param integer $kiloBitrate |
* @throws InvalidArgumentException |
*/ |
public function setAudioKiloBitrate($kiloBitrate) |
{ |
if ($kiloBitrate < 1) { |
throw new InvalidArgumentException('Wrong kiloBitrate value'); |
} |
|
$this->audioKiloBitrate = (int) $kiloBitrate; |
|
return $this; |
} |
|
/** |
* {@inheritdoc} |
*/ |
public function getAudioChannels() |
{ |
return $this->audioChannels; |
} |
|
/** |
* 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; |
} |
|
/** |
* {@inheritdoc} |
*/ |
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total) |
{ |
$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())); |
}); |
|
return array($listener); |
} |
|
/** |
* {@inheritDoc} |
*/ |
public function getPasses() |
{ |
return 1; |
} |
} |
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Format/ProgressListener/AbstractProgressListener.php |
@@ -0,0 +1,262 @@ |
<?php |
|
/* |
* 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. |
*/ |
|
namespace FFMpeg\Format\ProgressListener; |
|
use Alchemy\BinaryDriver\Listeners\ListenerInterface; |
use Evenement\EventEmitter; |
use FFMpeg\FFProbe; |
use FFMpeg\Exception\RuntimeException; |
|
/** |
* @author Robert Gruendler <r.gruendler@gmail.com> |
*/ |
abstract class AbstractProgressListener extends EventEmitter implements ListenerInterface |
{ |
/** @var integer */ |
private $duration; |
|
/** @var integer */ |
private $totalSize; |
|
/** @var integer */ |
private $currentSize; |
|
/** @var integer */ |
private $currentTime; |
|
/** @var double */ |
private $lastOutput = null; |
|
/** @var FFProbe */ |
private $ffprobe; |
|
/** @var string */ |
private $pathfile; |
|
/** @var Boolean */ |
private $initialized = false; |
|
/** @var integer */ |
private $currentPass; |
|
/** @var integer */ |
private $totalPass; |
|
/** |
* Transcoding rate in kb/s |
* |
* @var integer |
*/ |
private $rate; |
|
/** |
* Percentage of transcoding progress (0 - 100) |
* |
* @var integer |
*/ |
private $percent = 0; |
|
/** |
* Time remaining (seconds) |
* |
* @var integer |
*/ |
private $remaining = null; |
|
/** |
* @param FFProbe $ffprobe |
* @param string $pathfile |
* @param integer $currentPass The cureent pass number |
* @param integer $totalPass The total number of passes |
* |
* @throws RuntimeException |
*/ |
public function __construct(FFProbe $ffprobe, $pathfile, $currentPass, $totalPass) |
{ |
$this->ffprobe = $ffprobe; |
$this->pathfile = $pathfile; |
$this->currentPass = $currentPass; |
$this->totalPass = $totalPass; |
} |
|
/** |
* @return FFProbe |
*/ |
public function getFFProbe() |
{ |
return $this->ffprobe; |
} |
|
/** |
* @return string |
*/ |
public function getPathfile() |
{ |
return $this->pathfile; |
} |
|
/** |
* @return integer |
*/ |
public function getCurrentPass() |
{ |
return $this->currentPass; |
} |
|
/** |
* @return integer |
*/ |
public function getTotalPass() |
{ |
return $this->totalPass; |
} |
|
/** |
* @return int |
*/ |
public function getCurrentTime() |
{ |
return $this->currentTime; |
} |
|
/** |
* {@inheritdoc} |
*/ |
public function handle($type, $data) |
{ |
if (null !== $progress = $this->parseProgress($data)) { |
$this->emit('progress', array_values($progress)); |
} |
} |
|
/** |
* {@inheritdoc} |
*/ |
public function forwardedEvents() |
{ |
return array(); |
} |
|
/** |
* Get the regex pattern to match a ffmpeg stderr status line |
*/ |
abstract protected function getPattern(); |
|
/** |
* @param string $progress A ffmpeg stderr progress output |
* |
* @return array the progressinfo array or null if there's no progress available yet. |
*/ |
private function parseProgress($progress) |
{ |
if (!$this->initialized) { |
$this->initialize(); |
} |
|
if (null === $this->totalSize || null === $this->duration) { |
return; |
} |
|
$matches = array(); |
|
if (preg_match($this->getPattern(), $progress, $matches) !== 1) { |
return null; |
} |
|
$currentDuration = $this->convertDuration($matches[2]); |
$currentTime = microtime(true); |
$currentSize = trim(str_replace('kb', '', strtolower(($matches[1])))); |
$percent = max(0, min(1, $currentDuration / $this->duration)); |
|
if ($this->lastOutput !== null) { |
$delta = $currentTime - $this->lastOutput; |
|
// Check the type of the currentSize variable and convert it to an integer if needed. |
if(!is_numeric($currentSize)) { |
$currentSize = (int)$currentSize; |
} |
|
$deltaSize = $currentSize - $this->currentSize; |
$rate = $deltaSize * $delta; |
if ($rate > 0) { |
$totalDuration = $this->totalSize / $rate; |
$this->remaining = floor($totalDuration - ($totalDuration * $percent)); |
$this->rate = floor($rate); |
} else { |
$this->remaining = 0; |
$this->rate = 0; |
} |
} |
|
$percent = $percent / $this->totalPass + ($this->currentPass - 1) / $this->totalPass; |
|
$this->percent = floor($percent * 100); |
$this->lastOutput = $currentTime; |
$this->currentSize = (int) $currentSize; |
$this->currentTime = $currentDuration; |
|
return $this->getProgressInfo(); |
} |
|
/** |
* |
* @param string $rawDuration in the format 00:00:00.00 |
* @return number |
*/ |
private function convertDuration($rawDuration) |
{ |
$ar = array_reverse(explode(":", $rawDuration)); |
$duration = floatval($ar[0]); |
if (!empty($ar[1])) { |
$duration += intval($ar[1]) * 60; |
} |
if (!empty($ar[2])) { |
$duration += intval($ar[2]) * 60 * 60; |
} |
|
return $duration; |
} |
|
/** |
* @return array |
*/ |
private function getProgressInfo() |
{ |
if ($this->remaining === null) { |
return null; |
} |
|
return array( |
'percent' => $this->percent, |
'remaining' => $this->remaining, |
'rate' => $this->rate |
); |
} |
|
private function initialize() |
{ |
try { |
$format = $this->ffprobe->format($this->pathfile); |
} catch (RuntimeException $e) { |
return; |
} |
|
if (false === $format->has('size') || false === $format->has('duration')) { |
return; |
} |
|
$this->totalSize = $format->get('size') / 1024; |
$this->duration = $format->get('duration'); |
|
$this->initialized = true; |
} |
} |
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Format/Video/DefaultVideo.php |
@@ -0,0 +1,141 @@ |
<?php |
|
/* |
* 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. |
*/ |
|
namespace FFMpeg\Format\Video; |
|
use FFMpeg\FFProbe; |
use FFMpeg\Exception\InvalidArgumentException; |
use FFMpeg\Format\Audio\DefaultAudio; |
use FFMpeg\Format\VideoInterface; |
use FFMpeg\Media\MediaTypeInterface; |
use FFMpeg\Format\ProgressListener\VideoProgressListener; |
|
/** |
* The abstract default Video format |
*/ |
abstract class DefaultVideo extends DefaultAudio implements VideoInterface |
{ |
/** @var string */ |
protected $videoCodec; |
|
/** @var Integer */ |
protected $kiloBitrate = 1000; |
|
/** @var Integer */ |
protected $modulus = 16; |
|
/** @var Array */ |
protected $additionalParamaters; |
|
/** |
* {@inheritdoc} |
*/ |
public function getKiloBitrate() |
{ |
return $this->kiloBitrate; |
} |
|
/** |
* Sets the kiloBitrate value. |
* |
* @param integer $kiloBitrate |
* @throws InvalidArgumentException |
*/ |
public function setKiloBitrate($kiloBitrate) |
{ |
if ($kiloBitrate < 1) { |
throw new InvalidArgumentException('Wrong kiloBitrate value'); |
} |
|
$this->kiloBitrate = (int) $kiloBitrate; |
|
return $this; |
} |
|
/** |
* {@inheritdoc} |
*/ |
public function getVideoCodec() |
{ |
return $this->videoCodec; |
} |
|
/** |
* Sets the video codec, Should be in the available ones, otherwise an |
* exception is thrown. |
* |
* @param string $videoCodec |
* @throws InvalidArgumentException |
*/ |
public function setVideoCodec($videoCodec) |
{ |
if ( ! in_array($videoCodec, $this->getAvailableVideoCodecs())) { |
throw new InvalidArgumentException(sprintf( |
'Wrong videocodec value for %s, available formats are %s' |
, $videoCodec, implode(', ', $this->getAvailableVideoCodecs()) |
)); |
} |
|
$this->videoCodec = $videoCodec; |
|
return $this; |
} |
|
/** |
* @return integer |
*/ |
public function getModulus() |
{ |
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; |
} |
|
/** |
* {@inheritdoc} |
*/ |
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total) |
{ |
$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; |
} |
} |
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Format/Video/X264.php |
@@ -0,0 +1,94 @@ |
<?php |
|
/* |
* 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. |
*/ |
|
namespace FFMpeg\Format\Video; |
|
/** |
* The X264 video format |
*/ |
class X264 extends DefaultVideo |
{ |
/** @var boolean */ |
private $bframesSupport = true; |
|
/** @var integer */ |
private $passes = 2; |
|
public function __construct($audioCodec = 'libfaac', $videoCodec = 'libx264') |
{ |
$this |
->setAudioCodec($audioCodec) |
->setVideoCodec($videoCodec); |
} |
|
/** |
* {@inheritDoc} |
*/ |
public function supportBFrames() |
{ |
return $this->bframesSupport; |
} |
|
/** |
* @param $support |
* |
* @return X264 |
*/ |
public function setBFramesSupport($support) |
{ |
$this->bframesSupport = $support; |
|
return $this; |
} |
|
/** |
* {@inheritDoc} |
*/ |
public function getAvailableAudioCodecs() |
{ |
return array('aac', 'libvo_aacenc', 'libfaac', 'libmp3lame', 'libfdk_aac'); |
} |
|
/** |
* {@inheritDoc} |
*/ |
public function getAvailableVideoCodecs() |
{ |
return array('libx264'); |
} |
|
/** |
* @param $passes |
* |
* @return X264 |
*/ |
public function setPasses($passes) |
{ |
$this->passes = $passes; |
return $this; |
} |
|
/** |
* {@inheritDoc} |
*/ |
public function getPasses() |
{ |
return $this->passes; |
} |
|
/** |
* @return int |
*/ |
public function getModulus() |
{ |
return 2; |
} |
} |
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Format/VideoInterface.php |
@@ -0,0 +1,64 @@ |
<?php |
|
/* |
* 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. |
*/ |
|
namespace FFMpeg\Format; |
|
interface VideoInterface extends AudioInterface |
{ |
/** |
* Gets the kiloBitrate value. |
* |
* @return integer |
*/ |
public function getKiloBitrate(); |
|
/** |
* Returns the modulus used by the Resizable video. |
* |
* This used to calculate the target dimensions while maintaining the best |
* aspect ratio. |
* |
* @see http://www.undeadborn.net/tools/rescalculator.php |
* |
* @return integer |
*/ |
public function getModulus(); |
|
/** |
* Returns the video codec. |
* |
* @return string |
*/ |
public function getVideoCodec(); |
|
/** |
* Returns true if the current format supports B-Frames. |
* |
* @see https://wikipedia.org/wiki/Video_compression_picture_types |
* |
* @return Boolean |
*/ |
public function supportBFrames(); |
|
/** |
* Returns the list of available video codecs for this format. |
* |
* @return array |
*/ |
public function getAvailableVideoCodecs(); |
|
/** |
* Returns the list of available video codecs for this format. |
* |
* @return array |
*/ |
public function getAdditionalParameters(); |
} |