以毫秒为单位的mp3长度
问题描述:
我需要一个脚本或cmd线工具来获取以毫秒为单位的mp3长度。这些文件是64 kbit单声道cbr编码与跛脚。以毫秒为单位的mp3长度
(我找了红宝石,我选择的语言的libmad,但没有发现任何值得一提的...)
答
答
尝试exiftool:
$ sudo apt-get install libimage-exiftool-perl
$ exiftool "Stone Sour-Stone Sour-Bother.mp3"
ExifTool Version Number : 6.93
File Name : Stone Sour-Stone Sour-Bother.mp3
Directory : .
File Size : 6 MB
File Modification Date/Time : 2006:05:15 19:09:52
File Type : MP3
MIME Type : audio/mpeg
MPEG Audio Version : 1
Audio Layer : 3
Audio Bitrate : 128000
Sample Rate : 44100
Channel Mode : Joint Stereo
MS Stereo : On
Intensity Stereo : Off
Copyright Flag : False
Original Media : True
Emphasis : None
Album : Stone Sour
Artist : Stone Sour
Comment : ***/Foobar2000: MPC->MP3
Genre : Rock
Title : Bother
Track : 08
Recording Time : 2002
User Defined Text : (sub-genre) Alt Metal
Year : 2002
Duration : 0:06:03.67 (approx)
答
我知道ffmpeg的可以很容易地做到这一点:
ffmpeg -i file.mp3 2>&1|sed -n "s/.*Duration: \([^,]*\).*/\1/p"
不幸的是,我不知道,处理这个任何Ruby库。
答
def self.get_audio_length(filepath)
pipe = "ffmpeg -i "+ filepath.to_s+" 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//"
command = `#{pipe}`
if command =~ /([\d][\d]):([\d][\d]):([\d][\d]).([\d]+)/
#convert the result to only secs
duration = ($2.to_i * 60) + $3.to_i
end
#return and array containing the seconds and the human readable time length, ["6453","03:54"]
return "#{duration.to_s},#{$2}:#{$3}".split(",")
end
您是否需要实际的时间或ID3标签所说的时间? – 2009-06-14 23:08:13