diff --git a/src/Format/DefaultAudio.php b/src/Format/DefaultAudio.php new file mode 100644 index 0000000..cddae51 --- /dev/null +++ b/src/Format/DefaultAudio.php @@ -0,0 +1,27 @@ +setAudioCodec($codec); + $this->audioKiloBitrate = null; + $this->audioChannels = null; + } + + public function setAudioCodec($audioCodec) + { + $this->audioCodec = $audioCodec; + + return $this; + } + + public function getAvailableAudioCodecs() + { + return []; + } +} diff --git a/src/Format/DefaultSubtitle.php b/src/Format/DefaultSubtitle.php new file mode 100644 index 0000000..e3b4b08 --- /dev/null +++ b/src/Format/DefaultSubtitle.php @@ -0,0 +1,33 @@ +setSubtitleCodec($codec); + } + + public function setSubtitleCodec($subtitleCodec) + { + $this->subtitleCodec = $subtitleCodec; + + return $this; + } + + public function getSubtitleCodec() + { + return $this->subtitleCodec; + } + + public function getPasses() + { + return 1; + } + + public function getExtraParams() + { + return []; + } +} diff --git a/src/Format/DefaultVideo.php b/src/Format/DefaultVideo.php new file mode 100644 index 0000000..d9db5cf --- /dev/null +++ b/src/Format/DefaultVideo.php @@ -0,0 +1,46 @@ +setVideoCodec($codec); + $this->kiloBitrate = 0; + $this->modulus = 0; + } + + public function setVideoCodec($videoCodec) + { + $this->videoCodec = $videoCodec; + + return $this; + } + + public function getAvailableVideoCodecs() + { + return []; + } + + public function getAvailableAudioCodecs() + { + return []; + } + + public function supportBFrames() + { + return $this->supportsBFrames; + } + + public function setSupportBFrames(bool $supports = true): static + { + $this->supportsBFrames = $supports; + + return $this; + } +} diff --git a/src/Stream.php b/src/Stream.php index c3cb734..b686014 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -43,7 +43,45 @@ class Stream return $this; } - // @todo add hlper methods for setting codec + public function video(string $codec, callable $callback = null): static + { + $this->setCodec(new Format\DefaultVideo($codec)); + + if ($callback) { + return $this->editCodec($callback); + } + + return $this; + } + + public function audio(string $codec, callable $callback = null): static + { + $this->setCodec(new Format\DefaultAudio($codec)); + + if ($callback) { + return $this->editCodec($callback); + } + + return $this; + } + + + public function subtitle(string $codec, callable $callback = null): static + { + $this->setCodec(new Format\DefaultSubtitle($codec)); + + if ($callback) { + return $this->editCodec($callback); + } + + return $this; + } + + + public function copy(): static + { + return $this->setCodec(new Format\Copy()); + } public function getCodec(): FormatInterface { @@ -61,21 +99,15 @@ class Stream { if ($this->codec instanceof VideoInterface) { $this->parseVideo(); - } - - if ($this->codec instanceof AudioInterface) { + } elseif ($this->codec instanceof AudioInterface) { $this->parseAudio(); - } - - if ($this->codec instanceof Format\SubtitleInterface) { + } elseif ($this->codec instanceof Format\SubtitleInterface) { $this->parseSubtitle(); - } - - if ($this->codec instanceof Format\Copy) { + } elseif ($this->codec instanceof Format\Copy) { $this->addFlag('c', 'copy'); } - $this->parseExtras($this->codec->getExtraParameters()); + $this->parseExtras($this->codec->getExtraParams()); return $this; }