✨ Add subtitles
This commit is contained in:
parent
c383f863e0
commit
d75d5c125b
2 changed files with 52 additions and 18 deletions
12
src/Format/SubtitleInterface.php
Normal file
12
src/Format/SubtitleInterface.php
Normal 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();
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue