scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 114  →  ?path2? @ 115
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/ClipFilter.php
@@ -0,0 +1,72 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Format\VideoInterface;
use FFMpeg\Media\Video;
use FFMpeg\Coordinate\TimeCode;
 
class ClipFilter implements VideoFilterInterface
{
/** @var TimeCode */
private $start;
/** @var TimeCode */
private $duration;
/** @var integer */
private $priority;
 
public function __construct(TimeCode $start, TimeCode $duration = null, $priority = 0)
{
$this->start = $start;
$this->duration = $duration;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* @return TimeCode
*/
public function getStart()
{
return $this->start;
}
 
/**
* @return TimeCode
*/
public function getDuration()
{
return $this->duration;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
$commands = array('-ss', (string) $this->start);
 
if ($this->duration !== null) {
$commands[] = '-t';
$commands[] = (string) $this->duration;
}
 
return $commands;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/CropFilter.php
@@ -0,0 +1,60 @@
<?php
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Coordinate\Point;
use FFMpeg\Format\VideoInterface;
use FFMpeg\Media\Video;
 
class CropFilter implements VideoFilterInterface
{
/** @var integer */
protected $priority;
/** @var Dimension */
protected $dimension;
/** @var Point */
protected $point;
 
public function __construct(Point $point, Dimension $dimension, $priority = 0)
{
$this->priority = $priority;
$this->dimension = $dimension;
$this->point = $point;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
foreach ($video->getStreams()->videos() as $stream) {
if ($stream->has('width') && $stream->has('height')) {
$stream->set('width', $this->dimension->getWidth());
$stream->set('height', $this->dimension->getHeight());
}
}
 
return array(
'-filter:v',
'crop=' .
$this->dimension->getWidth() .':' . $this->dimension->getHeight() . ':' . $this->point->getX() . ':' . $this->point->getY()
);
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/CustomFilter.php
@@ -0,0 +1,52 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Format\VideoInterface;
use FFMpeg\Media\Video;
 
class CustomFilter implements VideoFilterInterface
{
/** @var string */
private $filter;
/** @var integer */
private $priority;
 
/**
* A custom filter, useful if you want to build complex filters
*
* @param string $filter
* @param int $priority
*/
public function __construct($filter, $priority = 0)
{
$this->filter = $filter;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
$commands = array('-vf', $this->filter);
 
return $commands;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/ExtractMultipleFramesFilter.php
@@ -0,0 +1,128 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Strime <romain@strime.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Exception\InvalidArgumentException;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Video;
use FFMpeg\Format\VideoInterface;
 
class ExtractMultipleFramesFilter implements VideoFilterInterface
{
/** will extract a frame every second */
const FRAMERATE_EVERY_SEC = '1/1';
/** will extract a frame every 2 seconds */
const FRAMERATE_EVERY_2SEC = '1/2';
/** will extract a frame every 5 seconds */
const FRAMERATE_EVERY_5SEC = '1/5';
/** will extract a frame every 10 seconds */
const FRAMERATE_EVERY_10SEC = '1/10';
/** will extract a frame every 30 seconds */
const FRAMERATE_EVERY_30SEC = '1/30';
/** will extract a frame every minute */
const FRAMERATE_EVERY_60SEC = '1/60';
 
/** @var integer */
private $priority;
private $frameRate;
private $destinationFolder;
 
public function __construct($frameRate = self::FRAMERATE_EVERY_SEC, $destinationFolder = __DIR__, $priority = 0)
{
$this->priority = $priority;
$this->frameRate = $frameRate;
 
// Make sure that the destination folder has a trailing slash
if(strcmp( substr($destinationFolder, -1), "/") != 0)
$destinationFolder .= "/";
 
// Set the destination folder
$this->destinationFolder = $destinationFolder;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* {@inheritdoc}
*/
public function getFrameRate()
{
return $this->frameRate;
}
 
/**
* {@inheritdoc}
*/
public function getDestinationFolder()
{
return $this->destinationFolder;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
$commands = array();
$duration = 0;
 
try {
// Get the duration of the video
foreach ($video->getStreams()->videos() as $stream) {
if ($stream->has('duration')) {
$duration = $stream->get('duration');
}
}
 
// Get the number of frames per second we have to extract.
if(preg_match('/(\d+)(?:\s*)([\+\-\*\/])(?:\s*)(\d+)/', $this->frameRate, $matches) !== FALSE){
$operator = $matches[2];
 
switch($operator){
case '/':
$nbFramesPerSecond = $matches[1] / $matches[3];
break;
 
default:
throw new InvalidArgumentException('The frame rate is not a proper division: ' . $this->frameRate);
break;
}
}
 
// Set the number of digits to use in the exported filenames
$nbImages = ceil( $duration * $nbFramesPerSecond );
 
if($nbImages < 100)
$nbDigitsInFileNames = "02";
elseif($nbImages < 1000)
$nbDigitsInFileNames = "03";
else
$nbDigitsInFileNames = "06";
 
// Set the parameters
$commands[] = '-vf';
$commands[] = 'fps=' . $this->frameRate;
$commands[] = $this->destinationFolder . 'frame-%'.$nbDigitsInFileNames.'d.jpg';
}
catch (RuntimeException $e) {
throw new RuntimeException('An error occured while extracting the frames: ' . $e->getMessage() . '. The code: ' . $e->getCode());
}
 
return $commands;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/FrameRateFilter.php
@@ -0,0 +1,82 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Coordinate\FrameRate;
use FFMpeg\Media\Video;
use FFMpeg\Format\VideoInterface;
 
class FrameRateFilter implements VideoFilterInterface
{
private $rate;
private $gop;
private $priority;
 
public function __construct(FrameRate $rate, $gop, $priority = 0)
{
$this->rate = $rate;
$this->gop = $gop;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* Returns the frame rate.
*
* @return FrameRate
*/
public function getFrameRate()
{
return $this->rate;
}
 
/**
* Returns the GOP size.
*
* @see https://wikipedia.org/wiki/Group_of_pictures
*
* @return Integer
*/
public function getGOP()
{
return $this->gop;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
$commands = array('-r', $this->rate->getValue());
 
/**
* @see http://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
*/
if ($format->supportBFrames()) {
$commands[] = '-b_strategy';
$commands[] = '1';
$commands[] = '-bf';
$commands[] = '3';
$commands[] = '-g';
$commands[] = $this->gop;
}
 
return $commands;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/PadFilter.php
@@ -0,0 +1,59 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Strime <contact@strime.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Media\Video;
use FFMpeg\Format\VideoInterface;
 
class PadFilter implements VideoFilterInterface
{
/** @var Dimension */
private $dimension;
/** @var integer */
private $priority;
 
public function __construct(Dimension $dimension, $priority = 0)
{
$this->dimension = $dimension;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* @return Dimension
*/
public function getDimension()
{
return $this->dimension;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
$commands = array();
 
$commands[] = '-vf';
$commands[] = 'scale=iw*min(' . $this->dimension->getWidth() . '/iw\,' . $this->dimension->getHeight() .'/ih):ih*min(' . $this->dimension->getWidth() . '/iw\,' . $this->dimension->getHeight() .'/ih),pad=' . $this->dimension->getWidth() . ':' . $this->dimension->getHeight() . ':(' . $this->dimension->getWidth() . '-iw)/2:(' . $this->dimension->getHeight() .'-ih)/2';
 
return $commands;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/ResizeFilter.php
@@ -0,0 +1,143 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Video;
use FFMpeg\Format\VideoInterface;
 
class ResizeFilter implements VideoFilterInterface
{
/** fits to the dimensions, might introduce anamorphosis */
const RESIZEMODE_FIT = 'fit';
/** resizes the video inside the given dimension, no anamorphosis */
const RESIZEMODE_INSET = 'inset';
/** resizes the video to fit the dimension width, no anamorphosis */
const RESIZEMODE_SCALE_WIDTH = 'width';
/** resizes the video to fit the dimension height, no anamorphosis */
const RESIZEMODE_SCALE_HEIGHT = 'height';
 
/** @var Dimension */
private $dimension;
/** @var string */
private $mode;
/** @var Boolean */
private $forceStandards;
/** @var integer */
private $priority;
 
public function __construct(Dimension $dimension, $mode = self::RESIZEMODE_FIT, $forceStandards = true, $priority = 0)
{
$this->dimension = $dimension;
$this->mode = $mode;
$this->forceStandards = $forceStandards;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* @return Dimension
*/
public function getDimension()
{
return $this->dimension;
}
 
/**
* @return string
*/
public function getMode()
{
return $this->mode;
}
 
/**
* @return Boolean
*/
public function areStandardsForced()
{
return $this->forceStandards;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
$dimensions = null;
$commands = array();
 
foreach ($video->getStreams() as $stream) {
if ($stream->isVideo()) {
try {
$dimensions = $stream->getDimensions();
break;
} catch (RuntimeException $e) {
 
}
}
}
 
if (null !== $dimensions) {
$dimensions = $this->getComputedDimensions($dimensions, $format->getModulus());
 
// Using Filter to have ordering
$commands[] = '-vf';
$commands[] = '[in]scale=' . $dimensions->getWidth() . ':' . $dimensions->getHeight() . ' [out]';
}
 
return $commands;
}
 
private function getComputedDimensions(Dimension $dimension, $modulus)
{
$originalRatio = $dimension->getRatio($this->forceStandards);
 
switch ($this->mode) {
case self::RESIZEMODE_SCALE_WIDTH:
$height = $this->dimension->getHeight();
$width = $originalRatio->calculateWidth($height, $modulus);
break;
case self::RESIZEMODE_SCALE_HEIGHT:
$width = $this->dimension->getWidth();
$height = $originalRatio->calculateHeight($width, $modulus);
break;
case self::RESIZEMODE_INSET:
$targetRatio = $this->dimension->getRatio($this->forceStandards);
 
if ($targetRatio->getValue() > $originalRatio->getValue()) {
$height = $this->dimension->getHeight();
$width = $originalRatio->calculateWidth($height, $modulus);
} else {
$width = $this->dimension->getWidth();
$height = $originalRatio->calculateHeight($width, $modulus);
}
break;
case self::RESIZEMODE_FIT:
default:
$width = $this->dimension->getWidth();
$height = $this->dimension->getHeight();
break;
}
 
return new Dimension($width, $height);
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/RotateFilter.php
@@ -0,0 +1,82 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Exception\InvalidArgumentException;
use FFMpeg\Media\Video;
use FFMpeg\Format\VideoInterface;
 
class RotateFilter implements VideoFilterInterface
{
const ROTATE_90 = 'transpose=1';
const ROTATE_180 = 'hflip,vflip';
const ROTATE_270 = 'transpose=2';
 
/** @var string */
private $angle;
/** @var integer */
private $priority;
 
public function __construct($angle, $priority = 0)
{
$this->setAngle($angle);
$this->priority = (int) $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* @return Dimension
*/
public function getAngle()
{
return $this->angle;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
if (in_array($this->angle, array(self::ROTATE_90, self::ROTATE_270), true)) {
foreach ($video->getStreams()->videos() as $stream) {
if ($stream->has('width') && $stream->has('height')) {
$width = $stream->get('width');
$stream->set('width', $stream->get('height'));
$stream->set('height', $width);
}
}
}
 
return array('-vf', $this->angle, '-metadata:s:v:0', 'rotate=0');
}
 
private function setAngle($angle)
{
switch ($angle) {
case self::ROTATE_90:
case self::ROTATE_180:
case self::ROTATE_270:
$this->angle = $angle;
break;
default:
throw new InvalidArgumentException('Invalid angle value.');
}
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/SynchronizeFilter.php
@@ -0,0 +1,44 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Format\VideoInterface;
use FFMpeg\Media\Video;
 
/**
* Synchronizes audio and video in case of desynchronized movies.
*/
class SynchronizeFilter implements VideoFilterInterface
{
private $priority;
 
public function __construct($priority = 12)
{
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
return array('-async', '1', '-metadata:s:v:0', 'start_time=0');
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/VideoFilterInterface.php
@@ -0,0 +1,29 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Format\VideoInterface;
use FFMpeg\Media\Video;
 
interface VideoFilterInterface extends FilterInterface
{
/**
* Applies the filter on the the Video media given an format.
*
* @param Video $video
* @param VideoInterface $format
*
* @return array An array of arguments
*/
public function apply(Video $video, VideoInterface $format);
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/VideoFilters.php
@@ -0,0 +1,178 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Coordinate\Point;
use FFMpeg\Media\Video;
use FFMpeg\Coordinate\TimeCode;
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Coordinate\FrameRate;
use FFMpeg\Filters\Audio\AudioResamplableFilter;
use FFMpeg\Filters\Audio\AudioFilters;
 
class VideoFilters extends AudioFilters
{
public function __construct(Video $media)
{
parent::__construct($media);
}
 
/**
* Resizes a video to a given dimension.
*
* @param Dimension $dimension
* @param string $mode
* @param Boolean $forceStandards
*
* @return VideoFilters
*/
public function resize(Dimension $dimension, $mode = ResizeFilter::RESIZEMODE_FIT, $forceStandards = true)
{
$this->media->addFilter(new ResizeFilter($dimension, $mode, $forceStandards));
 
return $this;
}
 
/**
* Changes the video framerate.
*
* @param FrameRate $framerate
* @param Integer $gop
*
* @return VideoFilters
*/
public function framerate(FrameRate $framerate, $gop)
{
$this->media->addFilter(new FrameRateFilter($framerate, $gop));
 
return $this;
}
 
/**
* Extract multiple frames from the video
*
* @param string $frameRate
* @param string $destinationFolder
*
* @return $this
*/
public function extractMultipleFrames($frameRate = ExtractMultipleFramesFilter::FRAMERATE_EVERY_2SEC, $destinationFolder = __DIR__)
{
$this->media->addFilter(new ExtractMultipleFramesFilter($frameRate, $destinationFolder));
 
return $this;
}
 
/**
* Synchronizes audio and video.
*
* @return VideoFilters
*/
public function synchronize()
{
$this->media->addFilter(new SynchronizeFilter());
 
return $this;
}
 
/**
* Clips (cuts) the video.
*
* @param TimeCode $start
* @param TimeCode $duration
*
* @return VideoFilters
*/
public function clip($start, $duration = null)
{
$this->media->addFilter(new ClipFilter($start, $duration));
 
return $this;
}
 
/**
* Resamples the audio file.
*
* @param Integer $rate
*
* @return AudioFilters
*/
public function audioResample($rate)
{
$this->media->addFilter(new AudioResamplableFilter($rate));
 
return $this;
}
 
/**
* Adds padding (black bars) to a video.
*
* @param Dimension $dimension
*
* @return VideoFilters
*/
public function pad(Dimension $dimension)
{
$this->media->addFilter(new PadFilter($dimension));
 
return $this;
}
 
public function rotate($angle)
{
$this->media->addFilter(new RotateFilter($angle, 30));
 
return $this;
}
 
/**
* Crops the video
*
* @param Point $point
* @param Dimension $dimension
*
* @return VideoFilters
*/
public function crop(Point $point, Dimension $dimension)
{
$this->media->addFilter(new CropFilter($point, $dimension));
 
return $this;
}
 
/**
* @param string $imagePath
* @param array $coordinates
*
* @return $this
*/
public function watermark($imagePath, array $coordinates = array())
{
$this->media->addFilter(new WatermarkFilter($imagePath, $coordinates));
 
return $this;
}
 
/**
* Applies a custom filter: -vf foo bar
*
* @param string $parameters
*
* @return VideoFilters
*/
public function custom($parameters)
{
$this->media->addFilter(new CustomFilter($parameters));
 
return $this;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Video/WatermarkFilter.php
@@ -0,0 +1,80 @@
<?php
 
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <dev.team@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace FFMpeg\Filters\Video;
 
use FFMpeg\Exception\InvalidArgumentException;
use FFMpeg\Format\VideoInterface;
use FFMpeg\Media\Video;
 
class WatermarkFilter implements VideoFilterInterface
{
/** @var string */
private $watermarkPath;
/** @var array */
private $coordinates;
/** @var integer */
private $priority;
 
public function __construct($watermarkPath, array $coordinates = array(), $priority = 0)
{
if (!file_exists($watermarkPath)) {
throw new InvalidArgumentException(sprintf('File %s does not exist', $watermarkPath));
}
 
$this->watermarkPath = $watermarkPath;
$this->coordinates = $coordinates;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* {@inheritdoc}
*/
public function apply(Video $video, VideoInterface $format)
{
$position = isset($this->coordinates['position']) ? $this->coordinates['position'] : 'absolute';
 
switch ($position) {
case 'relative':
if (isset($this->coordinates['top'])) {
$y = $this->coordinates['top'];
} elseif (isset($this->coordinates['bottom'])) {
$y = sprintf('main_h - %d - overlay_h', $this->coordinates['bottom']);
} else {
$y = 0;
}
 
if (isset($this->coordinates['left'])) {
$x = $this->coordinates['left'];
} elseif (isset($this->coordinates['right'])) {
$x = sprintf('main_w - %d - overlay_w', $this->coordinates['right']);
} else {
$x = 0;
}
 
break;
default:
$x = isset($this->coordinates['x']) ? $this->coordinates['x'] : 0;
$y = isset($this->coordinates['y']) ? $this->coordinates['y'] : 0;
break;
}
 
return array('-vf', sprintf('movie=%s [watermark]; [in][watermark] overlay=%s:%s [out]', $this->watermarkPath, $x, $y));
}
}