Merge pull request #50 from alchemy-fr/ffprobe-on-uris
Allow ffprobe on remote files
This commit is contained in:
commit
5cbec1981b
5 changed files with 52 additions and 19 deletions
|
|
@ -1,6 +1,10 @@
|
|||
CHANGELOG
|
||||
---------
|
||||
|
||||
* 0.3.1 (xx-xx-2013)
|
||||
|
||||
* Allow use of FFProbe on remote URIs.
|
||||
|
||||
* 0.3.0 (07-04-2013)
|
||||
|
||||
* Complete rewrite of the library, lots of BC breaks, check the doc.
|
||||
|
|
|
|||
13
README.md
13
README.md
|
|
@ -288,6 +288,19 @@ FFMpeg use many units for time and space coordinates.
|
|||
- `FFMpeg\Coordinate\Point` represent a point.
|
||||
- `FFMpeg\Coordinate\TimeCode` represent a timecode.
|
||||
|
||||
### FFProbe
|
||||
|
||||
`FFMpeg\FFProbe` is used internally by `FFMpeg\FFMpeg` to probe medias. You can
|
||||
also use it to extract media metadata.
|
||||
|
||||
```php
|
||||
$ffprobe = FFMpeg\FFProbe::create();
|
||||
$ffprobe
|
||||
->streams('/path/to/video/mp4') // extracts streams informations
|
||||
->videos() // filters video streams
|
||||
->first() // returns the first video stream
|
||||
->get('duration'); // returns the duration property
|
||||
```
|
||||
|
||||
##Using with Silex Microframework
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace FFMpeg;
|
||||
|
||||
use Alchemy\BinaryDriver\ConfigurationInterface;
|
||||
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use FFMpeg\Driver\FFProbeDriver;
|
||||
|
|
@ -207,12 +208,6 @@ class FFProbe
|
|||
|
||||
private function probe($pathfile, $command, $type, $allowJson = true)
|
||||
{
|
||||
if (!is_file($pathfile)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid filepath %s, unable to read.', $pathfile
|
||||
));
|
||||
}
|
||||
|
||||
$id = sprintf('%s-%s', $command, $pathfile);
|
||||
|
||||
if ($this->cache->contains($id)) {
|
||||
|
|
@ -237,7 +232,11 @@ class FFProbe
|
|||
$parseIsToDo = true;
|
||||
}
|
||||
|
||||
try {
|
||||
$output = $this->ffprobe->command($commands);
|
||||
} catch (ExecutionFailureException $e) {
|
||||
throw new RuntimeException(sprintf('Unable to probe %s', $pathfile), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
if ($parseIsToDo) {
|
||||
$data = $this->parser->parse($type, $output);
|
||||
|
|
|
|||
29
tests/FFMpeg/Functional/FFProbeTest.php
Normal file
29
tests/FFMpeg/Functional/FFProbeTest.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace FFMpeg\Functional;
|
||||
|
||||
use FFMpeg\FFProbe;
|
||||
|
||||
class FFProbeTest extends FunctionalTestCase
|
||||
{
|
||||
public function testProbeOnFile()
|
||||
{
|
||||
$ffprobe = FFProbe::create();
|
||||
$this->assertGreaterThan(0, count($ffprobe->streams(__DIR__ . '/../../files/Audio.mp3')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException FFMpeg\Exception\RuntimeException
|
||||
*/
|
||||
public function testProbeOnUnexistantFile()
|
||||
{
|
||||
$ffprobe = FFProbe::create();
|
||||
$ffprobe->streams('/path/to/no/file');
|
||||
}
|
||||
|
||||
public function testProbeOnRemoteFile()
|
||||
{
|
||||
$ffprobe = FFProbe::create();
|
||||
$this->assertGreaterThan(0, count($ffprobe->streams('http://video-js.zencoder.com/oceans-clip.mp4')));
|
||||
}
|
||||
}
|
||||
|
|
@ -228,18 +228,6 @@ class FFProbeTest extends TestCase
|
|||
$this->assertEquals($output, call_user_func(array($ffprobe, $method), $pathfile));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException FFMpeg\Exception\InvalidArgumentException
|
||||
* @dataProvider provideProbeMethod
|
||||
*/
|
||||
public function testProbeWithInvalidFile($method)
|
||||
{
|
||||
$pathfile = '/path/to/nofile';
|
||||
|
||||
$ffprobe = new FFProbe($this->getFFProbeDriverMock(), $this->getCacheMock());
|
||||
call_user_func(array($ffprobe, $method), $pathfile);
|
||||
}
|
||||
|
||||
public function provideProbeMethod()
|
||||
{
|
||||
return array(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue