简体   繁体   English

如何使用gstreamer创建中继服务器?

[英]How to create a relay server with gstreamer?

I know how I can accept a stream from my webcam and display it inside a swing component: 我知道如何接受来自网络摄像头的流并将其显示在swing组件中:

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);
        }
    });

What I'd like to do now would be to make this stream available for each client which will connect to a certain port using, for example, vlc media player or another video stream reader. 我现在想做的是使此流可用于每个客户端,这些客户端将使用例如vlc媒体播放器或其他视频流读取器连接到特定端口。 This would have to be generic, that is I may want to connect another gstreamer program too and make this program a relay server: it is client for the first one and makes this stream available for other clients. 这将是通用的,也就是说,我可能也想连接另一个gstreamer程序并使该程序成为中继服务器:它是第一个客户端,并将此流提供给其他客户端。

Is there a way to do this? 有没有办法做到这一点? I am still new to gstreamer... 我还是gstreamer的新手...

This is actually quite straightforward using RTPbin, but first you'll want to encode your video because sending raw YUV will take an enormous amount of bandwidth. 使用RTPbin实际上这非常简单,但是首先您要对视频进行编码,因为发送原始YUV将占用大量带宽。

Here is an example pipeline using h263 encoding and RTP bin: 这是使用h263编码和RTP bin的示例管道:

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                           \

More information here (including how to receive this data on the other end): http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-rtpbin.html 此处提供更多信息(包括如何在另一端接收此数据): http : //gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-插件,rtpbin.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM