🚧 Add stream to map
Still need to handle the codecs. But almost there.
This commit is contained in:
parent
90906a517d
commit
de5cf914da
4 changed files with 113 additions and 8 deletions
76
src/Stream.php
Normal file
76
src/Stream.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue