6

我正在尝试使用 gstreamer 1.0 将网络摄像头视频从 Raspberry 流式传输到 VLC 播放器。现在我得到了树莓的以下命令:

gst-launch-1.0 -vv -e v4l2src device=/dev/video0  \
! videoscale \
! "video/x-raw,width=352,height=288,framerate=10/1" \
! queue  \
! x264enc \
! h264parse \
! rtph264pay config-interval=10 pt=96 \
! udpsink host=239.255.12.42 port=5004

以及以下 sdp 文件以使用 vlc 播放流:

c=IN IP4 239.255.12.42
m=video 5004 RTP/AVP 96
a=rtpmap:96 H264/90000

当我运行 gst-launch-1.0 命令时,我可以使用 wireshark 看到它正在发送 udp 数据包,但是当我尝试使用 vlc 和 sdp 文件播放流时,我什么也得不到。vlc 日志说:

es error: cannot peek
es error: cannot peek
live555 error: no data received in 10s, aborting

我不知道怎么了。我可能没有正确构建管道,这就是 vlc 无法将流识别为正确的视频流的原因。有任何想法吗?

在此先感谢您的帮助。

4

1 回答 1

6

VLC 理解 ts 流结合 RTP 协议。该方法是在 mpegtsmux 之后使用 rtp 加载器,它将加载生成的 ts 缓冲区(数据包)。

所以代替这个:

src ! queue ! x264enc ! h264parse ! rtph264pay ! udpsink

你可以这样做:

src ! queue ! x264enc ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink

然后rtp://@:port在 vlc 中使用这种方式,mpegtsmux 将封装有关它包含哪些流的信息

我应该注意到您的方法并不正确,并且可能更有效(mpegtsmux 会将视频切成 188 字节的数据包,但您的方法将切成〜 1400 字节的 udp 数据包),但是您需要为 vlc 提供正确的 SDP 文件为了流式传输它。例如像这样,但我对此没有太多经验..

所以这是你当前有效的管道:

gst-launch-1.0 -vv -e v4l2src device=/dev/video0 ! "video/x-raw,width=352,height=288,framerate=25/1"\ ! queue ! x264enc speed-preset=1 ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=192.255.10.41 port=5004

使用 zerolatency 时,您可能会获得更好的结果:

像这样x264enc tune=4它将丢弃所有其他质量参数,如速度预设等。

这是来自关于 tune 属性的文档:

tune : Preset name for non-psychovisual tuning options
       flags: readable, writable
       Flags "GstX264EncTune" Default: 0x00000000, "(none)"
       (0x00000001): stillimage       - Still image
       (0x00000002): fastdecode       - Fast decode
       (0x00000004): zerolatency      - Zero latency
于 2016-02-02T08:57:14.603 回答