scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 114  →  ?path2? @ 115
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Audio/AddMetadataFilter.php
@@ -0,0 +1,58 @@
<?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\Filters\Audio;
 
use FFMpeg\Filters\Audio\AudioFilterInterface;
use FFMpeg\Format\AudioInterface;
use FFMpeg\Media\Audio;
 
class AddMetadataFilter implements AudioFilterInterface
{
/** @var Array */
private $metaArr;
/** @var Integer */
private $priority;
 
function __construct($metaArr = null, $priority = 9)
{
$this->metaArr = $metaArr;
$this->priority = $priority;
}
 
public function getPriority()
{
//must be of high priority in case theres a second input stream (artwork) to register with audio
return $this->priority;
}
 
public function apply(Audio $audio, AudioInterface $format)
{
$meta = $this->metaArr;
 
if (is_null($meta)) {
return ['-map_metadata', '-1', '-vn'];
}
 
$metadata = [];
 
if (array_key_exists("artwork", $meta)) {
array_push($metadata, "-i", $meta['artwork'], "-map", "0", "-map", "1");
unset($meta['artwork']);
}
 
foreach ($meta as $k => $v) {
array_push($metadata, "-metadata", "$k=$v");
}
 
return $metadata;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Audio/AudioClipFilter.php
@@ -0,0 +1,84 @@
<?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\Filters\Audio;
 
use FFMpeg\Coordinate\TimeCode;
use FFMpeg\Format\AudioInterface;
use FFMpeg\Media\Audio;
 
class AudioClipFilter implements AudioFilterInterface {
 
/**
* @var TimeCode
*/
private $start;
 
/**
* @var TimeCode
*/
private $duration;
 
/**
* @var int
*/
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;
}
 
/**
* Returns the start position the audio is being cutted
*
* @return TimeCode
*/
public function getStart() {
return $this->start;
}
 
/**
* Returns how long the audio is being cutted. Returns null when the duration is infinite,
*
* @return TimeCode|null
*/
public function getDuration() {
return $this->duration;
}
 
/**
* @inheritDoc
*/
public function apply(Audio $audio, AudioInterface $format) {
$commands = array('-ss', (string) $this->start);
 
if ($this->duration !== null) {
$commands[] = '-t';
$commands[] = (string) $this->duration;
}
 
$commands[] = '-acodec';
$commands[] = 'copy';
 
return $commands;
}
 
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Audio/AudioFilterInterface.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\Audio;
 
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Format\AudioInterface;
use FFMpeg\Media\Audio;
 
interface AudioFilterInterface extends FilterInterface
{
/**
* Applies the filter on the the Audio media given an format.
*
* @param Audio $audio
* @param AudioInterface $format
*
* @return array An array of arguments
*/
public function apply(Audio $audio, AudioInterface $format);
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Audio/AudioFilters.php
@@ -0,0 +1,74 @@
<?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\Filters\Audio;
 
use FFMpeg\Filters\Audio\AddMetadataFilter;
use FFMpeg\Media\Audio;
use FFMpeg\Coordinate\TimeCode;
 
class AudioFilters
{
protected $media;
 
public function __construct(Audio $media)
{
$this->media = $media;
}
 
/**
* Resamples the audio file.
*
* @param Integer $rate
*
* @return AudioFilters
*/
public function resample($rate)
{
$this->media->addFilter(new AudioResamplableFilter($rate));
 
return $this;
}
 
/**
* Add metadata to an audio file. If no arguments are given then filter
* will remove all metadata from the audio file
* @param Array|Null $data If array must contain one of these key/value pairs:
* - "title": Title metadata
* - "artist": Artist metadata
* - "composer": Composer metadata
* - "album": Album metadata
* - "track": Track metadata
* - "artwork": Song artwork. String of file path
* - "year": Year metadata
* - "genre": Genre metadata
* - "description": Description metadata
*/
public function addMetadata($data = null)
{
$this->media->addFilter(new AddMetadataFilter($data));
 
return $this;
}
 
/**
* Cuts the audio at `$start`, optionally define the end
*
* @param TimeCode $start Where the clipping starts(seek to time)
* @param TimeCode $duration How long the clipped audio should be
* @return AudioFilters
*/
public function clip($start, $duration = null) {
$this->media->addFilter(new AudioClipFilter($start, $duration));
 
return $this;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Audio/AudioResamplableFilter.php
@@ -0,0 +1,54 @@
<?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\Audio;
 
use FFMpeg\Format\AudioInterface;
use FFMpeg\Media\Audio;
 
class AudioResamplableFilter implements AudioFilterInterface
{
/** @var string */
private $rate;
/** @var integer */
private $priority;
 
public function __construct($rate, $priority = 0)
{
$this->rate = $rate;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
*
* @return Integer
*/
public function getRate()
{
return $this->rate;
}
 
/**
* {@inheritdoc}
*/
public function apply(Audio $audio, AudioInterface $format)
{
return array('-ac', 2, '-ar', $this->rate);
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Audio/SimpleFilter.php
@@ -0,0 +1,43 @@
<?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\Filters\Audio;
 
use FFMpeg\Media\Audio;
use FFMpeg\Format\AudioInterface;
 
class SimpleFilter implements AudioFilterInterface
{
private $params;
private $priority;
 
public function __construct(array $params, $priority = 0)
{
$this->params = $params;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* {@inheritdoc}
*/
public function apply(Audio $audio, AudioInterface $format)
{
return $this->params;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Concat/ConcatFilterInterface.php
@@ -0,0 +1,20 @@
<?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\Concat;
 
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Media\Concat;
 
interface ConcatFilterInterface extends FilterInterface
{
public function apply(Concat $concat);
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Concat/ConcatFilters.php
@@ -0,0 +1,24 @@
<?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\Concat;
 
use FFMpeg\Media\Concat;
 
class ConcatFilters
{
private $concat;
 
public function __construct(Concat $concat)
{
$this->concat = $concat;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/FilterInterface.php
@@ -0,0 +1,22 @@
<?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;
 
interface FilterInterface
{
/**
* Returns the priority of the filter.
*
* @return integer
*/
public function getPriority();
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/FiltersCollection.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;
 
class FiltersCollection implements \Countable, \IteratorAggregate
{
private $sorted;
private $filters = array();
 
/**
* @param FilterInterface $filter
*
* @return FiltersCollection
*/
public function add(FilterInterface $filter)
{
$this->filters[$filter->getPriority()][] = $filter;
$this->sorted = null;
 
return $this;
}
 
/**
* {@inheritdoc}
*/
public function count()
{
if (0 === count($this->filters)) {
return 0;
}
 
return count(call_user_func_array('array_merge', $this->filters));
}
 
/**
* {@inheritdoc}
*/
public function getIterator()
{
if (null === $this->sorted) {
if (0 === count($this->filters)) {
$this->sorted = $this->filters;
} else {
krsort($this->filters);
$this->sorted = call_user_func_array('array_merge', $this->filters);
}
}
 
return new \ArrayIterator($this->sorted);
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Frame/DisplayRatioFixerFilter.php
@@ -0,0 +1,58 @@
<?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\Frame;
 
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Frame;
 
class DisplayRatioFixerFilter implements FrameFilterInterface
{
/** @var integer */
private $priority;
 
public function __construct($priority = 0)
{
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* {@inheritdoc}
*/
public function apply(Frame $frame)
{
$dimensions = null;
$commands = array();
 
foreach ($frame->getVideo()->getStreams() as $stream) {
if ($stream->isVideo()) {
try {
$dimensions = $stream->getDimensions();
$commands[] = '-s';
$commands[] = $dimensions->getWidth() . 'x' . $dimensions->getHeight();
break;
} catch (RuntimeException $e) {
 
}
}
}
 
return $commands;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Frame/FrameFilterInterface.php
@@ -0,0 +1,20 @@
<?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\Frame;
 
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Media\Frame;
 
interface FrameFilterInterface extends FilterInterface
{
public function apply(Frame $frame);
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Frame/FrameFilters.php
@@ -0,0 +1,39 @@
<?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\Frame;
 
use FFMpeg\Media\Frame;
 
class FrameFilters
{
private $frame;
 
public function __construct(Frame $frame)
{
$this->frame = $frame;
}
 
/**
* Fixes the display ratio of the output frame.
*
* In case the sample ratio and display ratio are different, image may be
* anamorphozed. This filter fixes this by specifying the output size.
*
* @return FrameFilters
*/
public function fixDisplayRatio()
{
$this->frame->addFilter(new DisplayRatioFixerFilter());
 
return $this;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Gif/GifFilterInterface.php
@@ -0,0 +1,20 @@
<?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\Gif;
 
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Media\Gif;
 
interface GifFilterInterface extends FilterInterface
{
public function apply(Gif $gif);
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Gif/GifFilters.php
@@ -0,0 +1,24 @@
<?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\Gif;
 
use FFMpeg\Media\Gif;
 
class GifFilters
{
private $gif;
 
public function __construct(Gif $gif)
{
$this->gif = $gif;
}
}
/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));
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Waveform/WaveformDownmixFilter.php
@@ -0,0 +1,74 @@
<?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\Waveform;
 
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Waveform;
 
class WaveformDownmixFilter implements WaveformFilterInterface
{
 
/** @var boolean */
private $downmix;
/** @var integer */
private $priority;
 
// By default, the downmix value is set to FALSE.
public function __construct($downmix = FALSE, $priority = 0)
{
$this->downmix = $downmix;
$this->priority = $priority;
}
 
/**
* {@inheritdoc}
*/
public function getDownmix()
{
return $this->downmix;
}
 
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
 
/**
* {@inheritdoc}
*/
public function apply(Waveform $waveform)
{
$commands = array();
 
foreach ($waveform->getAudio()->getStreams() as $stream) {
if ($stream->isAudio()) {
try {
// If the downmix parameter is set to TRUE, we add an option to the FFMPEG command
if($this->downmix == TRUE) {
$commands[] = '"aformat=channel_layouts=mono"';
}
break;
 
} catch (RuntimeException $e) {
 
}
}
}
 
return $commands;
}
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Waveform/WaveformFilterInterface.php
@@ -0,0 +1,20 @@
<?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\Waveform;
 
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Media\Waveform;
 
interface WaveformFilterInterface extends FilterInterface
{
public function apply(Waveform $waveform);
}
/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Filters/Waveform/WaveformFilters.php
@@ -0,0 +1,38 @@
<?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\Waveform;
 
use FFMpeg\Media\Waveform;
 
class WaveformFilters
{
private $waveform;
 
public function __construct(Waveform $waveform)
{
$this->waveform = $waveform;
}
 
/**
* Sets the downmix of the output waveform.
*
* If you want a simpler waveform, sets the downmix to TRUE.
*
* @return WaveformFilters
*/
public function setDownmix()
{
$this->waveform->addFilter(new WaveformDownmixFilter());
 
return $this;
}
}