First implemtation of the waveform feature
This commit is contained in:
parent
010b3b8a6d
commit
b7a8be46aa
5 changed files with 300 additions and 0 deletions
20
src/FFMpeg/Filters/Waveform/WaveformFilterInterface.php
Normal file
20
src/FFMpeg/Filters/Waveform/WaveformFilterInterface.php
Normal 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);
|
||||
}
|
||||
39
src/FFMpeg/Filters/Waveform/WaveformFilters.php
Normal file
39
src/FFMpeg/Filters/Waveform/WaveformFilters.php
Normal 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;
|
||||
}
|
||||
}
|
||||
69
src/FFMpeg/Filters/Waveform/WaveformRatioFixerFilter.php
Normal file
69
src/FFMpeg/Filters/Waveform/WaveformRatioFixerFilter.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue