Unknown frame size

喜你入骨 提交于 2021-02-10 17:43:25

问题


Trying to get the frame size of an audio file I am getting instead -1. I tried to look for the interpretation of of this result in the JavaDoc but it does not mention anything big. Here's the source code :

import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
/*....*/
File file = new File("/home/songs/audio.mp3");
MpegAudioFileReader mpegAudioFileReader = new MpegAudioFileReader();        
AudioInputStream audioInputStream = mpegAudioFileReader.getAudioInputStream(file); 
AudioFormat format = audioInputStream.getFormat();   
long frameSize = format.getFrameSize();//frameSize = -1
float frameRate = format.getFrameRate();//frameRate = 38.28125

Inspecting he format object gives this : MPEG1L3 44100.0 Hz, unknown bits per sample, stereo, unknown frame size, 38.28125 frames/second, I do not know why the frame size is unknown although it does appear on my audio file properties :

Any help is more than appreciated. Thanks.


回答1:


getFormat() etc is implemented by the MPEG guys so it returns what they have - probably they left this blank or unable to extract;

If you put another .wav file you will probably get 2:

try {
  audioInputStream=AudioSystem.getAudioInputStream(new File(".......wav"));

  System.out.println(audioInputStream.getFormat().getFrameSize());

} catch (Exception e) {
        e.printStackTrace();
}

Other notes: I dont see the Frame size in your display; it's rather the sample/bit rate so be sure to differentiate about that.

But for mp3 you have to live with that.

You can also create your own format if that helps - dont know your application

AudioFormat format = audioInputStream.getFormat();
newFormat=new AudioFormat(
          AudioFormat.Encoding.PCM_SIGNED,
          format.getSampleRate(),
          16,
          format.getChannels(),
          format.getChannels() * 2,
          format.getSampleRate(),
          false);


来源:https://stackoverflow.com/questions/42042533/unknown-frame-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!