forked from PHP-FFMpeg/PHP-FFMpeg
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add missing headers * add audio clip filter and improve timecode * php 5.4 :( * prevent audio from being reencoded * php 5.x: Really? * fix tests... I need to concentrate...
- Loading branch information
Showing
6 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Tests\FFMpeg\Unit\Filters\Audio; | ||
|
||
use FFMpeg\Filters\Audio\AudioFilters; | ||
use FFMpeg\Coordinate\TimeCode; | ||
use Tests\FFMpeg\Unit\TestCase; | ||
|
||
class AudioClipTest extends TestCase { | ||
|
||
public function testClipping() { | ||
$capturedFilter = null; | ||
|
||
$audio = $this->getAudioMock(); | ||
$audio->expects($this->once()) | ||
->method('addFilter') | ||
->with($this->isInstanceOf('FFMpeg\Filters\Audio\AudioClipFilter')) | ||
->will($this->returnCallback(function ($filter) use (&$capturedFilter) { | ||
$capturedFilter = $filter; | ||
})); | ||
$format = $this->getMock('FFMpeg\Format\AudioInterface'); | ||
|
||
$filters = new AudioFilters($audio); | ||
|
||
$filters->clip(TimeCode::fromSeconds(5)); | ||
$this->assertEquals(array(0 => '-ss', 1 => '00:00:05.00', 2 => '-acodec', 3 => 'copy'), $capturedFilter->apply($audio, $format)); | ||
} | ||
|
||
public function testClippingWithDuration() { | ||
$capturedFilter = null; | ||
|
||
$audio = $this->getAudioMock(); | ||
$audio->expects($this->once()) | ||
->method('addFilter') | ||
->with($this->isInstanceOf('FFMpeg\Filters\Audio\AudioClipFilter')) | ||
->will($this->returnCallback(function ($filter) use (&$capturedFilter) { | ||
$capturedFilter = $filter; | ||
})); | ||
$format = $this->getMock('FFMpeg\Format\AudioInterface'); | ||
|
||
$filters = new AudioFilters($audio); | ||
|
||
$filters->clip(TimeCode::fromSeconds(5), TimeCode::fromSeconds(5)); | ||
$this->assertEquals(array(0 => '-ss', 1 => '00:00:05.00', 2 => '-t', 3 => '00:00:05.00', 4 => '-acodec', 5 => 'copy'), $capturedFilter->apply($audio, $format)); | ||
} | ||
|
||
} |