且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有用于 mp4 文件的 Java API?

更新时间:2022-02-20 22:44:37

Mp4 是一种容器格式——要能够找到里面音频的时长,你必须先解析容器外的内容.您可以使用 isobox mp4parser 提取 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 一样打开这个文件.最初,您可能会将音频提取到一个单独的文件中,为简单起见和更容易调试.当这工作时,您可以进行内联提取 - 您可以实现一个 InputStreamFilter 来动态地从 mp4 中提取音频内容,因此不需要额外的外部文件.

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.

IBM Alphaworks 有一个纯 Java MP4 解码器库可用,但对于您目前的需求.

IBM Alphaworks have a pure java MP4 decoder library available, but it's possibly overkill for your present needs.