ffmpeg-mappable-media/src/Stream.php

77 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Danjones\FFMpeg;
use FFMpeg\Format\FormatInterface;
class Stream
{
use Traits\HasMetadata;
protected Map $map;
protected FormatInterface $codec;
protected string $input = '0:0';
protected array $flags = [];
public function __construct(Map $map)
{
$this->map = $map;
}
public function setInput(string $input): static
{
$this->input = $input;
return $this;
}
public function addFlag(string $key, string $value): static
{
$this->flags[$key] = $value;
return $this;
}
public function setCodec(FormatInterface $codec): static
{
$this->codec = $codec;
return $this;
}
protected function parseCodec(): static
{
// @todo
$this->addFlag('c', 'libx265');
return $this;
}
public function saveStream(): Map
{
$this->map->saveStream($this);
return $this->map;
}
public function buildCommand(int $idx = 0): array
{
$this->parseCodec();
$commands = [];
$commands[] = '-map';
$commands[] = $this->input;
foreach ($this->flags as $k => $v) {
array_push($commands, "-{$k}:{$idx}", $v);
}
foreach ($this->metadata as $k => $v) {
array_push($commands, "-metadata:s:{$idx}", "{$k}={$v}");
}
return $commands;
}
}