First implemtation of the waveform feature

This commit is contained in:
Romain Biard 2016-11-15 16:54:46 -03:00
commit b7a8be46aa
5 changed files with 300 additions and 0 deletions

View file

@ -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\Waveform;
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Media\Waveform;
interface WaveformFilterInterface extends FilterInterface
{
public function apply(Waveform $waveform);
}

View file

@ -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\Waveform;
use FFMpeg\Media\Waveform;
class WaveformFilters
{
private $waveform;
public function __construct(Waveform $waveform)
{
$this->waveform = $waveform;
}
/**
* 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;
}
}

View file

@ -0,0 +1,69 @@
<?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\Waveform;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Waveform;
class WaveformRatioFixerFilter implements WaveformFilterInterface
{
/** @var boolean */
private $downmix;
// By default, the downmix value is set to FALSE.
public function __construct($downmix = FALSE)
{
$this->downmix = $downmix;
}
/**
* {@inheritdoc}
*/
public function getDownmix()
{
return $this->downmix;
}
/**
* {@inheritdoc}
*/
public function apply(Waveform $waveform)
{
$dimensions = null;
$commands = array();
foreach ($waveform->getVideo()->getStreams() as $stream) {
if ($stream->isVideo()) {
try {
// Get the dimensions of the video
$dimensions = $stream->getDimensions();
// If the downmix parameter is set to TRUE, we add an option to the FFMPEG command
if(!$this->downmix) {
$commands[] = '"showwavespic=s=' . $dimensions->getWidth() . 'x' . $dimensions->getHeight().'"';
}
else {
$commands[] = '"aformat=channel_layouts=mono,showwavespic=s=' . $dimensions->getWidth() . 'x' . $dimensions->getHeight().'"';
}
break;
} catch (RuntimeException $e) {
}
}
}
return $commands;
}
}