我是gstreamer-java的新手, 我正在使用gstreamer做一个java swt项目,我读了教程和 其他事情要做。 我决定首先编写管道,用命令行测试, 并且所有管道工作正常。 但现在我想在我的java代码中使用它。 我试过“pipeline.launch”,例如这个管道: “v4l2src!videoscale!video / x-raw-yuv,height = 240!xvimagesink autoaudiosrc! audioconvert! alsasink“ (同时获得网络摄像头输出和音频输出)
但结果不是预期的,也就是说,我有两个窗户, 而不是一个。一个用于网络摄像头输出,另一个用于包含 没有。我明白这是因为有一个窗口 用管道生成。
我现在知道我应该使用视频组件来包含网络摄像头 流入我的特定框架。 我试过这个:
Display display = new Display();
Shell shell = new Shell(display); // my frame
Pipeline pipe = new Pipeline("Webcam");
Element src = ElementFactory.make("v4l2src", "sourcevideo"); // the
第一个来源 元素src2 = ElementFactory.make(“autoaudiosrc”,“sourceaudio”)// 第二个来源
VideoComponent videocomponent = new VideoComponent(shell, SWT.NONE,
TRUE); //包括进入我的框架
videocomponent.getElement().setName("webcam");
videocomponent.setKeepAspect(true);
videocomponent.setLayoutData(new GridData());
Element videosink = videocomponent.getElement();
Element audiosink = ElementFactory.make("alsasink",
“sortieaudio”); //用于音频输出 videocomponent.setBounds(25,65,420,320);
pipe.addMany(src, videosink,src2, audiosink);
Element.linkMany(src, videosink, src2, audiosink);
pipe.play();
shell.open();
但网络摄像头存在错误。视频流已停止,并且存在 没有音频输出。 有人能帮我吗?我真的很困惑!
答案 0 :(得分:0)
最后我在其他地方找到了解决方案。 对于这个管道,
gst-launch -ev v4l2src!视频! video / x-raw-yuv,身高= 240! xvimagesink autoaudiosrc! audioconvert! alsasink
这是gstreamer-java中的解决方案,不使用“Pipeline.launch”:
VideoComponent videocomponent = new VideoComponent(shell,SWT.NONE,true); videocomponent.getElement()的setName( “网络摄像头”); videocomponent.setKeepAspect(真); videocomponent.setLayoutData(new GridData());
Element videosource,videosink,audiosource,audioconv,audiosink; videosource = ElementFactory.make(“v4l2src”,“sourcevid”); audiosource = ElementFactory.make(“autoaudiosrc”,“sourceaud”); audioconv = ElementFactory.make(“audiconvert”,“conv”); audiosink = ElementFactory.make(“alsasink”,“DestAud”); videosink = videocomponent.getElement();
pipe.addMany(videosrc,videosink,audiosrc,audioconv,audiosrc,videosink);
Element.linkMany(videosrc,videosink); Element.linkMany(audiosrc,audioconv,audiosink);
pipe.play();
shell.open();
如果这可以帮助某人,那就太好了! 再见