سؤال

I know how I can accept a stream from my webcam and display it inside a swing component:

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. 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.

Is there a way to do this? I am still new to 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.

Here is an example pipeline using h263 encoding and 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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top