Skip to content
André Schild edited this page Aug 27, 2021 · 21 revisions

Usage

You can use maven dependencies to include the libraries in your projects. Include the following in your pom files.

For all platforms [ Remember always to check the latest release here ]

<dependency>

    <groupId>ws.schild</groupId>

    <artifactId>jave-all-deps</artifactId>

    <version>2.4.2</version>

</dependency>

For one platform only (Linux 64Bit in this case)

<dependency>

    <groupId>ws.schild</groupId>

    <artifactId>jave-core</artifactId>

    <version>2.4.2</version>

</dependency>

<dependency>

    <groupId>ws.schild</groupId>

    <artifactId>jave-native-linux64</artifactId>

    <version>2.4.2</version>

</dependency>

Example usage:

    System.out.println("encode WEBM");
    File source = new File("test/videos/l4.mov");
    File target = new File("test/out/l4.faststart.webm");
    AudioAttributes audio = new AudioAttributes();
    VideoAttributes video = new VideoAttributes();
    EncodingAttributes attrs = new EncodingAttributes();
    attrs.setAudioAttributes(audio);
    attrs.setVideoAttributes(video);
    audio.setCodec("libvorbis");
    audio.setBitRate(new Integer(64000));
    audio.setSamplingRate(new Integer(44100));
    audio.setChannels(new Integer(2));
    audio.setBitRate(new Integer(192000));
    video.setCodec("libvpx");
    video.setBitRate(new Integer(250000));
    video.setFrameRate(new Integer(25));
    attrs.setFormat("webm");
    Encoder instance = new Encoder();
    instance.encode(new MultimediaObject(source), target, attrs, null);

All available platforms:

  • jave-native-linux32

  • jave-native-linux64

  • jave-native-osx64

  • jave-native-win32

  • jave-native-win64

  • Download the current release from here .

  • You need the jave-2.0.jar file which is your java interface to use

  • In addition you need one of the native libraries, matching your platform. So for linux 64 bit you download also jave-2.0-linux64.jar. This file contents the binary executable for linux 64 bit

  • Now you are ready to use it, you can find the javadoc here: https://javadoc.io/doc/ws.schild/jave-core/latest/index.html

The most important JAVE class is ws.schild.jave.Encoder. Encoder objects expose many methods for multimedia transcoding. In order to use JAVE, you always have to create an Encoder istance:

Encoder encoder = new Encoder();

Once the instance has been created, you can start transcoding calling the encode() method:

public void encode(ws.schild.MultimediaObject source,
               java.io.File target,
               ws.schild.jave.EncodingAttributes attributes)
        throws java.lang.IllegalArgumentException,
               ws.schild.jave.InputFormatException,
               ws.schild.jave.EncoderException

The first parameter, source, represents the source file to decode.

The second parameter, target, is the target file that will be created and encoded.

The attributes parameter, whose type is ws.schild.jave.EncodingAttributes, is a data structure containing any information needed by the encoder.

Please note that a call to encode() is a blocking one: the method will return only once the transcoding operation has been completed (or failed). If you are interested in monitoring the transcoding operation take a look to the "Monitoring the transcoding operation" section. Encoding attributes

To specify your preferences about the transcoding operation you have to supply an ws.schild.jave.EncodingAttributes instance to the encode() call. You can create your own EncodingAttributes instance, and you can populate it with the following methods:

public void setAudioAttributes(ws.schild.jave.AudioAttributes audioAttributes)

It sets the audio encoding attributes. If never called on a new EncodingAttributes instance, or if the given parameter is null, no audio stream will be included in the encoded file. See also "Audio encoding attributes".

public void setVideoAttributes(ws.schild.jave.AudioAttributes videoAttributes)

It sets the video encoding attributes. If never called on a new EncodingAttributes instance, or if the given parameter is null, no video stream will be included in the encoded file. See also "Video encoding attributes".

public void setFormat(java.lang.String format)

