5
$\begingroup$

I was making a video by combining some images and this audio, when I encounter the problem:

I need to get the duration of the audio, and when I use Duration function or just import it, mma tells me that it remains about 8m01s.

But when I open it with potplayer or Groove music, it remains 7m59s. After comparing them I found that the last 2s is silent.

So why and how to import the audio the same as above? Someone told me that when he use ffmpeg, it gives 7m59s but warns:

Estimating duration from bitrate, this may be inaccurate.

I think maybe it is about encoding or so, but I am not familiar with it. Can anyone help me?

Code:(I upload the audio at somewhere because I don't know how to upload it at this cite.)

url = "https://raw.githubusercontent.com/SHBookP/SHBookP/main/azz.mp3";
Import[url](*an 8m01s audio*)
Import[url, "Duration"](*481.306*)
SystemOpen@URLDownload@url(*the end of it is 7:59*)
$\endgroup$
1
  • 2
    $\begingroup$ I reproduce the issue with version 13.0.0 on Windows 10 x64. VLC player also reports the duration of 7:59 for the audio. Looks like a bug. $\endgroup$ Jan 26, 2022 at 8:14

1 Answer 1

6
$\begingroup$

I reproduce the issue with version 13.0.0 on Windows 10 x64. The last 2 seconds are indeed silent:

audio = Import["https://raw.githubusercontent.com/SHBookP/SHBookP/main/azz.mp3"];
sr = SampleRate /. Options[audio]
last2sec = AudioData[audio][[All, -2*sr ;;]];
Max[Abs[last2sec]]
44100
0.` 

Plot last three seconds of the sum of the channels:

ListLinePlot[Plus @@ AudioData[audio][[All, -(3*sr) ;;]], PlotRange -> All, 
 DataRange -> {-3, 0}, AxesLabel -> {"Seconds", "Sum of the channels"}]

plot

Looks like a bug. Please report it to the support.

$\endgroup$
3
  • 2
    $\begingroup$ OK, thanks. I've voted and reported it by email. $\endgroup$
    – SHBooKP
    Jan 26, 2022 at 9:22
  • 1
    $\begingroup$ @SHBooKP Here's a theory for why this happens. Two seconds is quite long, so this might not be the actual reason though. Encoding to lossy formats like MP3 typically involve partitioning the audio into fixed-length segments. If the file length is not an integer multiple of the segment length, some padding is added at the end. Modern formats include some metadata to encode the true length of the file, but MP3 does not provide a standard way to do this. There is a non-standard but very widely supported extension introduced by the LAME encode. $\endgroup$
    – Szabolcs
    Sep 2, 2022 at 9:53
  • 1
    $\begingroup$ To learn more, search for "gapless playback" and "LAME gapless tag". Maybe Mathematica does not support this tag? It's possible, but two seconds seems too long for this to be the explanation. The extra padding at the end used to be a problem when each track of a live album (with contiguous audio) was encoded into a separate file. Playing back these files one after the other was not seamless. $\endgroup$
    – Szabolcs
    Sep 2, 2022 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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