We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename the attached test.txt to test.mp3 (Github doesn't allow MP3 attachment).
test.mp3
The MP3 is detected as MPEG-2 Layer 3:
falahati\PHPMP3\MpegAudioFrameHeader Object ( [bitRate:falahati\PHPMP3\MpegAudioFrameHeader:private] => 48000 [sampleRate:falahati\PHPMP3\MpegAudioFrameHeader:private] => 11025 [version:falahati\PHPMP3\MpegAudioFrameHeader:private] => 2 [profile:falahati\PHPMP3\MpegAudioFrameHeader:private] => 3 [duration:falahati\PHPMP3\MpegAudioFrameHeader:private] => 0.1045 [offset:falahati\PHPMP3\MpegAudioFrameHeader:private] => 3336 [length:falahati\PHPMP3\MpegAudioFrameHeader:private] => 627 [padding:falahati\PHPMP3\MpegAudioFrameHeader:private] => 1 [errorProtection:falahati\PHPMP3\MpegAudioFrameHeader:private] => 1 [privateBit:falahati\PHPMP3\MpegAudioFrameHeader:private] => [copyrighted:falahati\PHPMP3\MpegAudioFrameHeader:private] => 1 [original:falahati\PHPMP3\MpegAudioFrameHeader:private] => 1 [mode:falahati\PHPMP3\MpegAudioFrameHeader:private] => 3 [middleSideStereoJoining:falahati\PHPMP3\MpegAudioFrameHeader:private] => [intensityStereoMode:falahati\PHPMP3\MpegAudioFrameHeader:private] => 0 )
The current length calculation in MpegAudioFrameHeader::tryParse() is:
length
MpegAudioFrameHeader::tryParse()
if ($frame->profile == self::Profile_1) { $frame->length = (((12 * $frame->bitRate) / $frame->sampleRate) + $frame->padding) * 4; } else if ($frame->profile == self::Profile_2 || $frame->profile == self::Profile_3) { $frame->length = ((144 * $frame->bitRate) / $frame->sampleRate) + $frame->padding; }
I cannot find a mention of this in the ISO, but I've seen several sources claim that MPEG-2 Layer 3 samples per frame is acutally 576 / 8 = 72 instead of 1152 / 8 = 144, for example, https://stackoverflow.com/questions/62536328/mpeg-2-and-2-5-problems-calculating-frame-sizes-in-bytes.
576 / 8 = 72
1152 / 8 = 144
Also, claims that padding should be part of the denominator (144 * bitRate / (sampleRate + padding) instead of 144 * bitRate / sampleRate + padding), for example, https://stackoverflow.com/questions/57103676/formula-from-mp3-frame-length.
144 * bitRate / (sampleRate + padding)
144 * bitRate / sampleRate + padding
When I try to append the test MP3 to another MP3 it fails because of this check in MpegAudio::read():
MpegAudio::read()
if ($this->memoryPointer >= $this->memoryLength) { return false; }
Updating the frame length calculation to $frame->length = 72 * $frame->bitRate / ($frame->sampleRate + $frame->padding); fixes this issue.
$frame->length = 72 * $frame->bitRate / ($frame->sampleRate + $frame->padding);
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Rename the attached test.txt to
test.mp3
(Github doesn't allow MP3 attachment).The MP3 is detected as MPEG-2 Layer 3:
The current
length
calculation inMpegAudioFrameHeader::tryParse()
is:I cannot find a mention of this in the ISO, but I've seen several sources claim that MPEG-2 Layer 3 samples per frame is acutally
576 / 8 = 72
instead of1152 / 8 = 144
, for example, https://stackoverflow.com/questions/62536328/mpeg-2-and-2-5-problems-calculating-frame-sizes-in-bytes.Also, claims that padding should be part of the denominator (
144 * bitRate / (sampleRate + padding)
instead of144 * bitRate / sampleRate + padding
), for example, https://stackoverflow.com/questions/57103676/formula-from-mp3-frame-length.When I try to append the test MP3 to another MP3 it fails because of this check in
MpegAudio::read()
:Updating the frame length calculation to
$frame->length = 72 * $frame->bitRate / ($frame->sampleRate + $frame->padding);
fixes this issue.The text was updated successfully, but these errors were encountered: