使用Java Gstreamer绑定1,我想从磁盘读取一个音频文件,并将该文件的一部分写回磁盘。为此,我不能使用“filesrc”元素,而是发现我可以使用Gnonlin插件2中的“gnlurisource”元素。
我接受了Gstreamer Java绑定,并在本地编译它,得到一个我添加到项目中的jar文件。我还使用以下命令在Ubuntu上安装了Gstreamer:
sudo apt-get install libgstreamer1.0-dev
sudo apt-get install gstreamer1.0-gnonlin
程序编译时没有错误,但它仍然卡住并且什么都不做。下面我附上我的程序代码:
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();
}
}
我对Gstreamer没有那么多经验,你能给我一个关于错误的暗示吗?
谢谢!
答案 0 :(得分:0)
更新:我设法从命令行使用gstreamer从音频文件中选择一个段。 “gnlurisource”元素具有“inpoint”参数来设置段开始时间和“持续时间”以指定段的持续时间。 这是命令:
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
我仍在尝试用Java实现这个管道。我尝试过类似的东西,但它不起作用:
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();
}