Gstreamer:udpsink / udpsrc与tcpserversink / tcpclientsrc

时间:2018-05-27 06:25:42

标签: gstreamer

我对gstreamer很新,但经过大量的研究后,我现在设法创建了自己的工作流程,通过网络将网络摄像头从Raspberry PI Zero通过UDP传输流式传输到PC。我很高兴我的进步! :)

但我正在努力创建TCP传输......

此管道在UDP上完美运行: (注意:使用测试视频源和JPEG编码简化):

Server UDP (192.168.2.1):
gst-launch-1.0 videotestsrc is-live=true ! jpegenc ! rtpjpegpay  ! udpsink host=192.168.2.13  port=7001

Client UDP (192.168.2.13):
gst-launch-1.0 udpsrc port=7001 ! application/x-rtp,encoding-name=JPEG ! rtpjpegdepay ! jpegdec ! autovideosink

...但是当我使用带有完全相同元素的TCP接收器/源时,我只收到错误。

使用 tcpserversink tcpclientsrc 修改后的管道:

Server TCP (192.168.2.1):
gst-launch-1.0 videotestsrc is-live=true ! jpegenc ! rtpjpegpay  ! tcpserversink port=7001

Client TCP (192.168.2.13):
gst-launch-1.0 tcpclientsrc host=192.168.2.1 port=7001 ! application/x-rtp,encoding-name=JPEG ! rtpjpegdepay ! jpegdec ! autovideosink

尝试1: tcpserversink port = 7001

ERROR: Failed to connect to host '192.168.2.1:7001': No connection could be made because the target machine actively refused it.

尝试2: tcpserversink host = localhost port = 7001

ERROR: from element /GstPipeline:pipeline0/GstTCPClientSrc:tcpclientsrc0: Could not open resource for reading.

尝试3: tcpserversink host = 127.0.0.1 port = 7001

ERROR: from element /GstPipeline:pipeline0/GstTCPClientSrc:tcpclientsrc0: Could not open resource for reading.

尝试4: tcpserversink host = 192.168.2.1 port = 7001

ERROR: from element /GstPipeline:pipeline0/GstTCPClientSrc:tcpclientsrc0: Internal data stream error.

尝试5: tcpserversink host = 0.0.0.0 port = 7001

ERROR: from element /GstPipeline:pipeline0/GstTCPClientSrc:tcpclientsrc0: Internal data stream error.

我想我应该可以替换src&在没有管道破裂的情况下沉没元素所以我必须遗漏一些东西。

我很感激你能解决这个问题。

1 个答案:

答案 0 :(得分:1)

您可以(至少)使用以下两种方法之一解决它。首先是在您的媒体类型的rtp有效负载之后添加rtpstreampay元素。

https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good/html/gst-plugins-good-plugins-rtpstreampay.html

服务器:

gst-launch-1.0 videotestsrc is-live=true \
    ! jpegenc \
    ! rtpjpegpay \
    ! rtpstreampay \
    ! tcpserversink port=7001

客户端:

gst-launch-1.0 tcpclientsrc port=7001 \
    ! application/x-rtp-stream,encoding-name=JPEG \
    ! rtpstreamdepay \
    ! rtpjpegdepay \
    ! jpegdec \
    ! autovideosink

第二种方法是使用混合器而不是rtp有效负载,例如matroskamux,这很通用。

服务器:

gst-launch-1.0 videotestsrc is-live=true \
    ! jpegenc \
    ! matroskamux \
    ! tcpserversink port=7001

客户端:

gst-launch-1.0 tcpclientsrc port=7001 \
    ! matroskademux \
    ! jpegdec \
    ! autovideosink

如果要进行客户端/服务器rtp连接,则可能还需要研究GstRtspServer。这样的简单Python脚本将充当服务器。

rtspserver.py

import gi
gi.require_version('Gst','1.0')
gi.require_version('GstRtspServer','1.0')
from gi.repository import Gst, GObject, GstRtspServer

Gst.init(None)
mainloop = GObject.MainLoop()
server = GstRtspServer.RTSPServer()
factory = GstRtspServer.RTSPMediaFactory()
factory.set_launch((
    'videotestsrc is-live=true '
    '! jpegenc '
    '! rtpjpegpay name=pay0 pt=26'
))
# allow multiple connections
factory.set_shared(True)
mounts = server.get_mount_points()
mounts.add_factory('/live', factory)
server.attach(None)
mainloop.run()

您可以使用这样的管道来查看输出。

gst-launch-1.0 \
    rtspsrc location=rtsp://localhost:8554/live latency=100 \
    ! rtpjpegdepay \
    ! jpegdec \
    ! autovideosink