Add subtitles

This commit is contained in:
Dan Jones 2022-08-23 21:23:23 -05:00
commit d75d5c125b
2 changed files with 52 additions and 18 deletions

View file

@ -0,0 +1,12 @@
<?php
namespace Danjones\FFMpeg\Format;
use FFMpeg\Format\AudioInterface;
use FFMpeg\Format\FormatInterface;
use FFMpeg\Format\ProgressListener\AbstractProgressListener;
interface SubtitleInterface extends FormatInterface
{
public function getSubtitleCodec();
}

View file

@ -67,42 +67,67 @@ class Stream
return $this->parseAudio();
}
// @todo add subtitles
if ($this->codec instanceof Format\SubtitleInterface) {
return $this->parseSubtitle();
}
$this->addFlag('c', 'copy');
$this->parseExtras($this->codec->getExtraParameters());
return $this;
}
protected function parseSubtitle(): static
{
if (null !== ($codec = $this->codec->getSubtitleCodec())) {
$this->addFlag('c', $codec);
}
$this->parseExtras($this->codec->getExtraParameters());
return $this;
}
protected function parseAudio(): static
{
if (null !== ($codec = $format->getAudioCodec())) {
if (null !== ($codec = $this->codec->getAudioCodec())) {
$this->addFlag('c', $codec);
}
if (null !== ($kb = $format->getAudioKiloBitrate())) {
if (null !== ($kb = $this->codec->getAudioKiloBitrate())) {
$this->addFlag('b', "{$kb}k");
}
if (null !== ($channels = $format->getAudioChannels())) {
if (null !== ($channels = $this->codec->getAudioChannels())) {
$this->addFlag('ac', $channels);
}
$this->parseExtras($this->codec->getExtraParameters());
return $this;
}
protected function parseVideo(): static
{
if (null !== ($codec = $format->getVideoCodec())) {
if (null !== ($codec = $this->codec->getVideoCodec())) {
$this->addFlag('c', $codec);
}
if (0 !== ($kb = $format->getKiloBitrate())) {
if (0 !== ($kb = $this->codec->getKiloBitrate())) {
$this->addFlag('b', "{$kb}k");
}
// If the user passed some additional format parameters.
if (null !== ($params = $format->getAdditionalParameters())) {
$this->parseExtras($this->codec->getAdditionalParameters());
$this->parseExtras($this->codec->getExtraParameters());
return $this;
}
protected function parseExtras (?array $params): void
{
if (is_null($params)) {
return;
}
reset($params);
while(null !== key($params)) {
$key = current($params);
@ -115,9 +140,6 @@ class Stream
}
}
return $this;
}
public function saveStream(): Map
{
$this->map->saveStream($this);