Skip to content
New issue

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

Length of a trimmed MP3 is not set correctly #14

Open
iFlash opened this issue Apr 24, 2023 · 4 comments
Open

Length of a trimmed MP3 is not set correctly #14

iFlash opened this issue Apr 24, 2023 · 4 comments

Comments

@iFlash
Copy link

iFlash commented Apr 24, 2023

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.

@falahati
Copy link
Owner

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.

@iFlash
Copy link
Author

iFlash commented Apr 24, 2023

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.

@hikashop-nicolas
Copy link

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.

@kafco
Copy link

kafco commented Jan 16, 2024

hi
stripTags() worked for me!

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

thank you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants