🚧 Add stream to map

Still need to handle the codecs. But almost there.
This commit is contained in:
Dan Jones 2022-08-23 15:25:27 -05:00
commit de5cf914da
4 changed files with 113 additions and 8 deletions

View file

@ -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;
}