PHP-MP3
PHP-MP3 copied to clipboard
Length of a trimmed MP3 is not set correctly
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.
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.
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.
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.
hi
stripTags()
worked for me!
example:
\falahati\PHPMP3\MpegAudio::fromFile($AudioFullPath)->trim(0, $length)->stripTags()->saveFile($AudioDemoFullPath);
thank you so much