【问题标题】:How to create a relay server with gstreamer?如何使用 gstreamer 创建中继服务器?
【发布时间】:2014-03-31 13:13:11
【问题描述】:

我知道如何接受来自网络摄像头的流并将其显示在摆动组件中:

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 的新手...

【问题讨论】:

    标签: java gstreamer


    【解决方案1】:

    这实际上使用 RTPbin 非常简单,但首先您需要对视频进行编码,因为发送原始 YUV 会占用大量带宽。

    这是一个使用 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                           \
    

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

    【讨论】:

    • 我尝试用 vlc 打开它,但显示“demux: cannot peek”..而且 ffenc_h263 不存在,我不得不使用 avenc_h263
    • avenc_h263 是 gstreamer 1.x 的等效 ffmpeg 编码器插件。为不正确的管道道歉。听起来 VLC 不知道如何处理原始 h263 流,因为您看到的错误来自解复用器,您甚至没有发送多路复用的内容。您是否尝试使用 gstreamer 播放流?如果您可以在 GST 中播放但不能在 VLC 中播放,您可能还需要将 h263 流包装在传输流中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 2015-02-05
    • 2016-11-16
    • 1970-01-01
    • 2021-09-26
    相关资源
    最近更新 更多