2014-03-31 18 views
0

我知道我可以从我的摄像头接受流,并显示它Swing组件内:如何用gstreamer创建中继服务器?

args = Gst.init("VideoTest", args); 
    pipe = new Pipeline("VideoTest"); 
    final Element videosrc = ElementFactory.make("v4l2src", "source"); 
    final Element videofilter = ElementFactory.make("capsfilter", "filter"); 
    videofilter.setCaps(Caps.fromString("video/x-raw-yuv, width=640, height=480" 
      + ", bpp=32, depth=32, framerate=30/1")); 
    SwingUtilities.invokeLater(new Runnable() { 

     public void run() { 
      VideoComponent videoComponent = new VideoComponent(); 
      Element videosink = videoComponent.getElement(); 
      pipe.addMany(videosrc, videofilter, videosink); 
      Element.linkMany(videosrc, videofilter, videosink); 

      // Now create a JFrame to display the video output 
      JFrame frame = new JFrame("Swing Video Test"); 
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      frame.add(videoComponent, BorderLayout.CENTER); 
      videoComponent.setPreferredSize(new Dimension(720, 576)); 
      frame.pack(); 
      frame.setVisible(true); 

      // Start the pipeline processing 
      pipe.setState(State.PLAYING); 
     } 
    }); 

我想什么现在要做的是使可用于每个客户端将连接到该流例如使用vlc媒体播放器或其他视频流阅读器的某个端口。这必须是通用的,也就是说,我可能还想连接另一个gstreamer程序,并将此程序设置为中继服务器:它是第一个客户端,并使此流可用于其他客户端。

有没有办法做到这一点?我还是新的GStreamer ...

回答

1

这实际上是非常简单使用RTPbin,但首先你要编码的视频,因为发送原始YUV将带宽的巨大数额。

下面是一个例子管道使用H263编码和RTP仓:

gst-launch-1.0 rtpbin name=rtpbin \ 
     v4l2src ! videoconvert ! ffenc_h263 ! rtph263ppay ! rtpbin.send_rtp_sink_0 \ 
        rtpbin.send_rtp_src_0 ! udpsink port=5000       \ 
        rtpbin.send_rtcp_src_0 ! udpsink port=5001 sync=false async=false \ 
        udpsrc port=5005 ! rtpbin.recv_rtcp_sink_0       \ 

的更多信息在这里(包括如何接收在另一端将该数据): http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-rtpbin.html

+0

我试图与VLC打开它但说“解复用:不能偷看”。而且ffenc_h263不存在,我不得不使用avenc_h263 – Phate

+0

avenc_h263是GStreamer的1.x中的等价ffmpeg的编码器插件对不正确的管道道歉。这听起来像VLC不知道如何处理一个原始的h263流,因为你看到的错误来自于分路器,你甚至不会发送混合内容。你有没有尝试用gstreamer播放流?如果你可以在GST中播放而不是在VLC中播放,你可能需要将你的h263流包装在传输流中。 – ejcunningham