Version 0.3
This commit is contained in:
parent
0d69145ec3
commit
ad3a5af623
130 changed files with 7283 additions and 2627 deletions
80
src/FFMpeg/FFProbe/DataMapping/AbstractData.php
Normal file
80
src/FFMpeg/FFProbe/DataMapping/AbstractData.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?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\FFProbe\DataMapping;
|
||||
|
||||
use FFMpeg\Exception\InvalidArgumentException;
|
||||
|
||||
abstract class AbstractData implements \Countable
|
||||
{
|
||||
private $properties;
|
||||
|
||||
public function __construct(array $properties)
|
||||
{
|
||||
$this->properties = $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if data has property
|
||||
*
|
||||
* @param string $property
|
||||
* @return Boolean
|
||||
*/
|
||||
public function has($property)
|
||||
{
|
||||
return isset($this->properties[$property]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property value given its name
|
||||
*
|
||||
* @param string $property
|
||||
* @return mixed
|
||||
*
|
||||
* @throws InvalidArgumentException In case the data does not have the property
|
||||
*/
|
||||
public function get($property)
|
||||
{
|
||||
if (!isset($this->properties[$property])) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid property `%s`.', $property));
|
||||
}
|
||||
|
||||
return $this->properties[$property];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all property names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function keys()
|
||||
{
|
||||
return array_keys($this->properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all properties and their values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->properties);
|
||||
}
|
||||
}
|
||||
16
src/FFMpeg/FFProbe/DataMapping/Format.php
Normal file
16
src/FFMpeg/FFProbe/DataMapping/Format.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?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\FFProbe\DataMapping;
|
||||
|
||||
class Format extends AbstractData
|
||||
{
|
||||
}
|
||||
35
src/FFMpeg/FFProbe/DataMapping/Stream.php
Normal file
35
src/FFMpeg/FFProbe/DataMapping/Stream.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?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\FFProbe\DataMapping;
|
||||
|
||||
class Stream extends AbstractData
|
||||
{
|
||||
/**
|
||||
* Returns true if the stream is an audio stream
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function isAudio()
|
||||
{
|
||||
return $this->has('codec_type') ? 'audio' === $this->get('codec_type') : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the stream is a video stream
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function isVideo()
|
||||
{
|
||||
return $this->has('codec_type') ? 'video' === $this->get('codec_type') : false;
|
||||
}
|
||||
}
|
||||
99
src/FFMpeg/FFProbe/DataMapping/StreamCollection.php
Normal file
99
src/FFMpeg/FFProbe/DataMapping/StreamCollection.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?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\FFProbe\DataMapping;
|
||||
|
||||
class StreamCollection implements \Countable, \IteratorAggregate
|
||||
{
|
||||
private $streams;
|
||||
|
||||
public function __construct(array $streams = array())
|
||||
{
|
||||
$this->streams = array_values($streams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first stream of the collection, null if the collection is
|
||||
* empty.
|
||||
*
|
||||
* @return null|Stream
|
||||
*/
|
||||
public function first()
|
||||
{
|
||||
$stream = reset($this->streams);
|
||||
|
||||
return $stream ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a stream to the collection
|
||||
*
|
||||
* @param Stream $stream
|
||||
*
|
||||
* @return StreamCollection
|
||||
*/
|
||||
public function add(Stream $stream)
|
||||
{
|
||||
$this->streams[] = $stream;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new StreamCollection with only video streams
|
||||
*
|
||||
* @return StreamCollection
|
||||
*/
|
||||
public function videos()
|
||||
{
|
||||
return new static(array_filter($this->streams, function (Stream $stream) {
|
||||
return $stream->isVideo();
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new StreamCollection with only audio streams
|
||||
*
|
||||
* @return StreamCollection
|
||||
*/
|
||||
public function audios()
|
||||
{
|
||||
return new static(array_filter($this->streams, function (Stream $stream) {
|
||||
return $stream->isAudio();
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->streams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of contained streams
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->streams;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->streams);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue