我有两个工作管道 - 一个用于 MJPEG 流,另一个用于 H.264。
udpsrc port=5021 caps="application/x-rtp,encoding-name=JPEG,payload=26" ! \
rtpjitterbuffer ! rtpjpegdepay ! jpegparse ! jpegdec ! autovideosink
udpsrc port=5021 caps="application/x-rtp,encoding-name=H264,payload=96" ! \
rtpjitterbuffer ! rtph264depay ! h264parse ! openh264dec ! autovideosink
现在我不想根据当前使用的编码在这些之间手动切换,所以我尝试使用 switchbin,这似乎对我不起作用......
我尝试过的:
udpsrc port=5021 ! rtpjitterbuffer ! \
switchbin num-paths=2 \
path0::element="rtpjpegdepay ! jpegparse ! jpegdec" \
path0::caps="application/x-rtp,encoding-name=JPEG,payload=26" \
path1::element="rtph264depay ! h264parse ! openh264dec" \
path1::caps="application/x-rtp,encoding-name=H264,payload=96" ! autovideosink
这只是在
Setting pipeline to PLAYING ...
之后不显示任何内容。
udpsrc port=5021 ! \
switchbin num-paths=2 \
path0::element="rtpjitterbuffer ! rtpjpegdepay ! jpegparse ! jpegdec" \
path0::caps="application/x-rtp,encoding-name=JPEG,payload=26" \
path1::element="rtpjitterbuffer ! rtph264depay ! h264parse ! openh264dec" \
path1::caps="application/x-rtp,encoding-name=H264,payload=96" ! autovideosink
这引发以下错误:
ERROR: from element /GstPipeline:pipeline0/GstUDPSrc:udpsrc0: Internal data stream error.
我在这里做错了什么?
仅供参考:我正在使用 Windows 11 23H2 和 GStreamer 1.22.7(MSVC 64 位)。
我认为您不能在您的情况下使用直接 RTP/UDP 流。 udpsrc 无法猜测其 src 上限(您在工作管道中明确设置的)。
您可以使用 RTSP。使用 gstreamer,您可以非常轻松地设置 RTSP 服务器。您必须安装 libgstrtspserver-1.0-0,然后构建示例应用程序test-launch。 构建完成后,您可以使用:
# RTP/JPG
test-launch.exe "videotestsrc ! jpegenc ! rtpjpegpay name=pay0"
# RTP/H264
test-launch.exe "videotestsrc pattern=ball ! videoconvert ! x264enc ! h264parse ! rtph264pay name=pay0"
# RTP/H265
test-launch.exe "videotestsrc ! videoconvert ! x265enc ! h265parse ! rtph265pay name=pay0"
服务器默认应在端口 8554 上侦听客户端。
现在在接收方,也许这些简单的命令就足够了:
gst-play-1.0 rtsp://<SERVER_IP>:8554/test
gst-launch-1.0 playbin uri=rtsp://<SERVER_IP>:8554/test
如果你想有更多的控制权,你可以使用 switchbin 例如:
gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test ! switchbin num-paths=3\
path0::caps="application/x-rtp,encoding-name=JPEG,clock-rate=90000,payload=26" path0::element="rtpjpegdepay ! jpegdec"\
path1::caps="application/x-rtp,encoding-name=H264,clock-rate=90000,payload=96" path1::element="rtph264depay ! h264parse ! openh264dec ! videoconvert"\
path2::caps="ANY" path2::element="fakesink videotestsrc pattern=snow" \
! autovideosink
如果未找到 RTPH264 或 RTPJPG(例如流式传输 H265),后备情况将仅显示雪花图案。