diff --git a/src/Format/SubtitleInterface.php b/src/Format/SubtitleInterface.php new file mode 100644 index 0000000..f4f4909 --- /dev/null +++ b/src/Format/SubtitleInterface.php @@ -0,0 +1,12 @@ +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())) { - reset($params); - while(null !== key($params)) { - $key = current($params); - $value = next($params); - if (null == key($params)) { - continue; - } - - $this->addFlag(ltrim($key, '-k'), $value); - } - } + $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); + $value = next($params); + if (null == key($params)) { + continue; + } + + $this->addFlag(ltrim($key, '-k'), $value); + } + } + public function saveStream(): Map { $this->map->saveStream($this);