Question

I'm uploading a different mp3 file to each post as an attachment and using wp_get_attachment_metadata() to print the duration of the mp3 file. Sometimes the response from wp_get_attachment_metadata() does not contain the file length and when I inspect the mp3s inside the Media Library, some of them display a length and some do not:

enter image description here   enter image description here

I suspect that there are some encoders that produce an mp3 with the length attribute and some that don't. So far I've tried Audacity's LAME encoder and Traktor Pro 2. Does anyone know a piece of software the will reliably give me the length attribute in for mp3s uploaded to WordPress or have some other means of resolving this issue?

Was it helpful?

Solution

I found that this issue could be overcome by opening the mp3 file in the excellent Linux/Windows application Mp3 Diags and applying the Rebuild VBR Data transformation. It discards the file's Xing header and attaches a new one.

After doing this, the files's duration and bitrate are listed in it's Attachment Details when it is uploaded to WordPress.

If you know simpler way to do this in Windows (for example via shell integration/file explorer context menus) or WordPress (via plugin, etc), I'll gladly mark your answer as the accepted answer.

OTHER TIPS

While my other solution resolved the issue describe in my question, I found that it caused inaccuracies in duration when the files were loaded into some podcast apps. The solution found here produces files that have durations in WordPress and show up in podcast apps with the correct duration:

ffmpeg -i file_orig.mp3 -acodec copy file_fixed.mp3
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top