Audio file’s length (duration) is missing from Attachment Details in Media Library

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:

Audio file's length (duration) is missing from Attachment Details in Media Library   Audio file's length (duration) is missing from Attachment Details in Media Library

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x