1

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?

1
  • The question is not off topic. Are we to close all issues in WordPress with solutions that do not require changes to the WordPress source code?
    – Keyslinger
    Commented Mar 30, 2021 at 23:59

2 Answers 2

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.

1
  • This question is not off-topic. See the images in the question.
    – Keyslinger
    Commented Mar 29, 2021 at 3:36
0

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
1
  • Also, I heard anecdotal advice suggesting that mp3s with constant bit rates (CBR) tend to have more reliable duration values than ones with variable bit rates (VBR)
    – Keyslinger
    Commented Mar 18, 2021 at 4:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.