Raspberry Pi 使用 Gstreamer 将 USB 网络摄像头串流到计算机

Raspberry Pi USB Webcam Stream to Computer using Gstreamer

我有一个连接到 raspberry pi 的鱼眼 USB 网络摄像头,我正在尝试将其流式传输到计算机。我玩过 ffmpeg,它似乎在 320x240 之外有点滞后。据我所知,人们对 gstreamer 很满意。

所以我测试了 USB 网络摄像头,它在本地工作

gst-launch-1.0 -v v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480' ! glimagesink

这些是我一直试图用来将视频传输到我的计算机的命令。但是,我只看到绿色 window。

TCP 服务器:gst-launch-1.0 -v v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=30/1' ! x264enc byte-stream=true ! rtph264pay ! gdppay ! tcpserversink host=192.168.200.38 port=5000 sync=false

TCP 客户端:gst-launch-1.0 -v tcpclientsrc host=192.168.200.38 port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false

UDP 服务器: gst-launch-1.0 -v v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=30/1' ! x264enc byte-stream=true ! rtph264pay ! gdppay ! udpsink host=192.168.200.37 port=5000 sync=false

UDP 客户端: gst-launch-1.0 -v udpsrc port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false

我想我一定是把插件管道弄错了。任何建议表示赞赏。

首先尝试以下方法:

  1. 在你的 x264enc 之后添加 tune=zerolatency(这在嵌入式系统中通常需要)
  2. 重新检查 IP 和连接(我看到 IP 在 TCP 和 UDP 情况下是不同的)

如果问题还没有解决,请说明几点:

  1. 你的摄像头提供的是什么视频格式(在第一个命令后加“-v”,它会告诉你)
  2. x264enc 支持该格式吗?
    (根据its manual,x264enc支持I420、YV12、Y42B、Y444、NV12、I420_10LE、I422_10LE、Y444_10LE
    • 如果不支持该格式,请尝试使用其他相机或其他编码器。
    • 如果支持,请尝试确认您的编码命令(使用filesink/fakesink)和解码命令(使用videotestsrc

所以我花了一天的时间来解决问题并使其正常工作。我会 post 我目前所拥有的。队列让 rpi 多线程处理 h264 编码部分,我已经将 omxh264enc 子化为 x264enc,因为它是 openmax/accelerated。这两项更改都有助于延迟。

我猜我不需要 gdppay? (看到有人在没有它的情况下直播

rpi 侧

gst-launch-1.0 -vv -e v4l2src device=/dev/video0 ! "video/x-raw,width=640,height=480" ! queue ! omxh264enc ! h264parse ! rtph264pay ! udpsink host=192.168.200.37 port=5000

电脑端

gst-launch-1.0 -vv -e udpsrc port=5000 ! application/x-rtp, payload=96 ! rtph264depay ! queue ! avdec_h264 ! videoconvert ! autovideosink sync=false