From e869ff2a593f6b0b03584330e2c8ec4bb97d620e Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 29 Aug 2022 10:02:04 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Set=20stream=20codecs=20properly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Format/DefaultAudio.php | 27 +++++++++++++++++ src/Format/DefaultSubtitle.php | 33 +++++++++++++++++++++ src/Format/DefaultVideo.php | 46 +++++++++++++++++++++++++++++ src/Stream.php | 54 +++++++++++++++++++++++++++------- 4 files changed, 149 insertions(+), 11 deletions(-) create mode 100644 src/Format/DefaultAudio.php create mode 100644 src/Format/DefaultSubtitle.php create mode 100644 src/Format/DefaultVideo.php 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; }