The aim of this project is to provide an easy to use interface to FFmpeg. This project is not command line based like many others do. In addition JavaAV is easily maintainable. First, the native FFmpeg library is accessed through JNI. There is no other extra layer of native code like in Xuggler. Second, all the JNI classes are automatically generated with JavaCPP. Even the compilation into native code is controlled by JavaCPP. This way there is less effort to react to new FFmpeg updates. To improve JavaAV or fix bugs you do not need to touch the native code.
- Android ARM
- Linux x86 / x64
- Mac OS X x64
- Windows x86 / x64
- Encoding / Decoding with any codec that was compiled into FFmpeg
- Muxing / Demuxing
- Audio / Video resampling
- Log access through callback
Below some code snippets are shown to demonstrate the API usage. For more complete code see the examples section.
Enumerate installed codecs (each string contains name, type and description):
String[] codecs = Codec.getInstalledCodecs();
Create and use a real-time video encoder:
Options options = new Options();
options.put("tune", "zerolatency");
options.put("preset", "ultrafast");
Encoder encoder = new Encoder(CodecID.H264);
encoder.setPixelFormat(PixelFormat.YUV420P);
encoder.setImageWidth(1280);
encoder.setImageHeight(720);
encoder.setGOPSize(25);
encoder.setBitrate(2000000);
encoder.setFramerate(25);
encoder.open(options);
BufferedImage image = ...;
VideoFrame frame = VideoFrame.create(image);
MediaPacket packet = encoder.encodeVideo(frame);
... send packet over a network, write it to a file or whatever
encoder.close();
Below is the list of some basic examples. All examples can be found in the projects src/examples folder.
For those who use Maven may include this project as dependency:
<dependency>
<groupId>com.github.hoary</groupId>
<artifactId>JavaAV</artifactId>
<version>0.5</version>
</dependency>
You can also download JavaAV manually. In doing so, JavaAV and the necessary dependencies must be added to the classpath.