如何获取MP3文件(VBR或CBR)服务器端的实际持续时间 [英] How to get the real, actual duration of an MP3 file (VBR or CBR) server-side

查看:334
本文介绍了如何获取MP3文件(VBR或CBR)服务器端的实际持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经用ffmpeg来计算MP3文件服务器端的持续时间,这似乎工作正常。今天我发现一些计算是错误的。不知何故,由于某种原因,ffmpeg将会错误计算持续时间,并且似乎只发生可变比特率mp3文件。



在本地测试时,我注意到ffmpeg打印了两个



使用的命令:

  ffmpeg -i song_9747c077aef8.mp3 

ffmpeg说:

  [mp3 @ 0x102052600] max_analyze_duration 5000000已达到5015510 
[mp3 @ 0x102052600]从比特率估计持续时间,这可能不准确
pre>

在一个不错的,热门的Google会话后,我发现了一些帖子,但没有找到解决方案。



然后我尝试增加最长时间:

  ffmpeg -analyzeduration 999999999 -i song_9747c077aef8.mp3 

此后,ffmpeg只返回第二行:

  [mp3 @ 0x102052600]从比特率估计持续时间,这可能是我naccurate 

但是无论在哪种情况下,计算的持续时间都是错误的。比较VLC我注意到持续时间是正确的。



经过更多的研究,我偶然发现了我安装和使用的mp3info。

  mp3info -p%Ssong_9747c077aef8.mp3 

mp3info,然后返回 CORRECT 持续时间,但只能作为一个整数,我不能使用,因为我需要一个更准确的数字。原因是在下面的评论中解释,用户 blahdiblah - mp3info只是从文件中拉出ID3信息,实际上不执行任何计算。



我还尝试使用mplayer来检索持续时间,但是像ffmpeg一样,mplayer返回错误的值。

解决方案

我终于找到了使用sox的这个问题的一个正确的解决方案 - 它返回正确的信息。

  sox file.mp3 -n stat 
样本阅读:19321344
长度(秒):219.062857
缩放:2147483647.0
最大幅度:1.000000
最小幅度:-1.000000
中线幅度: 0.000000
平均值:0.141787
平均幅度:0.000060
RMS幅度:0.191376
最大增量:0.947598
最小值delta:0.000000
平均delta:0.086211
RMS delta:0.115971
粗糙频率:4253
音量调整:1.000

长度(秒):219.062857


I used to calculate the duration of MP3 files server-side using ffmpeg - which seemed to work fine. Today i discovered that some of the calculations were wrong. Somehow, for some reason, ffmpeg will miscalculate the duration and it seems to happen with variable bit rate mp3 files only.

When testing this locally, i noticed that ffmpeg printed two extra lines in green.

Command used:

ffmpeg -i song_9747c077aef8.mp3

ffmpeg says:

[mp3 @ 0x102052600] max_analyze_duration 5000000 reached at 5015510
[mp3 @ 0x102052600] Estimating duration from bitrate, this may be inaccurate

After a nice, warm google session, i discovered some posts on this, but no solution was found.

I then tried to increase the maximum duration:

ffmpeg -analyzeduration 999999999 -i song_9747c077aef8.mp3

After this, ffmpeg returned only the second line:

[mp3 @ 0x102052600] Estimating duration from bitrate, this may be inaccurate

But in either case, the calculated duration was just plain wrong. Comparing it to VLC i noticed that there the duration is correct.

After more research i stumbled over mp3info - which i installed and used.

mp3info -p "%S" song_9747c077aef8.mp3

mp3info then returned the CORRECT duration, but only as an integer, which i cannot use as i need a more accurate number here. The reason for this was explained in a comment below, by user blahdiblah - mp3info is simply pulling ID3 info from the file and not actually performing any calculations.

I also tried using mplayer to retrieve the duration, but just as ffmpeg, mplayer is returning the wrong value.

解决方案

I finally found a proper solution to this problem using sox - which returns the correct information.

sox file.mp3 -n stat
Samples read:          19321344
Length (seconds):    219.062857
Scaled by:         2147483647.0
Maximum amplitude:     1.000000
Minimum amplitude:    -1.000000
Midline amplitude:    -0.000000
Mean    norm:          0.141787
Mean    amplitude:     0.000060
RMS     amplitude:     0.191376
Maximum delta:         0.947598
Minimum delta:         0.000000
Mean    delta:         0.086211
RMS     delta:         0.115971
Rough   frequency:         4253
Volume adjustment:        1.000

Length (seconds): 219.062857

这篇关于如何获取MP3文件(VBR或CBR)服务器端的实际持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