2022-08-21 20:47:05 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Danjones\FFMpeg;
|
|
|
|
|
|
|
|
|
|
class Map
|
|
|
|
|
{
|
|
|
|
|
protected MappableMedia $media;
|
|
|
|
|
protected string $path;
|
2022-08-21 22:42:02 -05:00
|
|
|
/** @var Stream[] */
|
|
|
|
|
protected array $streams = [];
|
|
|
|
|
protected array $metadata = [];
|
2022-08-21 20:47:05 -05:00
|
|
|
|
|
|
|
|
public function __construct(MappableMedia $media)
|
|
|
|
|
{
|
|
|
|
|
$this->media = $media;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveMap(): MappableMedia
|
|
|
|
|
{
|
|
|
|
|
$this->media->saveMap($this);
|
|
|
|
|
|
|
|
|
|
return $this->media;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveAs(string $path): static
|
|
|
|
|
{
|
|
|
|
|
$this->path = $path;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2022-08-21 22:42:02 -05:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2022-08-21 20:47:05 -05:00
|
|
|
}
|