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!

asked Sep 30, 2017 at 15:12

1 Answer 1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.