Fork me on GitHub

Introduction

FFSampledSP is a free service provider implementation of the javax.sound.sampled.spi interfaces. It is part of the SampledSP collection of javax.sound.sampled libraries.

Its main purpose is to decode audio from various formats at high speed using FFmpeg . To do so, it uses the tagtraum FFmpeg package 4.0.11, which offers FFmpeg binaries configured to decode audio while avoiding codecs with patent problems. In other words, it supports formats like OGG, FLAC, GSM, MP3... well, while leaving MPEG-4 unsupported. In order to decode those, please see alternatives below.

Getting Started

The easiest way to use FFSampledSP (other than simply using the jar is to start a Maven project and introduce a FFSampledSP dependency.

To do so, add something like this to the dependencies section of your pom:

<dependency>
    <groupId>com.tagtraum</groupId>
    <artifactId>ffsampledsp-complete</artifactId>
    <version>0.9.53</version>
</dependency>

To use the library, simply use the javax.sound.sampled classes like you normally would.

Requirements

On macOS, FFSampledSP requires OS X/macOS 10.10 or later and an Intel processor. Starting with v0.9.29, only 64 bit is supported. On Windows, FFSampledSP should run with Windows XP or higher. Both 32 bit and 64 bit are supported. On Linux/Debian, FFSampledSP should run with Ubuntu 20 or higher (x86/arm64). Only 64 bit is supported.

Stems Support

FFSampledSP supports Stems via a non-standard extension to the original Java API. Via getAudioFileFormats(URL) you can obtain an array of AudioFileFormats. To open a specific stream, you can call for example new FFAudioFileReader().getAudioInputStream(file, streamIndex); In this case, file has to be a File object and streamIndex has to be a valid index. For a regular Stem file this would be a number >=0 and <5. The indices in the audio file format array and in the getAudioInputStream(..., streamIndex) method correspond to each other.

For a code sample please see here.

Alternatives

For a 32/64 bit service provider implementation for Windows 7 or later, based on Microsoft's Media Foundation, check out MFSampledSP. This provider also supports a number of MPEG-4 formats (MP4, M4A, MOV, etc.) as well as MP3.

For a service provider based on Apple's CoreAudio, check out CASampledSP. This provider also supports many codecs with patent problems.

For a cross platform (OS X/Windows) 32 bit service provider based on QuickTime, check out QTSampledSP. Note that the QuickTime API has been removed from newer versions of macOS. So it's probably not a good idea to start a project with it.

Other Java FFmpeg Projects

There are numerous other Java-FFmpeg projects. Here's the short list, of the projects I'm aware of:

  • Xuggle - Java wrapper around FFmpeg using JNI.
  • jjmpeg - thin Java wrapper around FFmpeg using JNI.
  • JAVE - Java wrapper around FFmpeg executables.
  • FFMPEG-Java - Java wrapper around FFmpeg, using JNA. Apparently abandoned in 2007.
  • Jffmpeg - Plugins for the Java Media Framework (JMF). Apparently abandoned in 2006.

As far as I am aware, except for the abandoned Jffmpeg, all these wrappers require you to learn either the FFmpeg API or some other proprietary API. Contrary to this, you can use the familiar Java APIs when using FFSampledSP or other SampledSP libraries for decoding audio.

FFmpeg Sources

You can find the FFmpeg sources used for this package (i.e. the x86_64 macOS version) here.