Skip to content

Building FFMPEG JavaCPP preset on Ubuntu 16.04

Rishabh Joshi edited this page Nov 16, 2017 · 1 revision

1. Introduction

In my attempt to learn and use JavaCPP-Presets (specifically for FFmpeg) and debugging the crashes in my project, I spent a lot of my time on building JavaCPP-Presets and FFmpeg. To ensure no one else faces the same fate as mine, I am preparing this document. It documents the following specific goals only:

2. Setting up your build machine

I recommend setting up a private repository (Nexus or Artifactory) The benefits of having a private repository and the steps to setup one, are out of scope of this document, but you can easily find enough material on the web for the same.

2.1. Setup build environment

On your Ubuntu 16.04 (x86_64) machine:

sudo apt-get update

sudo apt-get -y install --no-install-recommends \
    git curl wget openjdk-8-jdk zip unzip \
    build-essential pkg-config python automake make cmake \
    nasm yasm libxcb1-dev maven

2.2. Setup JAVA_HOME environment variable

Open ~/.bash_profile and add the following line

export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

then execute

source ~/.bash_profile

3. Building JavaCPP

This is a prerequisite for building JavaCPP-Presets.

3.1. Get the source

cd ~

git clone https://github.com/bytedeco/javacpp.git --branch master

If you do not want to use --branch master, you can always use any of the tags. Just ensure that you checkout the same tag for JavaCPP-Presets too.

3.2. Build JavaCPP

Before you start the build, if you have setup your private Maven repository, then edit the javacpp/pom.xml and update the snapshot and staging <url>s under <distributionManagement> tag, to point to your repository.

cd javacpp

mvn clean install
### or ###
mvn clean install deploy

4. Building JavaCPP-Presets (FFmpeg only)

4.1. Get the source

It is mandatory that the tags of JavaCPP and JavaCPP-Presets match for a correct and stable build.

cd ~

git clone https://github.com/bytedeco/javacpp-presets.git --branch master

4.2. Enable debugging in FFmpeg

To be able to debug FFmpeg, we need to compile it with the following flags/options:

--disable-stripping --enable-debug=3 --extra-cflags="-gstabs+ -I../include/"

Open file ~/javacpp-presets/ffmpeg/cppbuild.sh and search for the case linux-x86_64) (since we are supporting linux-x86_64 platform only). Scroll further down and you'll find the line:

PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE --enable-libxcb --cc="gcc -m64" --extra-cflags="-I../include/" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -ldl"

Update it with the required flags/options as follows:

PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE --enable-libxcb --cc="gcc -m64" --disable-stripping --enable-debug=3 --extra-cflags="-gstabs+ -I../include/" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -ldl"

4.3. Build FFmpeg (time consuming)

cd ~/javacpp-presets

./cppbuild.sh -platform linux-x86_64 install ffmpeg

4.4. Finally build FFmpeg preset

4.4.1. Update POM

Comment out the unnecessary modules from the parent POM. Open ~/javacpp-presets/pom.xml, search for tag <modules> and comment out all modules except <module>ffmpeg</module>.

If you have the private Maven repository setup, you should update the <url>s under <distributionManagement> and <repository> accordingly.

4.4.2. Build

cd ~/javacpp-presets

mvn clean install -Djavacpp.platform=linux-x86_64
### or ###
mvn clean install deploy -Djavacpp.platform=linux-x86_64

5. Building JavaCPP-Presets (FFmpeg) Platform

5.1. Update Parent Platform POM

Edit ~/javacpp-presets/platform/pom.xml.

5.1.1. Update <modules>

Comment out all <modules> except <module>../ffmpeg/platform</module>.

5.1.2. Update <dependencies>

Comment out all <dependencies> barring

<dependency>
  <groupId>org.bytedeco</groupId>
  <artifactId>javacpp</artifactId>
  <version>${project.version}</version>
</dependency>

and

<dependency>
  <groupId>org.bytedeco.javacpp-presets</groupId>
  <artifactId>ffmpeg-platform</artifactId>
  <version>3.4-${project.version}</version>
</dependency>

5.2. Update Child (FFmpeg) Platform POM

Edit ~/javacpp-presets/ffmpeg/platform/pom.xml

5.2.1. Update <dependencies>

Comment out all <dependencies> barring

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>${javacpp.moduleId}</artifactId>
  <version>${project.version}</version>
</dependency>

and

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>${javacpp.moduleId}</artifactId>
  <version>${project.version}</version>
  <classifier>${javacpp.platform.linux-x86_64}</classifier>
</dependency>

5.2.2. Update maven-jar-plugin

5.2.2.1. Update the <Class-Path>

<Class-Path>${javacpp.moduleId}.jar ${javacpp.moduleId}-linux-x86_64.jar</Class-Path>

5.2.2.2. Add a classifier <classifier>platform</classifier>

This step is only required if you are deploying to a private repository.

  <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
      <execution>
        <id>default-jar</id>
        <configuration>
          <classifier>platform</classifier>
          <archive>
            <manifestEntries>
              <Class-Path>${javacpp.moduleId}.jar ${javacpp.moduleId}-linux-x86_64.jar</Class-Path>
            </manifestEntries>
          </archive>
        </configuration>
      </execution>
    </executions>
  </plugin>

5.3. Build ffmpeg-platform

cd ~/javacpp-presets/ffmpeg/platform

mvn install -Djavacpp.platform.host
### or ###
mvn install deploy -Djavacpp.platform.host