5

バイトに基づいて mp3 ファイルからデータを解析する際に問題があります。

出力の最初の部分は正しいです。254 秒の長さの mp3 ファイルがあり、Github の mp3 解析ライブラリ mp3agic からその情報を取得しています。

ただし、フレームの長さと期間に関する情報の 2 番目の部分は正しくありません。

Length of this mp3 is: 254 seconds
Bitrate: 320 kbps (CBR)
Sample rate: 44100 Hz
Has ID3v1 tag?: NO
Has ID3v2 tag?: YES
Has custom tag?: NO

framelength -1
framerate 38.28125
duration -271265.06

フレーム長、フレームレート、および期間を取得するために使用するコードは次のとおりです。

File file = musicFile.getFileValue();

    this.audioStream.startMusicStream(file);

    try {
        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
        AudioFormat format = audioInputStream.getFormat();
        long audioFileLength = file.length();
        int frameSize = format.getFrameSize();
        float frameRate = format.getFrameRate();
        float durationInSeconds = (audioFileLength / (frameSize * frameRate));

        System.out.println("framelength "+frameSize);
        System.out.println("framerate "+frameRate);
        System.out.println("duration "+durationInSeconds);

        this.setDurationLabel(durationInSeconds);
    } catch (Exception e) {
        e.printStackTrace();
    }

まず第一に、フレーム長やその他の測定値がマイナスになるのはなぜですか? それは一体何の意味ですか?また、audioinputstream と audioformat からの情報を使用して、mp3 ファイルの長さを正確に計算するにはどうすればよいですか?

4

2 に答える 2

0

フレームの長さと期間については、次を使用できます。

long frameLen = audioInputStream.getFrameLength();
double durationInSeconds = (frameLen+0.0) / format.getFrameRate(); 

機能説明:

getFrameLength:Obtains the length of the stream, expressed in sample frames rather than bytes.Returns:the length in sample frames

getFrameRate:Obtains the frame rate in frames per second.Returns:the number of frames per second, or AudioSystem.NOT_SPECIFIED

参考文献:

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/javax/sound/sampled/AudioInputStream.java#AudioInputStream.getFrameLength%28%29

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/javax/sound/sampled/AudioFormat.java#AudioFormat.getFrameRate%28%29

于 2016-03-06T05:14:20.357 に答える