0

Using Java Gstreamer binding 1, I want to read an audio file from disk and write a segment of this file back to disk. For this, I cannot use the "filesrc" element, but instead I found that I can use the "gnlurisource" element from the Gnonlin plugin 2.

I took Gstreamer Java binding and I compiled it locally, getting a jar file that I added to my project. I also installed Gstreamer on Ubuntu using the following commands:

sudo apt-get install libgstreamer1.0-dev
sudo apt-get install gstreamer1.0-gnonlin

The program compiles without errors, but it remains stuck and does nothing. Below I attach my program code:

import java.util.concurrent.TimeUnit;
import org.freedesktop.gstreamer.Element;
import org.freedesktop.gstreamer.ElementFactory;
import org.freedesktop.gstreamer.Gst;
import org.freedesktop.gstreamer.Pipeline;
import org.freedesktop.gstreamer.State;


public class AudioSegmentation {

public static void main(String[] args) {

    Pipeline pipe;
    Element asr;
    Element composition;
    Element gnlsource;
    Element convert;
    Element filesink;

    Gst.init();

    pipe = new Pipeline("SimplePipeline");
    composition = ElementFactory.make("gnlcomposition", "comp");
    gnlsource = ElementFactory.make("gnlurisource", "gnlsource");

    convert = ElementFactory.make("audioconvert", "compconvert");
    filesink = ElementFactory.make("filesink", "filesink");

    gnlsource.set("uri", "file:///home/user/Desktop/file-source.wav");
    gnlsource.set("start", TimeUnit.SECONDS.toNanos(5));
    gnlsource.set("duration", TimeUnit.SECONDS.toNanos(2));

    filesink.set("location", "/home/user/Desktop/file-destination.wav");

    composition.link(gnlsource);
    pipe.addMany(composition, convert, filesink);
    Element.linkMany(composition, convert, filesink);

    pipe.setState(State.PLAYING);
    Gst.main();
    Gst.quit();

}

}

I don't have so much experience with Gstreamer, can you give me a hint about what's wrong?

Thank you!

1 Answers1

0

UPDATE: I managed to use gstreamer from the command line to select a segment from an audio file. The "gnlurisource" element has the "inpoint" paramenter to set the segment start time and "duration" to specify the duration of the segment. Here is the command:

gst-launch-1.0 gnlurisource uri=file:///home/user/Desktop/file-source.wav inpoint=2000000000 duration=1500000000 ! audioconvert ! wavenc ! filesink location=/home/user/Desktop/file-destination.wav

I'm still trying to implement this pipeline in Java. I tried something like that, but it doesn't work:

import java.util.concurrent.TimeUnit;
import org.freedesktop.gstreamer.Element;
import org.freedesktop.gstreamer.ElementFactory;
import org.freedesktop.gstreamer.Gst;
import org.freedesktop.gstreamer.Pipeline;
import org.freedesktop.gstreamer.State;


public class AudioSegmentation {

public static void main(String[] args) {

    Pipeline pipe;
    Element gnlsource;
    Element audioconvert;
    Element wavenc;
    Element filesink;

    Gst.init();

    pipe = new Pipeline("SimplePipeline");
    gnlurisource = ElementFactory.make("gnlurisource", "gnlurisource");
    audioconvert = ElementFactory.make("audioconvert", "audioconvert");
    wavenc = ElementFactory.make("wavenc", "wavenc");
    filesink = ElementFactory.make("filesink", "filesink");

    gnlurisource.set("uri", "file:///home/user/Desktop/file-source.wav");
    gnlurisource.set("inpoint", TimeUnit.SECONDS.toNanos(2));
    gnlurisource.set("duration", TimeUnit.SECONDS.toNanos(3));

    filesink.set("location", "/home/user/Desktop/file-destination.wav");

    pipe.addMany(gnlurisource, audioconvert, wavenc, filesink);
    Element.linkMany(gnlurisource, audioconvert, wavenc, filesink);

    pipe.setState(State.PLAYING);
    Gst.main();
    Gst.quit();

}