Skip to content
codeanticode edited this page Sep 5, 2022 · 12 revisions

In order to develop the video library using the Eclipse IDE, we need to import the processing-core and processing-video projects into Eclipse, copy the GStreamer libraries into the processing-video project, and finally create a debug project.

Importing Processing projects into Eclipse

I - Setting up Processing

Since we only require Processing 4 as a dependency, perform a shallow clone of the processing repo and build it by running ant in the processing/build folder, as detailed in the build instructions for Processing:

git clone https://github.com/processing/processing4.git --depth 1

II - Import processing-core project into Eclipse

  1. Import the Processing 4 repo into Eclipse: Import > Projects from Git > Existing local repository > Select Processing folder > Import existing eclipse project
  2. Select processing-core

III - Import processing-video project into Eclipse

Import the processing-video repo into Eclipse, following the same procedure explained in the previous step to import processing-core.

IV - Copy GStreamer libraries

The video library needs the GStreamer native libraries in order to run, which are not included in the source repository because they are take up a lot of space. You can get them from the latest package of the video library, download video.zip, unzip the file and then you will find all the GStreamer native library sub-folders (macos-aarch64, macos-x86_64, windows-amd64, and linux-amd64) under the library folder of the video library. Copy (or move) those to the library folder of your local clone of the source.

Create debug Processing sketch in Eclipse

Once we have processing-core and processing-video imported in Eclipse and the GStreamer libraries copied into processing-video in the case we are developing either on Windows or Mac, we need to create an Eclipse project that allows to run a Processing sketch using the video's classes:

I - Create Eclipse project

First of all, we start creating a new empty Eclipse project as indicated in the tutorial, and then add a main class to it, named for example Test inside some package path such as video_test. But then, because processing-core and processing-video should be already imported into the Eclipse environment, we can simply include them in the Java Build Path of our project:

image

II - Implement Processing and video methods in Test class

We can import the core and video packages into our Test project because we added them to the Build path in the previous step. This will allow us to add all the functionality needed to to video operations in Processing, from our Eclipse project.

A - For testing movie playback:

package video_test;

import processing.core.*;
import processing.video.*;

public class Test extends PApplet {
  Movie movie;
	
  public void settings() {
    size(560, 406);
  }

  public void setup() {	  
    background(0);
    // Load and play the video in a loop
    movie = new Movie(this, "launch2.mp4");
    movie.loop();
  }

  public void draw() {
    image(movie, 0, 0, width, height);
  }	
	
  public void movieEvent(Movie m) {
    m.read();
  }  
  
  public static void main(String[] args) {
    PApplet.main("video_test.Test");
  }
}

It is important to add a video file to the Eclipse project, in this case it is called launch2.mp4, and should be located in a data folder created in the root of the project. Also, remember to set all methods, particularly movieEvent, as public. Otherwise, playback will not work.

B - For testing capture playback:

package video_test;

import processing.core.*;
import processing.video.*;

public class TestCapture extends PApplet {
  Capture cam;

  public void settings() {
    size(640, 480);
  }
  
  public void setup() {
    String[] cameras = Capture.list();

    if (cameras == null) {
      println("Failed to retrieve the list of available cameras, will try the default...");
      cam = new Capture(this, 640, 480);
    } else if (cameras.length == 0) {
      println("There are no cameras available for capture.");
      exit();
    } else {
      println("Available cameras:");
      printArray(cameras);

      // The camera can be initialized directly using an element
      // from the array returned by list():
      cam = new Capture(this, cameras[0]);
      
      // Start capturing the images from the camera
      cam.start();
    }
  }

  public void draw() {
    if (cam.available() == true) {
      cam.read();
    }
    image(cam, 0, 0, width, height);
  }
	
  public static void main(String[] args) {
    PApplet.main("video_test.TestCapture");
  }
}

Remember to have a capture device attached for Capture functionality to work properly. Also, remember to set all methods as public.

III - Add Gstreamer paths to VM arguments

When running the video library from Eclipse, we need to explicitly tell Java where to find the GStreamer base libraries and plugins (this is required only for Windows and Mac). Since the base libs should be located in <processing-video path>/library/<system> (where system is macos-aarch64, macos-x86_64, windows_amd64, or linux-amd64), and the plugins in <processing-video path>/library/<system>/gstreamer-1.0, we set them using the gstreamer.library.path and gstreamer.plugin.path, which are set in the Run Configurations of the Eclipse project:

image

under the Arguments tab:

image

After doing all of this, the project should run and play the video file:

image

Clone this wiki locally