🚧 Add stream to map
Still need to handle the codecs. But almost there.
This commit is contained in:
parent
90906a517d
commit
de5cf914da
4 changed files with 113 additions and 8 deletions
22
src/Map.php
22
src/Map.php
|
|
@ -4,11 +4,12 @@ namespace Danjones\FFMpeg;
|
|||
|
||||
class Map
|
||||
{
|
||||
use Traits\HasMetadata;
|
||||
|
||||
protected MappableMedia $media;
|
||||
protected string $path;
|
||||
/** @var Stream[] */
|
||||
protected array $streams = [];
|
||||
protected array $metadata = [];
|
||||
|
||||
public function __construct(MappableMedia $media)
|
||||
{
|
||||
|
|
@ -29,15 +30,22 @@ class Map
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function addMetadata(array|string $keyOrData, string $value = null): static
|
||||
public function stream(callable $callback = null): Stream|static
|
||||
{
|
||||
if (is_array($keyOrData)) {
|
||||
array_walk($keyOrData, fn($v, $k) => $this->addMetadata($k, $v));
|
||||
|
||||
return $this;
|
||||
$stream = new Stream($this);
|
||||
if (!$callback) {
|
||||
return $stream;
|
||||
}
|
||||
|
||||
$this->metadata[$keyOrData] = $value;
|
||||
$callback($stream);
|
||||
$this->saveStream($stream);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function saveStream(Stream $stream): static
|
||||
{
|
||||
$this->streams[] = $stream;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue