diff --git a/src/Map.php b/src/Map.php index 787a2f6..b427110 100644 --- a/src/Map.php +++ b/src/Map.php @@ -6,6 +6,9 @@ class Map { protected MappableMedia $media; protected string $path; + /** @var Stream[] */ + protected array $streams = []; + protected array $metadata = []; public function __construct(MappableMedia $media) { @@ -25,4 +28,31 @@ class Map return $this; } + + public function addMetadata(array|string $keyOrData, string $value = null): static + { + if (is_array($keyOrData)) { + array_walk($keyOrData, fn($v, $k) => $this->addMetadata($k, $v)); + + return $this; + } + + $this->metadata[$keyOrData] = $value; + + return $this; + } + + public function buildCommand(): array + { + $commands = []; + foreach ($this->streams as $idx => $stream) { + array_push($commands, ...$stream->buildCommand($idx)); + } + foreach ($this->metadata as $k => $v) { + array_push($commands, '-metadata', "{$k}={$v}"); + } + $commands[] = $this->path; + + return $commands; + } } diff --git a/src/MappableMedia.php b/src/MappableMedia.php index c4881ad..c25530b 100644 --- a/src/MappableMedia.php +++ b/src/MappableMedia.php @@ -322,9 +322,11 @@ class MappableMedia extends AbstractMediaType */ protected function buildMaps(array $maps): array { - $out = []; - // @todo + $commands = []; + foreach($maps as $map) { + array_push($commands, ...$map->buildCommand()); + } - return $out; + return $commands; } }