我试图让以下管道在gstreamer-java中工作(使用gstreamer-0.10):
" gst-launch-0.10 filesrc location = big_buck_bunny_480p_surround-fix.avi! decodebin2! ffmpegcolorspace! autovideosink"
此管道在命令行上运行。 机器vbox vm运行ubuntu 14.04 LTS
任何人都可以帮我确定我的问题可能与java代码中的管道有关吗?
java代码如下:
public static void main(String [] args){
args = Gst.init("AppSrcTest", args);
/* setup pipeline */
pipeline = new Pipeline("pipeline");
final AppSrc appsrc = (AppSrc) ElementFactory.make("appsrc", "appsrc");
final Element decodebin = ElementFactory.make("decodebin2", null);
final Element ffmpegcolorspace = ElementFactory.make("ffmpegcolorspace", "formatConverter");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("FakeSrcTest");
VideoComponent panel = new VideoComponent();
panel.setPreferredSize(new Dimension(width, height));
frame.add(panel, BorderLayout.CENTER);
Element videosink = panel.getElement();
pipeline.addMany(appsrc, decodebin,ffmpegcolorspace, videosink);
Element.linkMany(appsrc, decodebin,ffmpegcolorspace, videosink);
appsrc.setTimestamp(true);
appsrc.set("emit-signals", true);
appsrc.connect(new AppSrc.NEED_DATA() {
public void needData(AppSrc elem, int size) {
try {
//other code
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
}
System.out.println("Data collected..");
Buffer buffer = new Buffer(outputStream.toByteArray().length);
buffer.getByteBuffer().put(outputStream.toByteArray());
appsrc.pushBuffer(buffer);
} catch (Exception e) {
e.printStackTrace();
}
}
});
当我开始收到错误时,调试信息如下:
0:00:06.194558872 [332m14803[00m 0x7f24dc038680 [32;01mINFO [00m [00;01;37;41m GST_ELEMENT_PADS gstelement.c:728:gst_element_add_pad:<decodebin20>[00m adding pad 'src0'
0:00:06.194682253 [332m14803[00m 0x7f24dc038680 [32;01mINFO [00m [00;01;37;41m GST_ELEMENT_PADS gstelement.c:728:gst_element_add_pad:<decodebin20>[00m adding pad 'src1'
0:00:06.194765369 [332m14803[00m 0x7f24dc038680 [32;01mINFO [00m [00;01;31m GST_STATES gstbin.c:2942:bin_handle_async_done:<decodebin20>[00m committing state from READY to PAUSED, old pending PAUSED
0:00:06.194824176 [332m14803[00m 0x7f24dc038680 [32;01mINFO [00m [00;01;31m GST_STATES gstbin.c:2962:bin_handle_async_done:<decodebin20>[00m completed state change, pending VOID
0:00:06.194877892 [332m14803[00m 0x7f24dc038680 [32;01mINFO [00m [00;01;31m GST_STATES gstelement.c:2365:_priv_gst_element_state_changed:<decodebin20>[00m notifying about state-changed READY to PAUSED (VOID_PENDING pending)
Got TAG event
Tag audio-codec = Dolby Digital (AC-3)
Tag bitrate = 448000
0:00:06.212171413 [332m14803[00m 0x7f24dc038680 [32;01mINFO [00m [00m a52dec gsta52dec.c:439:gst_a52dec_reneg:<a52dec0>[00m reneg channels:6 rate:48000
0:00:06.258920113 [332m14803[00m 0x7f24dc043400 [33;01mWARN [00m [00m ffmpeg gstffmpegdec.c:2299:gst_ffmpegdec_frame:<ffdec_mpeg40>[00m ffdec_mpeg4: decoding error (len: -1, have_data: 0)
0:00:06.259312652 [332m14803[00m 0x7f24dc043450 [32;01mINFO [00m [00m basesrc gstbasesrc.c:2562:gst_base_src_loop:<appsrc>[00m pausing after gst_pad_push() = not-linked
0:00:06.259366067 [332m14803[00m 0x7f24dc043450 [33;01mWARN [00m [00m basesrc gstbasesrc.c:2625:gst_base_src_loop:<appsrc>[00m error: Internal data flow error.
0:00:06.259383885 [332m14803[00m 0x7f24dc043450 [33;01mWARN [00m [00m basesrc gstbasesrc.c:2625:gst_base_src_loop:<appsrc>[00m error: streaming task paused, reason not-linked (-1)
0:00:06.259418691 [332m14803[00m 0x7f24dc043450 [32;01mINFO [00m [00;01;31;47m GST_ERROR_SYSTEM gstelement.c:1964:gst_element_message_full:<appsrc>[00m posting message: Internal data flow error.
0:00:06.268446147 [332m14803[00m 0x7f24dc043400 [33;01mWARN [00m [00m ffmpeg gstffmpegdec.c:2299:gst_ffmpegdec_frame:<ffdec_mpeg40>[00m ffdec_mpeg4: decoding error (len: -1, have_data: 0)
0:00:06.273770933 [332m14803[00m 0x7f24dc043400 [33;01mWARN [00m [00m ffmpeg gstffmpegdec.c:2299:gst_ffmpegdec_frame:<ffdec_mpeg40>[00m ffdec_mpeg4: decoding error (len: -1, have_data: 0)
0:00:06.274603418 [332m14803[00m 0x7f24dc043400 [33;01mWARN [00m [00m ffmpeg gstffmpegdec.c:2299:gst_ffmpegdec_frame:<ffdec_mpeg40>[00m ffdec_mpeg4: decoding error (len: -1, have_data: 0)
0:00:06.275939105 [332m14803[00m 0x7f24dc043400 [33;01mWARN [00m [00m ffmpeg gstffmpegdec.c:2299:gst_ffmpegdec_frame:<ffdec_mpeg40>[00m ffdec_mpeg4: decoding error (len: -1, have_data: 0)
0:00:06.277303268 [332m14803[00m 0x7f24dc043400 [33;01mWARN [00m [00m ffmpeg gstffmpegdec.c:2299:gst_ffmpegdec_frame:<ffdec_mpeg40>[00m ffdec_mpeg4: decoding error (len: -1, have_data: 0)
Error: code=1 message=Internal data flow error.
0:00:06.291740181 [332m14803[00m 0x7f24dc043450 [32;01mINFO [00m [00;01;31;47m GST_ERROR_SYSTEM gstelement.c:1987:gst_element_message_full:<appsrc>[00m posted error message: Internal data flow error.
0:00:06.292844435 [332m14803[00m 0x7f24dc043400 [33;01mWARN [00m [00m ffmpeg gstffmpegdec.c:2299:gst_ffmpegdec_frame:<ffdec_mpeg40>[00m ffdec_mpeg4: decoding error (len: -1, have_data: 0)
Got TAG event
Tag minimum-bitrate = -1
Tag bitrate = 0
Tag maximum-bitrate = 0
0:00:06.297233217 [332m14803[00m 0x7f24dc043400 [33;01mWARN [00m [00m ffmpeg gstffmpegdec.c:2299:gst_ffmpegdec_frame:<ffdec_mpeg40>[00m ffdec_mpeg4: decoding error (len: -1, have_data: 0)
0:00:06.297382004 [332m14803[00m 0x7f24dc043400 [32;01mINFO [00m [00;01;31;41m GST_PADS gstpad.c:3554:gst_pad_event_default_dispatch:<mpeg4vparse0:sink>[00m Sending event 0x7f24dc148c60 (eos) to all internally linked pads
答案 0 :(得分:0)
回答我自己的问题
我在网上阅读有关gstreamer的最佳建议是:在执行代码之前在命令行上测试管道。因此,如果它在命令行上运行,它应该在代码中工作。
以下问题在c代码中回答我的问题。即它建议解决错误&#34;暂停后gst_pad_push()= not-linked&#34; gStreamer-Sharp Dynamic pads not linking
但是,我不知道如何在Java代码中执行此操作。因此,我使用以下教程更加熟悉gstreamer中的动态管道:动态管道:http://docs.gstreamer.com/display/GstSDK/Basic+tutorial+3%3A+Dynamic+pipelines
上述教程中有两点需要注意解决这个问题:
GSignals是GStreamer的关键点。它们允许您在发生有趣事件时收到通知(通过回调)。信号由名称标识,每个GObject都有自己的信号。
解复用器从没有其他元素可以链接的源焊盘开始,因此管道必须终止于它们。解决方案是构建从源到分离器的管道,并将其设置为运行(播放)。当解复用器已经收到足够的信息来了解容器中流的数量和种类时,它将开始创建源焊盘。现在是我们完成管道建设并将其连接到新添加的解复用器垫的最佳时机。
因此我的java代码如下所示:
public void run() {
JFrame frame = new JFrame("FakeSrcTest");
VideoComponent panel = new VideoComponent();
panel.setPreferredSize(new Dimension(width, height));
frame.add(panel, BorderLayout.CENTER);
final Element videosink = panel.getElement();
pipeline.addMany(appsrc, decodebin2, ffmpegcolorspace, videosink);
Element.linkMany(appsrc, decodebin2);
//we need to finish linking the pipeline later...
appsrc.set("emit-signals", true);
appsrc.connect(new AppSrc.NEED_DATA() { ...
此外,您需要为在decodebin2中创建打击垫时添加一个侦听器,此时您需要完成链接管道。
/* listen for newly created pads */
decodebin2.connect(new Element.PAD_ADDED() {
public void padAdded(Element element, Pad pad) {
System.out.println("New Pad " + pad.getName() + " was created");
Element.linkMany(decodebin2, ffmpegcolorspace, videosink);
}
});
那就是它。
我希望它可以帮助别人。