PHP-MP3 icon indicating copy to clipboard operation
PHP-MP3 copied to clipboard

Length of a trimmed MP3 is not set correctly

Open iFlash opened this issue 1 year ago • 4 comments

When I trim an MP3 using

\falahati\PHPMP3\MpegAudio::fromFile($names[0])->trim(0, 30)->saveFile($trimmed='tmp/trimmed/trimmed.mp3');

the original length will show up in any given MP3 player when I open the trimmed file rather than 30s.

iFlash avatar Apr 24 '23 08:04 iFlash

try removing the metadata. the right length of a file should be deduced from the file size and the block size. if it shows another number for the duration, it is probably stored in the meta data of the MP3 file.

falahati avatar Apr 24 '23 13:04 falahati

Tried that doing this:

\falahati\PHPMP3\MpegAudio::fromFile($names[0])->trim(0, 30)->->stripTags()->saveFile($trimmed='tmp/trimmed/trimmed.mp3');

No difference, unfortunately. It seems that it works correctly with a few files, but it fails with most mp3s I try.

iFlash avatar Apr 24 '23 13:04 iFlash

I find the same issue on my end with all the MP3 files I tried. I also tried stripTags and it doesn't change anything. I checked the tags of the resulting file and they are empty. So it seems there is something else at play which leads to the player calculating the duration based on something which isn't updated in the resulting file when it is cut. Unfortunately, I don't understand the MP3 frame structure well enough to understand what's missing.

hikashop-nicolas avatar Dec 11 '23 18:12 hikashop-nicolas

hi stripTags() worked for me!

example: \falahati\PHPMP3\MpegAudio::fromFile($AudioFullPath)->trim(0, $length)->stripTags()->saveFile($AudioDemoFullPath);

thank you so much

kafco avatar Jan 16 '24 17:01 kafco