Skip to content

Commit

Permalink
#450 Ogg wrong duration
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHeinrich committed Aug 8, 2024
1 parent c4f10f7 commit 3a59f2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion getid3/getid3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions getid3/module.audio.ogg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3a59f2e

Please sign in to comment.