问题描述
MP3文件可使用此来处理,但是我没有找到类似的东西的MP4文件。
Mp3 files can be handled using this mp3 SPI support, but I'm not finding something similar to mp4 files.
任何帮助将是AP preciated。
Any help would be appreciated.
- 更新
我想要做的就是文件的大小,我用这个code浪文件执行:
What I want to do is get the file's size, as I do with wave files using this code:
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));
- 答案
下面是一个使用@mdma的提示回答code(IBM工具包):
Here is the answer code using the hint of @mdma (IBM toolkit):
/**
* Use IBMPlayerForMpeg4SDK to get mp4 file duration.
*
* @return the mp4File duration in milliseconds.
*/
public static long getMp4Duration(File mp4File) throws IllegalStateException, IOException {
PlayerControl playerControl = PlayerFactory.createLightweightMPEG4Player();
playerControl.open(mp4File.getAbsolutePath());
long mili = playerControl.getDuration();
// int sec = (int) ((mili / 1000) % 60);
// int min = (int) ((mili / 1000) / 60);
// System.out.println("IBM Tookit result = " + min + ":" + sec);
return mili;
}
-
相关,与语言无关的,问题:
http://stackoverflow.com/questions/3057157/anyone-familiar-with-mp4-data-structure
Related, language independent, question:http://stackoverflow.com/questions/3057157/anyone-familiar-with-mp4-data-structure
推荐答案
MP4是一种容器格式 - 要能找到里面的声音的持续时间,你必须首先解析内容从容器中。您可以使用提取的MP4文件的内容。
Mp4 is a container format - to be able to find the duration of the audio inside, you have to first parse the content out of the container. You can extract the content of an mp4 file using isobox mp4parser.
一旦你做到了这一点,你再有原始的音频数据。如果是在Java的支持的格式(WAV,MP3等),那么你可以直接打开这个文件,您已经做了wav文件了。起初你可能会提取音频到一个单独的文件,为了简单起见,更容易调试。当这是工作,你可以再做提取在线 - 你实现了从提取的MP4动态的音频内容的InputStreamFilter,因此不需要额外的外部文件要求
Once you've done that, you then have the raw audio data. If it's one of the supported formats in java (wav, mp3, etc..) then you can just open this file like you have done for wavs already. Initially you will probably extract the audio to a separate file, for simplicity's sake and easier debugging. When this is working, you can then do the extraction inline - you implement an InputStreamFilter that extracts the audio content from the mp4 on the fly, so no additional external files are required.
有一个纯Java的MP4去codeR可用库,但它是你的可能是矫枉过正present需求。
IBM Alphaworks have a pure java MP4 decoder library available, but it's possibly overkill for your present needs.
这篇关于是否有MP4文件的Java API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!