media = $media; } public function saveMap(): MappableMedia { $this->media->saveMap($this); return $this->media; } public function saveAs(string $path): static { $this->path = $path; return $this; } public function stream(callable $callback = null): Stream|static { $stream = new Stream($this); if (!$callback) { return $stream; } $callback($stream); $this->saveStream($stream); return $this; } public function saveStream(Stream $stream): static { $this->streams[] = $stream; $format = $stream->getCodec(); if ($format instanceof ProgressableInterface) { $listener = $format->createProgressListener( $this->media, $this->media->getFFProbe(), 1, 1, 0 ); $this->listeners = array_merge($this->listeners, $listener); } return $this; } public function getListeners(): array { return $this->listeners; } 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; } }