2009-06-14 27 views
1

スクリプトやcmdラインツールが必要です。mp3の長さをミリ秒で取得します。ファイルは、ラメで符号化された64kbモノラルcbrです。mp3の長さ(ミリ秒単位)

+0

実際の時間が必要なのか、ID3タグが言っていることは時間ですか? –

答えて

2

http://id3lib-ruby.rubyforge.org/(私は...、ルビーのためのlibmadのための選択の私の言葉を見えたが、注目すべきは何も見つかりませんでしたか)? This pageに必要なコードがあります。

+0

これは素晴らしいです! Sooo COOOl !!! ありがとうjacob – luca

+0

link dead、id3libはgems 2.3+で利用できません – default

3

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) 
+0

それを計算するのですか、それともメタデータに格納されていますか? – luca

+0

Macにいる場合は、「brew install exiftool」と表示されます。 – Nobu

+0

@luca:その情報のほとんどはメタデータに含まれています。 –

1

私はffmpegのは簡単にこれを行うことができます知っている:

ffmpeg -i file.mp3 2>&1|sed -n "s/.*Duration: \([^,]*\).*/\1/p" 

は、残念ながら、私はこれを取り扱う任意のRubyのライブラリを知りません。

4
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 
関連する問題