From 3a59f2e0567cd560d5197638f35bc3b544896a70 Mon Sep 17 00:00:00 2001 From: James Heinrich Date: Thu, 8 Aug 2024 13:50:21 -0400 Subject: [PATCH] #450 Ogg wrong duration https://github.com/JamesHeinrich/getID3/issues/450 --- getid3/getid3.php | 2 +- getid3/module.audio.ogg.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/getid3/getid3.php b/getid3/getid3.php index 6a17cb04..94fb322f 100644 --- a/getid3/getid3.php +++ b/getid3/getid3.php @@ -387,7 +387,7 @@ class getID3 */ protected $startup_warning = ''; - const VERSION = '1.9.23-202408061058'; + const VERSION = '1.9.23-202408081349'; const FREAD_BUFFER_SIZE = 32768; const ATTACHMENTS_NONE = false; diff --git a/getid3/module.audio.ogg.php b/getid3/module.audio.ogg.php index ebd2b946..06452cbc 100644 --- a/getid3/module.audio.ogg.php +++ b/getid3/module.audio.ogg.php @@ -350,6 +350,12 @@ public function Analyze() { $this->fseek(max($info['avdataend'] - $this->getid3->fread_buffer_size(), 0)); $LastChunkOfOgg = strrev($this->fread($this->getid3->fread_buffer_size())); if ($LastOggSpostion = strpos($LastChunkOfOgg, 'SggO')) { + if (substr($LastChunkOfOgg, 13, 8) === "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF") { + // https://github.com/JamesHeinrich/getID3/issues/450 + // "Sometimes, Opus encoders (WhatsApp voice registrations and others) add a special last header with a granule duration of 0xFFFFFFFFFFFFFF. + // This value indicates "this is the end," but must be ignored; otherwise, it makes calculations wrong." + $LastOggSpostion = strpos($LastChunkOfOgg, 'SggO', $LastOggSpostion + 1); + } $this->fseek($info['avdataend'] - ($LastOggSpostion + strlen('SggO'))); $info['avdataend'] = $this->ftell(); $info['ogg']['pageheader']['eos'] = $this->ParseOggPageHeader();