我想使用 GStreamer 管道元素通过 rtsp 进行流式传输。首先,我使用 gst-inspect-1.0 检查 rtspclientsink 是否可用:
xilinx-k26-starterkit-2020_2:/# gst-inspect-1.0 | grep rtsp
rtspclientsink: rtspclientsink: RTSP RECORD client
rtsp: rtspsrc: RTSP packet receiver
rtsp: rtpdec: RTP Decoder
然后,编写最简单的管道并使用 videotestsrc 作为源和 kmssink 作为接收器进行测试。以下管道效果很好:
gst-launch-1.0 videotestsrc ! video/x-raw, width=1920, height=1080 ! kmssink bus-id=fd4a0000.zynqmp-display fullscreen-overlay=1 sync=false
然后,将sink更改为rtspclientsink:
gst-launch-1.0 videotestsrc ! video/x-raw, width=1920, height=1080 ! rtspclientsink location=rtsp://localhost:554/test
但是,即使使用简单的管道,流也无法启动并遇到错误:
xilinx-k26-starterkit-2020_2:/# gst-launch-1.0 videotestsrc ! video/x-raw, width=1920,height=1080 ! rtspclientsink location=rtsp://localhost:554/test
Setting pipeline to PAUSED ...
Pipeline is PREROLLED ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://localhost:554/test
ERROR: from element /GstPipeline:pipeline0/GstRTSPClientSink:rtspclientsink0: Could not open resource for reading and writing.
Additional debug info:
../../../gst-rtsp-server-1.16.1/gst/rtsp-sink/gstrtspclientsink.c(3236): gst_rtsp_client_sink_connect_to_server (): /GstPipeline:pipeline0 /GstRTSPClientSink:rtspclientsink0:
Failed to connect. (Generic error)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
有人能告诉我这个错误以及如何使用 rtspclientsink 作为接收器吗?我还考虑使用使用 rtsp 服务器的脚本(如下所示)进行流式传输,如下所示,但我想知道是否可以使用 rtspclientsink 作为管道元素。谢谢。
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#define DEFAULT_RTSP_PORT "9001"
...(some code)
/* create a server instance */
server = gst_rtsp_server_new ();
g_object_set (server, "service", port, NULL);
mounts = gst_rtsp_server_get_mount_points (server);
factory = gst_rtsp_media_factory_new ();
gst_rtsp_media_factory_set_launch (factory, argv[1]);
gst_rtsp_media_factory_set_shared (factory, TRUE);
...(some code that creates pipeline and calls rtsp stream function)
最佳答案
从下载rtsp-simple服务器
https://github.com/aler9/rtsp-simple-server/releases
解压并运行
tar xvf rtsp-simple-server_v0.19.3_linux_amd64.tar.gz
./rtsp-simple-server
它会告诉你它正在监听哪个端口
2022/07/31 13:23:34 INF rtsp-simple-server v0.19.3
2022/07/31 13:23:34 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2022/07/31 13:23:34 INF [RTMP] listener opened on :1935
2022/07/31 13:23:34 INF [HLS] listener opened on :8888
将您的 rtsp 流指向它(如果您通过网络发送,请将 localhost 更改为托管 rtsp-simple-server 的服务器)
gst-launch-1.0 -v videotestsrc ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! x264enc speed-preset=veryfast tune=zerolatency bitrate=800 ! rtspclientsink location=rtsp://localhost:8554/mystream
检查rtsp-simple-server控制台日志
2022/07/31 13:26:02 INF [RTSP] [conn 192.168.1.130:34932] opened
2022/07/31 13:26:02 INF [RTSP] [session 247376253] created by 192.168.1.130:34932
2022/07/31 13:26:03 INF [RTSP] [session 247376253] is publishing to path 'mystream', 1 track with UDP
打开vlc-player -> 媒体 -> 打开网络流
按播放
vlc 应显示测试模式
您将在 rtsp-simple-server 控制台日志中看到以下内容
2022/07/31 13:27:10 INF [RTSP] [conn 127.0.0.1:53900] opened
2022/07/31 13:27:10 INF [RTSP] [session 749381985] created by 127.0.0.1:53900
2022/07/31 13:27:10 INF [RTSP] [session 749381985] is reading from path 'mystream', 1 track with UDP
关于linux - 从命令行 rtspclientsink 测试管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69098720/