ffmpeg-mappable-media/src/Map.php

67 lines
1.3 KiB
PHP
Raw Normal View History

2022-08-21 20:47:05 -05:00
<?php
namespace Danjones\FFMpeg;
class Map
{
use Traits\HasMetadata;
2022-08-21 20:47:05 -05:00
protected MappableMedia $media;
protected string $path;
2022-08-21 22:42:02 -05:00
/** @var Stream[] */
protected array $streams = [];
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 stream(callable $callback = null): Stream|static
2022-08-21 22:42:02 -05:00
{
$stream = new Stream($this);
if (!$callback) {
return $stream;
2022-08-21 22:42:02 -05:00
}
$callback($stream);
$this->saveStream($stream);
return $this;
}
public function saveStream(Stream $stream): static
{
$this->streams[] = $stream;
2022-08-21 22:42:02 -05:00
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
}