It sets the format of the streams container that will be used for the new encoded file. The given parameter represents the format name. An encoding format name is valid and supported only if it appears in the list returned by the getSupportedEncodingFormats() method of the Encoder instance in use.

public void setOffset(java.lang.Float offset)

It sets an offset for the transcoding operation. The source file will be re-encoded starting at offset seconds since its beginning. In example if you'd like to cut the first five seconds of the source file, you should call setOffset(5) on the EncodingAttributes object passed to the encoder.

public void setDuration(java.lang.Float duration)

It sets a duration for the transcoding operation. Only duration seconds of the source will be re-encoded in the target file. In example if you'd like to extract and transcode a portion of thirty seconds from the source, you should call setDuration(30) on the EncodingAttributes object passed to the encoder.

Monitoring the transcoding operation

You can monitor a transcoding operation with a listener. JAVE defines the ws.schild.jave.EncoderProgressListener interface. This interface could be implemented by your application, and concrete EncoderProgressListener instances can be passed to the encoder. The encoder will call your listener methods every time a significant event occurs. To pass an EncoderProgressListener to the encoder you should use this definition of the encode() method:

public void encode(ws.schild.MultimediaObject source,
               java.io.File target,
               ws.schild.jave.EncodingAttributes attributes,
               ws.schild.jave.EncoderProgressListener listener)
        throws java.lang.IllegalArgumentException,
               ws.schild.jave.InputFormatException,
               ws.schild.jave.EncoderException

To implemen the EncoderProgressListener interface you have to define all of the following methods:

public void sourceInfo(ws.schild.jave.MultimediaInfo info)

The encoder calls this method after the source file has been analized. The info parameter is an instance of the ws.schild.jave.MultimediaInfo class and it represents informations about the source audio and video streams and their container.

public void progress(int permil)

This method is called by the encoder every time a progress in the encoding operation has been done. The permil parameter is a value representing the point reached by the current operation and its range is from 0 (operation just started) to 1000 (operation completed).

public void message(java.lang.String message)

This method is called by the encoder to notify a message regarding the transcoding operation (usually the message is a warning).

Transcoding failures

Of course, a transcoding operation could fail. Then the encode() method will propagate an exception. Depending on what is happened, the exception will be one of the following:

java.lang.IllegalArgumentException

The transcoding operation has never started since the encoding attributes passed to the encoder has been recognized as invalid. Usualy this occurs when the EncodingAttributes instance given to the encoder asks the encoding of a container with no audio and no video streams (both AudioAttributes and VideoAttribues attributes are null or not set).

ws.schild.jave.InputFormatException

The source file can't be decoded. It occurs when the source file container, the video stream format or the audio stream format are not supported by the decoder. You can check for supported containers and plugged decoders calling the encoder methods getSupportedDecodingFormats(), getAudioDecoders() and getVideoDecoders().

ws.schild.jave.EncoderExpection

The operation has failed during the trancoding due to an internal error. You should check the exception message, and you can also use an EncoderProgressListener instance to check any message issued by the encoder.

Getting informations about a multimedia file

You can get informations about an existing multimedia file before transcoding it, calling the encoder getInfo() method. The getInfo() method gives you informations about the container used by the file and about its wrapped audio and video streams:

MultimediaObject mmObject= new MultimediaObject(myFile);
MultimediaInfo infos= mmObject.getInfo();

or

MultimediaObject mmObject= new MultimediaObject(myURL);
MultimediaInfo infos= mmObject.getInfo();

An ws.schild.jave.MultimediaInfo object encapsulates information on the whole multimedia content and its streams, using instances of ws.schild.jave.AudioInfo and ws.schild.jave.VideoInfo to describe the wrapped audio and video. These objects are similar to the EncodingAttributes, AudioAttributes and VideoAttributes ones, but they works in a read-only mode. Check the JAVE API javadoc documentation, bundled with the JAVE distribution, to gain more details about them.

See the Examples page for more samples